parkingFeeDetail.js 36 KB

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