工行这里学车报名流程h5
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

221 lines
5.1 KiB

import loginApi from '@/api/login.js'; // 引入
import learnDriveApi from '@/api/learnDrive.js'; // 引入
import store from '@/store';
const install = (Vue, vm) => {
// 打开地图
const openMap = (lat, lng) => {
uni.openLocation({
latitude: lat,
longitude: lng
})
}
// 距离换算
const distanceFn = (val) => {
if (val * 1 < 1000) {
return val + '米'
} else {
return (val / 1000).toFixed(2) + '公里'
}
}
// 价格计算
const priceTo = (price = 0) => {
// return (price / 100).toFixed(2)
return (parseInt(price * 100) / 100 / 100).toFixed(2)
}
const distanceLatLng = (lat1, lng1) => {
var that = this;
let lat2 = store.state.latLng.lat;
let lng2 = store.state.latLng.lng;
let rad1 = lat1 * Math.PI / 180.0;
let rad2 = lat2 * Math.PI / 180.0;
let a = rad1 - rad2;
let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) *
Math.cos(
rad2) * Math.pow(
Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
s = s.toString();
s = s.substring(0, s.indexOf('.') + 2);
return s
}
const getLocation = () => {
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'wgs84',
success: function(res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
let obj = {
lat: res.latitude,
lng: res.longitude
}
store.commit('updateLatLng', obj)
resolve(obj)
}
});
}).catch((e) => {})
}
// 查询用户信息
let getOwnerAccountBase = async () => {
const [err, data] = await loginApi.getOwnerAccountBase();
if (data.code != 0) {
uni.removeStorageSync('Authorization')
uni.setStorageSync('userInfo', {});
return {}
}
uni.setStorageSync('userInfo', data.data);
return data.data;
}
// 查看是否有未支付订单
let checkOrderPay = async () => {
// 这一步判断是否有实名,避免接口报错
let userInfo = await getOwnerAccountBase()
uni.setStorageSync('userInfo', userInfo);
if (!userInfo || !userInfo.idcard) return false
// 1查询报名驾校
const [nulls, res] = await learnDriveApi.queryTrainingApplyByOwner()
if (!res.data) return false
let trainingApplyId = res.data[0].trainingApplyId
let transfer = res.data[0].transfer
if (!trainingApplyId) {
return {}
}
// 2查询订单id
let [err, res2] = await learnDriveApi.getTrainingApplyDetails({
trainingApplyId: trainingApplyId
})
let detail = res2.data
if (!detail.trainingOrderId) {
return {}
}
// 查询订单详情
let [err3, res3] = await learnDriveApi.getOwnerStudentStatus({
trainingOrderId: detail.trainingOrderId
})
console.log('详情')
console.log(res3.data)
res3.data.trainingOrderId = detail.trainingOrderId
// 有同城转样没有完成 用这个?transferStatus 还是用transfer
if (res3.haveTransfer == 2) {
uni.showModal({
content: '您有转校入学申请等完成',
confirmText: '去完成',
success: function(res) {
if (res.confirm) {
uni.navigateTo({
url: '/pages/user/businessHandling/transferAppliRecord/transferAppliRecord'
})
}
}
});
}
return res3.data
}
function addZeroPrefix(number) {
return number < 10 ? `0${number}` : number
}
let getDate = (date, splitor = '-') => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`
}
const browser = {
versions: function() {
const u = navigator.userAgent;
return {
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
}
}()
};
//调⽤APP交互
//apiName:⽅法名称
//parameter:参数
function appPostMessage(apiName, parameter) {
// console.log(browser.versions)
if (browser.versions.ios) { //判读iOS或安卓
try {
//参数类型可以为对象类型
var par = {
"type": apiName,
"callBack": {
//回调函数⾃定义参数
"callBackName": 'arouseNativeMsg',
},
"postParameter": parameter
};
//iOS调⽤格式
window.webkit.messageHandlers.requestApp.postMessage(par);
return "ios"
} catch (err) {
// on catch
}
} else if (browser.versions.android) {
try {
//par参数格式为json字符串
var par = {
"type": apiName,
"callBack": {
//
"callBackName": "arouseNativeMsg", //固定参数arouseNativeMsg
"callBackParms": parameter
}
};
//转jsonString
var parString = JSON.stringify(par);
//Android调⽤格式window.forJs.requestApp(par);
window.forJs.requestApp(parString);
return "android"
} catch (err) {
// on catch
}
} else {
alert("不是安卓或者IOS")
}
}
vm.$u.utils = {
openMap,
getLocation,
getOwnerAccountBase,
checkOrderPay,
priceTo,
distanceLatLng,
distanceFn,
getDate,
appPostMessage
}
}
export default {
install
}