parkingFeeDetail.js 35 KB

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