parkingFeeDetail.js 30 KB

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