parkingFeeDetail.js 31 KB

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