parkingFeeDetail.js 27 KB

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