parkingFeeDetail.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. import { mapState } from 'vuex';
  2. import uni from '@/utils/uniHooks';
  3. import {
  4. backLbsHome,
  5. getPlatform,
  6. isAlipay,
  7. } from '@/utils';
  8. import {debounce, } from 'lodash'
  9. import { Dialog, Toast } from 'vant';
  10. import { ordersAndPrepay } from '@/api/parking';
  11. import store from "@/store";
  12. // import newMemberPoints from '@/components/newMemberPoints/index.vue'
  13. import newMemberPointsItem from '@/components/newMemberPoints/item.vue'
  14. export default {
  15. name: 'parkingFeeDetail',
  16. components: { newMemberPointsItem },
  17. data() {
  18. this.toPay = debounce(this.toPay, 5000, {
  19. leading: true,
  20. trailing: false
  21. })
  22. return {
  23. hasDiscount: false,
  24. parkFee: {},
  25. refreshTime: 180, // 停车场重置费用倒计时3分钟
  26. // 微服务接口字段
  27. isShowDescription: true, // 缴费说明true:显示全部 false:显示部分
  28. btnLoading: false,
  29. isPay: false,
  30. popup: false,
  31. msData: {},
  32. orderTimeEvent: null,
  33. orderTime: null
  34. };
  35. },
  36. beforeRouteLeave(to, from, next) {
  37. // 设置下一个路由的 meta
  38. if (/index|home/.test(to.name)) {
  39. // 不在缓存列表中,从cachedViews缓存列表中移除
  40. this.$store.commit('cachedViews/DEL_CACHED_VIEW', from);
  41. }
  42. next();
  43. },
  44. async created() {
  45. // console.log('如果本地不存在', this.$route.query);
  46. const {fromPage = '', format = '', unlicensed = ''} = this.$route.query
  47. // licensedVehicle
  48. // format
  49. /* unlicensed: unlicensedVehicle(无牌车), licensedVehicle(有牌车)
  50. * format: success, fail
  51. * fromPage: 'parkingFeeDetail'
  52. */
  53. if(fromPage && format && unlicensed && !this.$store.state.pageHistory?.parkingFeeDetailPaystatus) {
  54. this.$store.commit('setPageHistory', {
  55. parkingFeeDetailPaystatus: 1
  56. })
  57. const query = {
  58. ...this.$route.query,
  59. }
  60. query.fromPage = ''
  61. query.format = ''
  62. query.unlicensed = ''
  63. // 无牌车失败跳转
  64. // 有牌车失败跳转
  65. if (format === 'success') {
  66. // 无牌车成功跳转, 有牌车成功跳转
  67. this.$router.replace({
  68. // path: 'parkingFeeSuccess?vehicleNo=' + this.$route.query.vehicleNo,
  69. path: this.getPagePath(),
  70. query: {
  71. ...this.$route.query,
  72. }
  73. });
  74. return
  75. }
  76. // 如果失败的话,刷新当前页面,则不做任何处理
  77. if(format === 'fail') {
  78. await Dialog.alert({
  79. title: '提示',
  80. message: '支付失败',
  81. confirmButtonColor: '#333',
  82. })
  83. // await this.pageInit();
  84. // return
  85. }
  86. }
  87. // 如果本地不存在
  88. // setTimeout(() => {
  89. // uni.setNavigationBarTitle({
  90. // title: '停车支付',
  91. // });
  92. // }, 300);
  93. // setTimeout(() => {
  94. // window?.toWXSendMsg({
  95. // type: 'uni_func',
  96. // funcName: 'setNavigationBarColor',
  97. // options: {
  98. // frontColor: '#000000',
  99. // backgroundColor: '#FBFCFF',
  100. // },
  101. // });
  102. // }, 500)
  103. setTimeout(async () => {
  104. // 如果从小程序来的用户已经登录。但是本地的 member 数据是空的,则从后端重新获取,如果获取失败则提示用户
  105. if(this.isLogin === 'haveLoggedIn' && (this.isNoLogin || !this.member?.vipcode)) {
  106. const res = await this.$store.dispatch('memberInit',{
  107. unionId: this.$store.state.sourceId,
  108. openid: this.$store.state.openid,
  109. isError: true
  110. })
  111. if(res) {
  112. backLbsHome()
  113. return;
  114. }
  115. }
  116. await this.pageInit();
  117. }, 300)
  118. },
  119. mounted() {
  120. // this.reloadPage()
  121. // console.log(7878, this.$route)
  122. },
  123. computed: {
  124. ...mapState({
  125. orderDetail: (state) => state.order.orderDetail,
  126. discountDesc: (state) => state.order.discountDesc,
  127. enableNewMemberPoints: (state) => state.order.enableNewMemberPoints,
  128. enablePoints: (state) => state.order.enablePoints,
  129. integralDesc: (state) => state.order.integralDesc,
  130. enableCoupon: (state) => state.order.enableCoupon,
  131. maxOneDayCoupons: (state) => state.order.maxOneDayCoupons,
  132. coupons: (state) => state.order.coupons,
  133. couponDesc: (state) => state.order.couponDesc,
  134. enablePaperCoupons: (state) => state.order.enablePaperCoupons,
  135. custTypeId: (state) => state.custTypeId,
  136. usingTotalDiscount: (state) => state.order.usingTotalDiscount,
  137. actualPayFee: (state) => state.order.actualPayFee,
  138. available: (state) => state.order.available,
  139. member: (state) => state.member,
  140. maxPointsTime: (state) => state.order.maxPointsTime,
  141. pointsTime: (state) => state.order.pointsTime,
  142. pointsPerHour: (state) => state.order.pointsPerHour,
  143. usePoints: (state) => state.order.usePoints,
  144. usePointsTime: (state) => state.order.usePointsTime,
  145. enableConsume: (state) => state.order.enableConsume,
  146. memberLevelDiscount: (state) => state.order.memberLevelDiscount,
  147. unitAmount: (state) => state.order.unitAmount,
  148. unlicensedInfo: state => state.unlicensedInfo,
  149. endlessLoop: (state) => state.endlessLoop,
  150. appId: state => state.appId,
  151. source: state => state.source,
  152. parkMallCode: (state) => state.order.parkMallCode,
  153. isLogin: (state) => state.isLogin,
  154. mallId: (state) => state.mallId,
  155. }),
  156. isNoLogin() {
  157. return JSON.stringify(this.member) === '{}' || !this.member
  158. },
  159. // 支付按钮状态
  160. payBtnDisabled() {
  161. // 当存在待支付金额 或者 用户登陆
  162. return !this.orderDetail?.parkingRecord?.totalFeeInYuan || (JSON.stringify(this.member) !== '{}' && !this.orderDetail.parkInfo);
  163. },
  164. // integralDesc() {
  165. // if (this.pointsTime > 0) {
  166. // // 深圳特殊处理(单位:金额)
  167. // if (this.orderDetail.parkInfo.parkMallCode === 5 || this.orderDetail.parkInfo.parkMallCode === 999) {
  168. // return `已选择兑换${this.pointsTime}元`;
  169. // }
  170. // return `已选择兑换${this.pointsTime}小时`;
  171. // }
  172. // if (this.bonusCopy < this.integral) {
  173. // return `${this.integral}积分可停车1小时`;
  174. // }
  175. // if (this.orderDetail.parkInfo.parkMallCode === 3 && app.globalData.member?.currnentintegral >= this.integral && !this.bonus) {
  176. // return `今日已达上限`;
  177. // }
  178. // return `${this.available}积分可减免`;
  179. // },
  180. },
  181. filters: {
  182. parkingTime(val) {
  183. const days = parseInt(val / 60 / 24)
  184. const hours = parseInt((val / 60) % 24)
  185. const minutes = parseInt(val % 60)
  186. if (days > 0) {
  187. return `${days}天 ${hours}小时 ${minutes}分钟`
  188. }
  189. if (hours > 0) {
  190. return `${hours}小时 ${minutes}分钟`
  191. }
  192. return `${minutes}分钟`
  193. },
  194. },
  195. methods: {
  196. // 刷新管理
  197. reloadPage() {
  198. setTimeout(() => {
  199. const fullPath = window.location.href.indexOf('parkingFeePaperCoupon') > -1 ? '/parkingFeeDetail/' : this.$route.fullPath
  200. window?.toWXSendMsg({
  201. type: 'nowRoute',
  202. options: {
  203. fullPath: fullPath
  204. },
  205. });
  206. window.subscribe('reload',( ) => {
  207. // 如果是纸质券页面,发起的扫码动作,不做任何刷新动作
  208. if (window.location.href.indexOf('parkingFeePaperCoupon') > -1) {
  209. this.reloadPage()
  210. return
  211. }
  212. // 如果当前路由不是支付页面,则回退到当前页面再刷新页面
  213. if(this.$route.name !== 'parkingFeeDetail') {
  214. this.$router.back()
  215. }
  216. setTimeout(() => {
  217. window.location.reload();
  218. }, 100)
  219. });
  220. }, 700)
  221. },
  222. // 前往支付
  223. async toPay() {
  224. // if (!isAlipayClient) {
  225. // // 判断微信小程序与 h5 是否正常通信
  226. // const isReload = await theCommunicationBetweenWechatAndH5IsNormal()
  227. // if(!isReload) {
  228. // uni.setStorageSync('isReload', 1)
  229. // window.location.reload()
  230. // return
  231. // }
  232. // }
  233. if (this.btnLoading) return
  234. this.btnLoading = true
  235. setTimeout(() => {
  236. if ( this.btnLoading && !this.isPay ) {
  237. const toast1 = Toast({
  238. message: '网络连接失败,请重试',
  239. duration: 3000,
  240. onClose: () => {
  241. this.clearOrderTimeEvent()
  242. this.$router.replace({
  243. // path: 'parkingFeeSuccess?carno=' + this.parkInfo.carno,
  244. path: 'home',
  245. query: {
  246. ...this.$route.query,
  247. }
  248. });
  249. }
  250. });
  251. this.btnLoading = false
  252. }
  253. }, 10000)
  254. const { parkingRecord, discountInfo = {}, parkingRule = {}} = this.orderDetail;
  255. const { coupons, points, memberGrade = [], paperCoupons = [], consume = [], newMemberPoints= {} } = discountInfo
  256. const { hourPrice } = parkingRule
  257. try {
  258. const params = {
  259. // vehicleNo: '', // 车牌号
  260. // points
  261. payChannel: isAlipay() ? 'MINI_PROGRAM' : 'OFFICIAL_ACCOUNT',
  262. payOption: isAlipay() ? 'ALIPAY' : 'WECHATPAY',
  263. parkingRecord: {
  264. ...parkingRecord,
  265. vehicleNo: parkingRecord.vehicleNo,
  266. enterTime: parkingRecord.enterTime,
  267. serviceMin: parkingRecord.serviceMin,
  268. totalFee: parkingRecord.totalFeeInYuan, //应缴
  269. actualPayFee: this.actualPayFee, //应付金额
  270. },
  271. discountInfo: {
  272. usingTotalDiscount: discountInfo?.usingTotalDiscount || 0, //优惠金额"
  273. actualUsedDiscount: discountInfo?.usingTotalDiscount || 0, //实际优惠金额
  274. },
  275. };
  276. // 会员等级减免
  277. if ( memberGrade?.length && memberGrade[0].discountFee > 0 && memberGrade[0].hasOwnProperty('selected')? memberGrade[0]?.selected : memberGrade[0]?.defaultSelected) {
  278. const selected = memberGrade[0].hasOwnProperty('selected') ? memberGrade[0].selected : memberGrade[0].defaultSelected;
  279. let discountTime = 0
  280. let discountFee = 0
  281. if(selected) {
  282. discountTime = memberGrade[0].hasOwnProperty('discountTime') ? memberGrade[0].discountTime : memberGrade[0].defaultDiscountTime;
  283. discountFee = memberGrade[0].hasOwnProperty('discountFee') ? memberGrade[0].discountFee : discountTime * hourPrice;
  284. }
  285. params.discountInfo.memberLevel = {
  286. "discountTime": discountTime * 60, // 小时转成分钟
  287. "discountFee": discountFee,
  288. "memberGrade": memberGrade[0].memberGrade
  289. }
  290. }
  291. // 消费减免
  292. if ( consume?.length && consume[0].discountFee > 0 && consume[0].hasOwnProperty('selected')? consume[0]?.selected : consume[0]?.defaultSelected) {
  293. const { redeemSalesAmount, defaultDiscountTime, couponCodes = ''} = consume[0]
  294. const selected = consume[0].hasOwnProperty('selected') ? consume[0].selected : consume[0].defaultSelected;
  295. let discountTime = 0
  296. let discountFee = 0
  297. if(selected) {
  298. discountFee = consume[0].hasOwnProperty('discountFee') ? consume[0].discountFee : memberGrade[0].defaultDiscountTime * hourPrice;
  299. discountTime = discountFee / hourPrice * 60;
  300. }
  301. params.discountInfo.consume = {
  302. ...consume[0],
  303. "defaultSelected": selected,
  304. "discountTime": discountTime,
  305. "discountFee": discountFee,
  306. // 杭州,沈阳,天津,福州,重新计算 redeemSalesAmount
  307. "redeemSalesAmount": ([2,4,6,8].indexOf(this.parkMallCode) > -1) ? (redeemSalesAmount / defaultDiscountTime) * ( discountFee / hourPrice) : redeemSalesAmount
  308. }
  309. // 浦东,重新计算 couponCodes
  310. if( this.parkMallCode == 1 && couponCodes) {
  311. params.discountInfo.consume.couponCodes = couponCodes.split('#').slice(0,discountFee / hourPrice).toString().replace(/,/g, '#')
  312. }
  313. }
  314. // 积分
  315. if (points?.length && points[0].discountFee > 0) {
  316. // 15 兑换 5元
  317. const { pointsPerUnit, unitAmount, discountFee, available } = points[0]
  318. params.discountInfo.points = {
  319. "discountTime": discountFee / hourPrice * 60,
  320. "discountFee": discountFee,
  321. "discountPoints": discountFee / hourPrice * pointsPerUnit
  322. }
  323. }
  324. // 优惠券
  325. if (coupons?.length) {
  326. const selectedCoupons = coupons.filter(elm => {
  327. const selected = elm.hasOwnProperty('selected') ? elm.selected : elm.defaultSelected;
  328. return selected
  329. }).map(elm => {
  330. elm.discountTime = elm.discountFee / hourPrice * 60
  331. return elm
  332. })
  333. if (selectedCoupons.length) {
  334. params.discountInfo.coupons = selectedCoupons
  335. }
  336. }
  337. // 纸质优惠券
  338. if ( paperCoupons?.length ) {
  339. params.discountInfo.paperCoupons = paperCoupons.filter(elm => {
  340. if ( !elm.discountFee ) {
  341. return false
  342. }
  343. return {
  344. ...elm,
  345. "discountFee": elm.discountFee,
  346. // discountTime: elm.discountFee / hourPrice * 60
  347. }
  348. })
  349. }
  350. // 新会员积分, 默认带上了,然后不加也不影响
  351. // if ( newMemberPoints?.discountFee ) {
  352. // params.discountInfo.paperCoupons = paperCoupons.filter(elm => {
  353. // if ( !elm.discountFee ) {
  354. // return false
  355. // }
  356. // return {
  357. // ...elm,
  358. // "discountFee": elm.discountFee,
  359. // // discountTime: elm.discountFee / hourPrice * 60
  360. // }
  361. // })
  362. // }
  363. console.log('下单时的参数', params);
  364. const unlicensed = this.$route.query?.vehicleNo ? this.$route.query?.vehicleNo.indexOf('临') > -1 : false; // true: 临时车牌;false:燃油车牌
  365. const res = await ordersAndPrepay(params, unlicensed);
  366. // console.log('orderDetail', res);
  367. if (res?.paymentType === 'NO_FEE_PAY') {
  368. this.btnLoading = false;
  369. this.isPay = false
  370. this.clearOrderTimeEvent()
  371. this.$router.replace({
  372. path: this.getPagePath(),
  373. query:{
  374. ...this.$route.query,
  375. }
  376. });
  377. // 支付成功
  378. return
  379. }
  380. // 如果是北京的ETCP
  381. if (this.isBKC() && !isAlipay()) {
  382. wx.miniProgram.navigateTo({
  383. url: `/pages/package-parkingFee/etcpPayment?token=${encodeURIComponent(
  384. res.token + '$'
  385. )}&syncId=${encodeURIComponent(
  386. res.syncId + '$'
  387. )}&CarNumber=${encodeURIComponent(
  388. res.vehicleNo + '$'
  389. )}`,
  390. });
  391. this.$router.back()
  392. return
  393. }
  394. if(res?.sessionId) {
  395. this.kerryPayment(res.sessionId, {unlicensed});
  396. return
  397. }
  398. // 如果接口返回异常,重置当前页面数据
  399. this.reCreateParkOrder()
  400. } catch (err) {
  401. // 网络异常返回首页
  402. if(err ==='ERR_NETWORK') {
  403. setTimeout(() => {
  404. this.clearOrderTimeEvent()
  405. this.$router.replace({
  406. // path: 'parkingFeeSuccess?carno=' + this.parkInfo.carno,
  407. path: 'home',
  408. query:{
  409. ...this.$route.query,
  410. }
  411. });
  412. }, 2900)
  413. } else {
  414. // 如果接口返回异常,重置当前页面数据
  415. console.log('err::::', err)
  416. if (err.code !=='NO_FEE_NEED_TO_PAY') {
  417. this.reCreateParkOrder()
  418. } else {
  419. Dialog.alert({
  420. title: '提示',
  421. message: '当前无需缴费',
  422. confirmButtonColor: '#333',
  423. }).then(() => {
  424. this.$router.replace({
  425. // path: 'parkingFeeSuccess?carno=' + this.parkInfo.carno,
  426. path: 'home',
  427. });
  428. // this.createParkOrder();
  429. });
  430. }
  431. this.btnLoading = false
  432. this.isPay = false
  433. }
  434. console.log(err);
  435. }
  436. },
  437. isBKC() {
  438. const lbsList = ['8a8884e77cc9e70a017cca4003590008','8a8485067ce4da2d017ce555e9b20000','8aaa80b47c784020017c78b205ba0023']
  439. return lbsList.indexOf(this.mallId) > -1
  440. },
  441. kerryPayment(session = '', payParams) {
  442. if(!session) return
  443. const platform = getPlatform();
  444. // console.log('platform:::', platform)
  445. let appId = uni.getStorageSync('appid');
  446. let openId = uni.getStorageSync('openid') || this.openid;
  447. if (platform === 'miniprogram') {
  448. // appId = 'wx92c3e55fbef6b2af';
  449. // appId = 'wxd830fe4d1e04988e';
  450. appId = this.appId;
  451. }
  452. // console.log('支付宝::', isAlipay())
  453. const params = {
  454. region: 'cn',
  455. payChannel: isAlipay() ? 'MINI_PROGRAM' : 'OFFICIAL_ACCOUNT',
  456. // payChannel: 'MOBILE_WEB',
  457. payOption: isAlipay() ? 'ALIPAY' : 'WECHATPAY',
  458. appId: appId,
  459. // openId: 'oudWQ5SCDElfn-IQH6eBR5JesOz4', // 下的appid: wxd830fe4d1e04988e
  460. openId,
  461. };
  462. // console.log(1854, params);
  463. this.$md(params);
  464. // let path = `/profileApi/payment/v1/services/session/${session}/transactions`;
  465. let path = `${window.profileApi}/payment/v1/services/session/${session}/transactions`;
  466. this.$request({
  467. url: path,
  468. data: params,
  469. method: 'POST',
  470. header: JSON.parse(uni.getStorageSync('handleUser')),
  471. })
  472. .then(async (res) => {
  473. // this.Toastloading.clear();
  474. // console.log(1795, res);
  475. if (res.data?.code == '000000') {
  476. const prepayJson = res.data.data.params;
  477. // console.log('prepayJson::', res.data)
  478. // const platform = getPlatform();
  479. this.isPay = true
  480. // TODO: h5环境判断
  481. // if (platform === 'micromessenger') {
  482. // const weixinH5PayRes = await this.weixinH5Pay(prepayJson);
  483. // // 微信支付完成,判断结果
  484. // // console.log(1784, weixinH5PayRes);
  485. // // errMsg: 'requestPayment:ok'
  486. // if (weixinH5PayRes?.errMsg === 'requestPayment:ok') {
  487. // this.btnLoading = false
  488. // this.isPay = false
  489. // this.clearOrderTimeEvent()
  490. // this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  491. // name: 'parkingFeeDetail',
  492. // });
  493. // this.$router.replace({
  494. // // path: 'parkingFeeSuccess?carno=' + this.parkInfo.carno,
  495. // path: this.getPagePath(),
  496. // query: {...this.$route.query}
  497. // });
  498. // } else {
  499. // this.reCreateParkOrder();
  500. // }
  501. // } else {
  502. let options = {}
  503. // if (isAlipay()) {
  504. // options = {
  505. // provider: 'alipay',
  506. // orderInfo: prepayJson.trade_no,
  507. // }
  508. // } else {
  509. options = {
  510. provider: 'wxpay',
  511. timeStamp: prepayJson.timeStamp,
  512. nonceStr: prepayJson.nonceStr,
  513. package: prepayJson.package,
  514. signType: prepayJson.signType,
  515. paySign: prepayJson.paySign,
  516. }
  517. // }
  518. // console.log(430, options)
  519. const data = {
  520. ...options,
  521. unlicensed: payParams.unlicensed,
  522. vehicleNo: this.$route.query.vehicleNo,
  523. };
  524. const timeStamp = data.timeStamp + '$';
  525. const nonceStr = data.nonceStr + '$';
  526. const packageStr = data.package + '$';
  527. const signType = data.signType + '$';
  528. const paySign = data.paySign + '$';
  529. const vehicleNo = this.orderDetail.parkingRecord.vehicleNo + '$';
  530. const unlicensed = this.orderDetail.unlicensed ? 'unlicensedVehicle' + '$': 'licensedVehicle' + '$';
  531. // console.log(486, this.orderDetail);
  532. // return
  533. wx.miniProgram.redirectTo({
  534. url: `/pages/package-parkingFee/payment?timeStamp=${encodeURIComponent(
  535. timeStamp
  536. )}&nonceStr=${encodeURIComponent(
  537. nonceStr
  538. )}&package=${encodeURIComponent(
  539. packageStr
  540. )}&signType=${encodeURIComponent(
  541. signType
  542. )}&paySign=${encodeURIComponent(paySign)}&activityRecordId=${
  543. res.signUpRecordId
  544. }&orderNo=${res.orderNo}&unlicensed=${
  545. unlicensed
  546. }&vehicleNo=${
  547. vehicleNo
  548. }`,
  549. });
  550. // return
  551. // window?.toWXSendMsg({
  552. // type: 'nowRoute',
  553. // options: {
  554. // fullPath: '1'
  555. // },
  556. // });
  557. // window.toWXSendMsg({
  558. // type: 'openWxPay',
  559. // options: options,
  560. // });
  561. // window.subscribe('wxPayOver', (options) => {
  562. // if(isAlipayClient) {
  563. // options.wxPayOver = options.options.wxPayOver
  564. // }
  565. // // this.Toastloading.clear();
  566. // // console.log('微信支付结束之后的返回参数', options);
  567. // // T-ODO: 在 qa 新发版前,只提示支付成功的信息(已处理成功信息)
  568. // if (options?.wxPayOver === 'fail') {
  569. // console.log('支付失败');
  570. // this.reCreateParkOrder();
  571. // } else {
  572. // this.btnLoading = false;
  573. // this.isPay = false
  574. // this.clearOrderTimeEvent()
  575. // this.$router.replace({
  576. // // path: 'parkingFeeSuccess?vehicleNo=' + this.$route.query.vehicleNo,
  577. // path: this.getPagePath(),
  578. // query:{
  579. // ...this.$route.query,
  580. // }
  581. // });
  582. // }
  583. // });
  584. // }
  585. } else {
  586. this.reCreateParkOrder();
  587. }
  588. })
  589. .catch((err) => {
  590. if(err.code === "ERR_NETWORK") {
  591. this.btnLoading = true;
  592. uni.showToast({ title: '网络连接失败,请重试', duration: 3000, icon: 'fail' });
  593. setTimeout(() => {
  594. this.clearOrderTimeEvent()
  595. this.$router.replace({
  596. // path: 'parkingFeeSuccess?carno=' + this.parkInfo.carno,
  597. path: 'home',
  598. query:{
  599. ...this.$route.query,
  600. }
  601. });
  602. }, 2900)
  603. return
  604. }
  605. this.reCreateParkOrder();
  606. });
  607. },
  608. // 支付失败后返还优惠券
  609. failedParkOrder() {
  610. // this.Toastloading.clear();
  611. const param = {
  612. orderno: this.parkInfo.orderno,
  613. };
  614. this.$md(param);
  615. uni
  616. .request({
  617. url: this.$baseURL + 'api/1.0/park/failedParkOrder',
  618. data: param,
  619. method: 'POST',
  620. header: JSON.parse(uni.getStorageSync('handleUser')),
  621. })
  622. .then((res) => {
  623. this.reCreateParkOrder();
  624. })
  625. .catch((err) => {
  626. this.reCreateParkOrder();
  627. });
  628. },
  629. // 支付失败弹框 重新创建订单
  630. reCreateParkOrder() {
  631. // console.log('支付失败弹框 重新创建订单');
  632. Dialog.alert({
  633. title: '提示',
  634. message: '支付失败',
  635. confirmButtonColor: '#333',
  636. }).then(() => {
  637. this.$refs.countDown.reset(); // 停车场重置费用倒计时3分钟
  638. this.$store.dispatch('order/orderInit', {
  639. gateId: this.$route.query?.gateId,
  640. vehicleNo: this.$route.query?.vehicleNo,
  641. endlessLoop: this.endlessLoop,
  642. callback: (res) => {
  643. this.orderInitCallBack(res)
  644. },
  645. })
  646. this.btnLoading = false;
  647. this.isPay = false
  648. // this.createParkOrder();
  649. });
  650. // uni.showModal({
  651. // showCancel: false,
  652. // title: '提示',
  653. // content: '支付失败',
  654. // complete: (r) => {
  655. // this.createParkOrder();
  656. // },
  657. // });
  658. },
  659. // 初始化
  660. async pageInit() {
  661. // console.log(247, checkOutResponse);
  662. // this.msData.detail = checkOutResponse
  663. // 停车优惠
  664. // this.discounts(this.msData.detail)
  665. // 积分减免
  666. // 优惠券
  667. // 纸质优惠券
  668. // 优惠金额
  669. // 应付金额
  670. // this.$store.commit('order/SET_ORDER_DETAIL', checkOutResponse);
  671. try {
  672. console.log('无牌车扫码出场', this.unlicensedInfo, this.endlessLoop);
  673. this.btnLoading = false
  674. this.isPay = false
  675. // return
  676. this.$store.dispatch('order/orderInit', {
  677. vehicleNo: this.$route.query.vehicleNo,
  678. gateId: this.$route.query?.gateId,
  679. endlessLoop: this.endlessLoop,
  680. callback: (res) => {
  681. this.orderInitCallBack(res)
  682. },
  683. enquiryFarePolling: () => {
  684. this.orderTimeEvent = setInterval(() => {
  685. if(!this.orderTime) {
  686. this.orderTime = new Date().getTime()
  687. }
  688. const nowTime = new Date().getTime()
  689. if(nowTime - this.orderTime >= 2.8 * 60 * 1000) {
  690. if(this.$route.name !== 'parkingFeeDetail') {
  691. this.$router.back()
  692. }
  693. setTimeout(() => {
  694. this.orderTime = new Date().getTime()
  695. this.resetCountDown()
  696. }, 250)
  697. }
  698. // console.log(509, (nowTime - this.orderTime) / 1000);
  699. }, 1100);
  700. }
  701. });
  702. setTimeout(() => {
  703. this.$store.dispatch('clearUnlicensed');
  704. }, 1200);
  705. } catch (err) {
  706. // console.log('查询车辆是否在场的报错信息?', err, err.code === "INTERNAL_SERVER_ERROR");
  707. // 如果网络异常(这里是因为订单页面存在空白场景,才需要单独处理报错交互)
  708. if (err.code === "INTERNAL_SERVER_ERROR") {
  709. this.clearOrderTimeEvent()
  710. this.$router.back()
  711. }
  712. }
  713. },
  714. // 停车优惠
  715. discounts() {
  716. // totalFee 为零的时候不做跳转
  717. if (this.orderDetail.parkingRecord.totalFeeInYuan === 0) return;
  718. if (!this.enableConsume && !this.memberLevelDiscount && this.orderDetail.parkInfo.parkMallCode !== 2) {
  719. return Toast({
  720. message: '暂无可用优惠',
  721. });
  722. }
  723. if( this.discountDesc !== '暂无可用优惠') {
  724. this.$router.push({
  725. path: 'parkingFeeDiscounts',
  726. });
  727. }
  728. },
  729. setColor() {
  730. window?.toWXSendMsg({
  731. type: 'uni_func',
  732. funcName: 'setNavigationBarColor',
  733. options: {
  734. frontColor: '#000000',
  735. backgroundColor: '#2151C5',
  736. },
  737. });
  738. // uni.setNavigationBarColor({
  739. // frontColor: '#000000',
  740. // backgroundColor: '#FAFBFF',
  741. // });
  742. },
  743. // 是否展示优惠信息
  744. // isShowDiscounts(params) {
  745. // console.log(277, params?.parkingRule?.enableCoupon);
  746. // return params?.parkingRule?.enableCoupon
  747. // },
  748. //
  749. // 计算优惠信息
  750. discountssss(params) {
  751. // console.log(275, params);
  752. // console.log(275, params.discountInfo);
  753. // console.log(275, params.discountInfo.consume);
  754. return 1;
  755. },
  756. coupon() {
  757. // totalFee 为零的时候不做跳转
  758. if (this.orderDetail.parkingRecord.totalFeeInYuan === 0) return;
  759. // 如果没有电子券的话,提示用户
  760. if (this.coupons.length === 0 && this.source !== 'KIP') {
  761. uni.showToast({
  762. title: '暂无可使用的优惠券,请前往积分商城兑换优惠券'
  763. })
  764. return
  765. }
  766. this.$router.push({
  767. path: 'parkingFeeCoupon',
  768. });
  769. },
  770. paperCoupon() {
  771. if(!this.actualPayFee) {
  772. Toast('当前无需追加优惠')
  773. return;
  774. }
  775. // totalFee 为零的时候不做跳转
  776. if (this.orderDetail.parkingRecord.totalFeeInYuan === 0) return;
  777. this.$router.push({
  778. path: 'parkingFeePaperCoupon',
  779. query:{
  780. vehicleNo: this.$route.query.vehicleNo
  781. }
  782. });
  783. },
  784. duration() { },
  785. couponCount() { },
  786. // 重置倒计时
  787. resetCountDown() {
  788. this.$refs?.countDown?.reset();
  789. this.btnLoading = false;
  790. this.isPay = false;
  791. this.popup = false;
  792. this.$store.dispatch('order/orderInit', {
  793. gateId: this.$route.query?.gateId,
  794. vehicleNo: this.$route.query?.vehicleNo,
  795. endlessLoop: this.endlessLoop,
  796. callback: (res) => {
  797. this.orderInitCallBack(res)
  798. },
  799. })
  800. // 重新创建订单
  801. // this.createParkOrder();
  802. },
  803. //缴费说明隐藏显示
  804. togglePayinstruction() {
  805. this.isShowDescription = !this.isShowDescription;
  806. },
  807. // 积分修改框
  808. showPointsMathPopup() {
  809. // totalFee 为零的时候不做跳转
  810. if (this.orderDetail.parkingRecord.totalFeeInYuan === 0) return;
  811. if(this.integralDesc === '暂无可用积分'){
  812. return
  813. }
  814. this.popup = true;
  815. },
  816. cancelPointsMathPopup() {
  817. this.$store.dispatch('order/cancelPointsMath', () => {
  818. this.popup = false;
  819. });
  820. },
  821. savePointsMathPopup() {
  822. this.$store.dispatch('order/savePointsMath', () => {
  823. this.popup = false;
  824. });
  825. },
  826. // 获取成功缴费之后前往的页面
  827. getPagePath() {
  828. const { vehicleNo = '', unlicensed = '' } = this.$route.query
  829. // unlicensed: unlicensedVehicle(无牌车), licensedVehicle(有牌车)
  830. let pagePath = 'parkingFeeSuccess?vehicleNo=' + this.$route.query.vehicleNo
  831. // console.log('临时车流程', this.endlessLoop);
  832. if (vehicleNo.indexOf('临') > -1 && unlicensed === 'unlicensedVehicle') {
  833. pagePath = 'parkingFeeMsg?type=pay'
  834. }
  835. return pagePath
  836. },
  837. pointsMathCallback({type, message}) {
  838. // console.log(465, type);
  839. Toast({
  840. message: message,
  841. icon: 'none',
  842. });
  843. },
  844. //
  845. setDescription() {
  846. if ( this?.orderDetail?.parkInfo?.description.length > 0 ) {
  847. let reg = /[;;]/g;
  848. return this.orderDetail.parkInfo.description.replace(reg, '\r\n').replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  849. }
  850. return ''
  851. },
  852. clearOrderTimeEvent() {
  853. if(this.orderTimeEvent) {
  854. clearInterval(this.orderTimeEvent);
  855. this.orderTime = null
  856. }
  857. },
  858. orderInitCallBack(res) {
  859. console.log('orderInitCallBack', res);
  860. try {
  861. setTimeout(() => {
  862. this.$store.dispatch('clearUnlicensed');
  863. }, 700);
  864. // 如果 无牌车扫码出场扫码 无需缴费,直接展示无需缴费页面
  865. if(/unlicensedOut/.test(res.code) && res?.unlicensed) {
  866. this.clearOrderTimeEvent()
  867. // console.log('818', {
  868. // type: 'pay',
  869. // ...this.$route.query,
  870. // });
  871. console.log('822822822822822', this.$route.query);
  872. this.$router.replace({
  873. path: 'parkingFeeMsg',
  874. query: {
  875. ...this.$route.query,
  876. type: 'pay',
  877. }
  878. });
  879. return
  880. }
  881. // 如果是无需缴费的话,提示用户无需缴费
  882. if (res?.orderDetail?.parkingRecord?.totalFee <= 0) {
  883. this.$store.dispatch('order/orderInitRule', res.orderDetail);
  884. setTimeout(() => {
  885. Dialog.alert({
  886. message: '当前无需缴费',
  887. confirmButtonColor: '#333',
  888. }).then(() => {
  889. this.clearOrderTimeEvent()
  890. this.$router.back()
  891. });
  892. }, 1000)
  893. return
  894. }
  895. if ( /CAR_NOT_FOUND|INOUT_FAILED/.test(res.code) ) {
  896. setTimeout(() => {
  897. this.clearOrderTimeEvent()
  898. this.$router.replace({
  899. path: 'parkingFeeMsg',
  900. query: {
  901. ...this.$route.query,
  902. type: 'outFail'
  903. }
  904. })
  905. }, 300)
  906. return;
  907. }
  908. if (/NOT_FOUND|PARKING_RECORD_NOT_FOUND/.test(res.code)) {
  909. // 当前车辆没有查到账单
  910. this.clearOrderTimeEvent()
  911. setTimeout(() => {
  912. this.$router.replace({
  913. path: 'parkingFeePayment',
  914. query: {
  915. ...this.$route.query,
  916. msg: res.langMessage,
  917. vehicleNo: this.$route.query.vehicleNo,
  918. },
  919. });
  920. }, 300)
  921. return
  922. }
  923. if (/LOCAL_PARK_ERROR|INTERNAL_SERVER_ERROR|VALIDATION_FAILED|PLEASE_SCAN_QRCODE/g.test(res.code)) {
  924. setTimeout(() => {
  925. this.clearOrderTimeEvent()
  926. this.$router.back()
  927. }, 3000)
  928. }
  929. } catch (err) {
  930. console.log('查费接口返回异常', err);
  931. }
  932. }
  933. },
  934. destroyed() {
  935. this.clearOrderTimeEvent()
  936. }
  937. };