工行这里学车报名流程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.

220 lines
5.1 KiB

  1. import loginApi from '@/api/login.js'; // 引入
  2. import learnDriveApi from '@/api/learnDrive.js'; // 引入
  3. import store from '@/store';
  4. const install = (Vue, vm) => {
  5. // 打开地图
  6. const openMap = (lat, lng) => {
  7. uni.openLocation({
  8. latitude: lat,
  9. longitude: lng
  10. })
  11. }
  12. // 距离换算
  13. const distanceFn = (val) => {
  14. if (val * 1 < 1000) {
  15. return val + '米'
  16. } else {
  17. return (val / 1000).toFixed(2) + '公里'
  18. }
  19. }
  20. // 价格计算
  21. const priceTo = (price = 0) => {
  22. // return (price / 100).toFixed(2)
  23. return (parseInt(price * 100) / 100 / 100).toFixed(2)
  24. }
  25. const distanceLatLng = (lat1, lng1) => {
  26. var that = this;
  27. let lat2 = store.state.latLng.lat;
  28. let lng2 = store.state.latLng.lng;
  29. let rad1 = lat1 * Math.PI / 180.0;
  30. let rad2 = lat2 * Math.PI / 180.0;
  31. let a = rad1 - rad2;
  32. let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  33. let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) *
  34. Math.cos(
  35. rad2) * Math.pow(
  36. Math.sin(b / 2), 2)));
  37. s = s * 6378.137;
  38. s = Math.round(s * 10000) / 10000;
  39. s = s.toString();
  40. s = s.substring(0, s.indexOf('.') + 2);
  41. return s
  42. }
  43. const getLocation = () => {
  44. return new Promise((resolve, reject) => {
  45. uni.getLocation({
  46. type: 'wgs84',
  47. success: function(res) {
  48. console.log('当前位置的经度:' + res.longitude);
  49. console.log('当前位置的纬度:' + res.latitude);
  50. let obj = {
  51. lat: res.latitude,
  52. lng: res.longitude
  53. }
  54. store.commit('updateLatLng', obj)
  55. resolve(obj)
  56. }
  57. });
  58. }).catch((e) => {})
  59. }
  60. // 查询用户信息
  61. let getOwnerAccountBase = async () => {
  62. const [err, data] = await loginApi.getOwnerAccountBase();
  63. if (data.code != 0) {
  64. uni.removeStorageSync('Authorization')
  65. uni.setStorageSync('userInfo', {});
  66. return {}
  67. }
  68. uni.setStorageSync('userInfo', data.data);
  69. return data.data;
  70. }
  71. // 查看是否有未支付订单
  72. let checkOrderPay = async () => {
  73. // 这一步判断是否有实名,避免接口报错
  74. let userInfo = await getOwnerAccountBase()
  75. uni.setStorageSync('userInfo', userInfo);
  76. if (!userInfo || !userInfo.idcard) return false
  77. // 1查询报名驾校
  78. const [nulls, res] = await learnDriveApi.queryTrainingApplyByOwner()
  79. if (!res.data) return false
  80. let trainingApplyId = res.data[0].trainingApplyId
  81. let transfer = res.data[0].transfer
  82. if (!trainingApplyId) {
  83. return {}
  84. }
  85. // 2查询订单id
  86. let [err, res2] = await learnDriveApi.getTrainingApplyDetails({
  87. trainingApplyId: trainingApplyId
  88. })
  89. let detail = res2.data
  90. if (!detail.trainingOrderId) {
  91. return {}
  92. }
  93. // 查询订单详情
  94. let [err3, res3] = await learnDriveApi.getOwnerStudentStatus({
  95. trainingOrderId: detail.trainingOrderId
  96. })
  97. console.log('详情')
  98. console.log(res3.data)
  99. res3.data.trainingOrderId = detail.trainingOrderId
  100. // 有同城转样没有完成 用这个?transferStatus 还是用transfer
  101. if (res3.haveTransfer == 2) {
  102. uni.showModal({
  103. content: '您有转校入学申请等完成',
  104. confirmText: '去完成',
  105. success: function(res) {
  106. if (res.confirm) {
  107. uni.navigateTo({
  108. url: '/pages/user/businessHandling/transferAppliRecord/transferAppliRecord'
  109. })
  110. }
  111. }
  112. });
  113. }
  114. return res3.data
  115. }
  116. function addZeroPrefix(number) {
  117. return number < 10 ? `0${number}` : number
  118. }
  119. let getDate = (date, splitor = '-') => {
  120. const year = date.getFullYear()
  121. const month = date.getMonth() + 1
  122. const day = date.getDate()
  123. return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`
  124. }
  125. const browser = {
  126. versions: function() {
  127. const u = navigator.userAgent;
  128. return {
  129. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  130. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
  131. }
  132. }()
  133. };
  134. //调⽤APP交互
  135. //apiName:⽅法名称
  136. //parameter:参数
  137. function appPostMessage(apiName, parameter) {
  138. // console.log(browser.versions)
  139. if (browser.versions.ios) { //判读iOS或安卓
  140. try {
  141. //参数类型可以为对象类型
  142. var par = {
  143. "type": apiName,
  144. "callBack": {
  145. //回调函数⾃定义参数
  146. "callBackName": 'arouseNativeMsg',
  147. },
  148. "postParameter": parameter
  149. };
  150. //iOS调⽤格式
  151. window.webkit.messageHandlers.requestApp.postMessage(par);
  152. return "ios"
  153. } catch (err) {
  154. // on catch
  155. }
  156. } else if (browser.versions.android) {
  157. try {
  158. //par参数格式为json字符串
  159. var par = {
  160. "type": apiName,
  161. "callBack": {
  162. //
  163. "callBackName": "arouseNativeMsg", //固定参数arouseNativeMsg
  164. "callBackParms": parameter
  165. }
  166. };
  167. //转jsonString
  168. var parString = JSON.stringify(par);
  169. //Android调⽤格式window.forJs.requestApp(par);
  170. window.forJs.requestApp(parString);
  171. return "android"
  172. } catch (err) {
  173. // on catch
  174. }
  175. } else {
  176. alert("不是安卓或者IOS")
  177. }
  178. }
  179. vm.$u.utils = {
  180. openMap,
  181. getLocation,
  182. getOwnerAccountBase,
  183. checkOrderPay,
  184. priceTo,
  185. distanceLatLng,
  186. distanceFn,
  187. getDate,
  188. appPostMessage
  189. }
  190. }
  191. export default {
  192. install
  193. }