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

203 lines
4.9 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. const callPhone = (phone)=> {
  6. phone = phone.trim()
  7. if(!phone) {
  8. uni.showToast({
  9. title: '暂无联系方式',
  10. icon: 'none'
  11. });
  12. return
  13. }
  14. uni.showModal({
  15. content: '确定要拨打:'+phone+'?' ,
  16. success: function (res) {
  17. if (res.confirm) {
  18. uni.makePhoneCall({
  19. phoneNumber: phone //仅为示例
  20. });
  21. } else if (res.cancel) {
  22. console.log('用户点击取消');
  23. }
  24. }
  25. });
  26. }
  27. // 打开地图
  28. const openMap = (lat,lng)=>{
  29. uni.openLocation({
  30. latitude: lat,
  31. longitude: lng
  32. })
  33. }
  34. // 距离换算
  35. const distanceFn = (val)=> {
  36. if(val*1<1000) {
  37. return val + '米'
  38. }else {
  39. return (val / 1000).toFixed(2) + '公里'
  40. }
  41. }
  42. // 价格计算
  43. const priceTo = (price = 0)=> {
  44. // return (price / 100).toFixed(2)
  45. return ( parseInt( price * 100 ) / 100 / 100 ).toFixed(2)
  46. }
  47. const distanceLatLng = (lat1, lng1)=> {
  48. var that = this;
  49. let lat2 = store.state.latLng.lat;
  50. let lng2 = store.state.latLng.lng;
  51. let rad1 = lat1 * Math.PI / 180.0;
  52. let rad2 = lat2 * Math.PI / 180.0;
  53. let a = rad1 - rad2;
  54. let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  55. let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) *
  56. Math.cos(
  57. rad2) * Math.pow(
  58. Math.sin(b / 2), 2)));
  59. s = s * 6378.137;
  60. s = Math.round(s * 10000) / 10000;
  61. s = s.toString();
  62. s = s.substring(0, s.indexOf('.') + 2);
  63. return s
  64. }
  65. const getLocation = ()=> {
  66. return new Promise((resolve,reject)=>{
  67. uni.getLocation({
  68. type: 'wgs84',
  69. success: function (res) {
  70. console.log('当前位置的经度:' + res.longitude);
  71. console.log('当前位置的纬度:' + res.latitude);
  72. let obj = {
  73. lat: res.latitude,
  74. lng: res.longitude
  75. }
  76. store.commit('updateLatLng',obj)
  77. resolve(obj)
  78. }
  79. });
  80. }).catch((e) => {})
  81. }
  82. // 查询用户信息
  83. let getOwnerAccountBase = async ()=> {
  84. const [err, data] = await loginApi.getOwnerAccountBase();
  85. if (data.code != 0) {
  86. uni.removeStorageSync('Authorization')
  87. uni.setStorageSync('userInfo', {});
  88. return {}
  89. }
  90. uni.setStorageSync('userInfo', data.data);
  91. return data.data;
  92. }
  93. // 查看是否有未支付订单
  94. let checkOrderPay = async ()=>{
  95. // 这一步判断是否有实名,避免接口报错
  96. let userInfo = await getOwnerAccountBase()
  97. uni.setStorageSync('userInfo', userInfo);
  98. if(!userInfo||!userInfo.idcard) return false
  99. // 1查询报名驾校
  100. const [nulls, res] = await learnDriveApi.queryTrainingApplyByOwner()
  101. if(!res.data) return false
  102. let trainingApplyId = res.data[0].trainingApplyId
  103. let transfer = res.data[0].transfer
  104. if(!trainingApplyId) {
  105. return {}
  106. }
  107. // 2查询订单id
  108. let [err, res2] = await learnDriveApi.getTrainingApplyDetails({trainingApplyId: trainingApplyId})
  109. let detail = res2.data
  110. if(!detail.trainingOrderId) {
  111. return {}
  112. }
  113. // 查询订单详情
  114. let [err3, res3] = await learnDriveApi.getOwnerStudentStatus({trainingOrderId: detail.trainingOrderId})
  115. console.log('详情')
  116. console.log(res3.data)
  117. res3.data.trainingOrderId = detail.trainingOrderId
  118. // 有同城转样没有完成 用这个?transferStatus 还是用transfer
  119. if(res3.haveTransfer==2) {
  120. uni.showModal({
  121. content: '您有转校入学申请等完成',
  122. confirmText: '去完成',
  123. success: function (res) {
  124. if (res.confirm) {
  125. uni.navigateTo({
  126. url: '/pages/user/businessHandling/transferAppliRecord/transferAppliRecord'
  127. })
  128. }
  129. }
  130. });
  131. }
  132. return res3.data
  133. }
  134. function addZeroPrefix(number) {
  135. return number < 10 ? `0${number}`:number
  136. }
  137. let getDate = (date, splitor = '-')=> {
  138. const year = date.getFullYear()
  139. const month = date.getMonth() + 1
  140. const day = date.getDate()
  141. return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`
  142. }
  143. var lastTime = 0
  144. var audioContext = uni.createInnerAudioContext() // 播放音频的
  145. let shakeFn = (res)=>{
  146. if(!store.state.havePay) return false
  147. let nowTimer = new Date().getTime()
  148. if (nowTimer - lastTime < 1000) return
  149. lastTime = nowTimer
  150. // 自己根据自己的力度调节 变量大小 满足自己设定的值后触发自己的逻辑
  151. if ((Math.abs(res.x) > 20 || Math.abs(res.y) > 20 || Math.abs(res.z) > 20) ) {
  152. console.log('yayaoyaoya6666666666666666')
  153. // 进入判断后 相当于摇一摇成功
  154. audioContext.src = 'https://lg-fe2b58o2-1255788064.cos.ap-shanghai.myqcloud.com/shark.mp3' // 播放音频
  155. audioContext.play() // 播放
  156. uni.navigateTo({
  157. url: '/pages/user/studentIdImg/studentIdImg'
  158. })
  159. }
  160. }
  161. vm.$u.utils={
  162. callPhone,
  163. openMap,
  164. getLocation,
  165. getOwnerAccountBase,
  166. checkOrderPay,
  167. priceTo,
  168. distanceLatLng,
  169. distanceFn,
  170. getDate,
  171. shakeFn
  172. }
  173. }
  174. export default {
  175. install
  176. }