parkingFee.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. import plateNumber from '@/components/plate-number/plateNumber.vue';
  2. import {LICENSE_PLATE_TYPE_ARR, REG_SOURCE} from '@/constants';
  3. import LoginDom from '@/components/Login/Login.vue';
  4. import {mapState} from 'vuex';
  5. import {initWxJsSdkConfig} from '@/utils/login';
  6. import {getUrlParams, isHZ} from '@/utils';
  7. import wxPointsAuth from '@/components/wx-points-auth/wx-points-auth.vue'
  8. const app = {
  9. globalData: {
  10. regSource: '',
  11. },
  12. };
  13. import uni from '@/utils/uniHooks';
  14. import {parkingLots, qrCodes, unlicensedCarCheckIn, getConfValueOfKey, getVehicles, parkingRecord} from '@/api/parking';
  15. export default {
  16. components: {
  17. plateNumber,
  18. LoginDom,
  19. 'wx-points-auth': wxPointsAuth,
  20. // blueCom,
  21. // greenCom,
  22. // officeBlueCom,
  23. // purpleCom,
  24. },
  25. data() {
  26. return {
  27. showPointsAuth: true,
  28. vehicleMgt_content_index: -1, //历史车辆选中
  29. carType: 0, //车辆类型
  30. init_ch: false, // 字体超出隐藏显示
  31. search_price: false, //查询按钮隐藏显示
  32. parkInfoEntity: {},
  33. show_chinese: false, //是否显示汉字键盘
  34. show_allBoard: false, //是否显示英文数字键盘
  35. plate_number: '', //车牌号
  36. description: '', // 车场描述
  37. ind: null,
  38. numArr: ['', '', '', '', '', '', ''],
  39. active: null,
  40. carList: [], // 车辆列表
  41. classifyList: ['燃油车牌', '新能源', '特殊车牌'], // 车牌类型
  42. vehicleNumber: '',
  43. localimgPic: '',
  44. hourMoney: '',
  45. showSq: false,
  46. blueHeadBg: 'parkingFee/fee-head-bg.png',
  47. picUrl: this.$picUrl,
  48. colorAry: ['', '-blue', '-green'],
  49. openId: null,
  50. options: null,
  51. preUrl: '',
  52. tabbarActive: '手动缴费',
  53. supportUnlicensed: false, // 控制当前site,是否使用无牌车
  54. qrCodeHistory: '',
  55. isAlipayClient: isAlipayClient
  56. // custTypeId: 0,
  57. };
  58. },
  59. computed: {
  60. disabledBtn() {
  61. return this.numArr.filter((val) => !val).length > 0;
  62. },
  63. ...mapState({
  64. groupId: (state) => state.groupId,
  65. openid: (state) => state.openid,
  66. mallId: (state) => state.mallId,
  67. kipUserId: (state) => state.kipUserId,
  68. userInfo: (state) => state.userInfo,
  69. member: (state) => state.member,
  70. mobile: (state) => state.mobile,
  71. custTypeId: (state) => state.custTypeId,
  72. unlicensedCar: (state) => state.order.unlicensedCar,
  73. // 如果是扫码进入的无牌车
  74. unlicensedInfo: (state) => state.unlicensedInfo,
  75. endlessLoop: (state) => state.endlessLoop,
  76. source: (state) => state.source,
  77. }),
  78. },
  79. created() {
  80. // console.log('二次加载this.$route.query.fromPage', this.$route.query.fromPage, this.$store.state.pageHistory);
  81. // console.log('二次加载', this.$route.query.fromPage && !this.$store.state.pageHistory[this.$route.query.fromPage]);
  82. const fromPage = localStorage.getItem(`${this.$route.query.fromPage}`)
  83. // console.log(9191, this.$route.query?.fromPage);
  84. if (this.$route.query?.fromPage !== 'undefined' && !this.$store.state.pageHistory[this.$route.query.fromPage] && !fromPage) {
  85. // console.log(93939);
  86. this.$store.commit('setPageHistory', {
  87. [this.$route.query.fromPage]: 1
  88. })
  89. localStorage.setItem(`${this.$route.query.fromPage}`, this.$route.query.fromPage)
  90. this.$router.push({
  91. path: this.$route.query.fromPage, query: {
  92. ...this.$route.query,
  93. loginCount: 1
  94. }
  95. });
  96. }
  97. const {type = '', code = ''} = this.$route.query
  98. // 无牌车流程
  99. if (/unlicensedOut|unlicensedIn/.test(type) && code && !this.$store.state.pageHistory?.unlicensed && !this.endlessLoop) {
  100. this.$store.commit('setPageHistory', {
  101. unlicensed: 1
  102. })
  103. this.$store.commit('SET_UNLICENSED_INFO', {
  104. type, code
  105. });
  106. this.$store.commit('SET_ENDLESS_LOOP', type);
  107. this.$nextTick(() => {
  108. this.qrCodesRule(code);
  109. })
  110. }
  111. },
  112. beforeRouteLeave(to, from, next) {
  113. this.$store.commit('cachedViews/DEL_CACHED_VIEW', to);
  114. next();
  115. },
  116. watch: {
  117. openid() {
  118. if (this.openid) {
  119. this.getParkInfo();
  120. this.showSq = false;
  121. }
  122. },
  123. // unlicensedInfo:{
  124. // handler(){
  125. // // const member = uni.getStorageSync('member');
  126. // // if(!member) return // 如果用户走未登录流程的话
  127. // // 不论是否出入场,都使用此函数获取 gateId(闸口机器的ID)
  128. // if (this.unlicensedInfo?.type && /unlicensedOut|unlicensedIn/.test(this.unlicensedInfo.type) && this.endlessLoop.length === 0) {
  129. // // 此处记录扫码流程执行次数。如果超过一次则不再执行
  130. // this.$store.commit('SET_ENDLESS_LOOP', this.unlicensedInfo.type);
  131. // this.$nextTick(() => {
  132. // this.qrCodesRule(this.unlicensedInfo.code);
  133. // })
  134. // }
  135. // },
  136. // immediate:true //true就表示会立即执行
  137. // }
  138. },
  139. async mounted() {
  140. // console.log(114, 99999999999);
  141. // const platform = getPlatform();
  142. // if (platform === 'micromessenger') {
  143. // await initWxJsSdkConfig(['checkJsApi', 'scanQRCode']);
  144. // }
  145. this.getVehiclesINTMP()
  146. const openid = uni.getStorageSync('openid');
  147. // 如果用户未登录的话,返回之后,重新获取数据用户的基础数据
  148. if (openid) {
  149. this.getParkInfo();
  150. this.showSq = false;
  151. } else {
  152. const regSource = REG_SOURCE.PARKING;
  153. app.globalData.regSource = regSource;
  154. if (this.options?.regSource) {
  155. app.globalData.regSource = REG_SOURCE[this.options?.regSource];
  156. }
  157. if (this.options?.tpName) {
  158. app.globalData.tpName = this.options?.tpName;
  159. }
  160. this.showSq = true;
  161. }
  162. try {
  163. const href = window.location.href;
  164. if (!isAlipayClient && !/808[0-9]/.test(href)) {
  165. setTimeout(async () => {
  166. await initWxJsSdkConfig(['checkJsApi', 'scanQRCode']);
  167. }, 1500)
  168. }
  169. } catch (e) {
  170. console.log(e)
  171. }
  172. },
  173. methods: {
  174. toggleType(carType) {
  175. this.ind = 0;
  176. this.active = 0;
  177. this.carType = carType;
  178. if (carType === 1) {
  179. this.numArr = [
  180. this.numArr[0],
  181. this.numArr[1],
  182. this.numArr[2],
  183. this.numArr[3],
  184. this.numArr[4],
  185. this.numArr[5],
  186. this.numArr[6],
  187. this.numArr[7],
  188. ];
  189. } else {
  190. this.numArr = [
  191. this.numArr[0],
  192. this.numArr[1],
  193. this.numArr[2],
  194. this.numArr[3],
  195. this.numArr[4],
  196. this.numArr[5],
  197. this.numArr[6],
  198. ];
  199. }
  200. },
  201. // 获取停车场信息
  202. getParkInfo: async function () {
  203. uni.showLoading({
  204. title: '加载中',
  205. });
  206. try {
  207. // console.log('加载车场信息', this.$store.state.lbsId);
  208. // const res = await parkingLots('8aaa82ea804d07cd0180516ff03b0008'); // TODO: 临时写死
  209. const res = await parkingLots(this.$store.state.lbsId); // TODO: 临时写死
  210. // console.log(res);
  211. let reg = /[;;]/g;
  212. this.description = res?.description?.replace(reg, '\r\n').replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  213. this.supportUnlicensed = res.supportUnlicensed || false
  214. const carList = uni.getStorageSync('carList');
  215. if (carList) {
  216. this.carList = JSON.parse(carList);
  217. }
  218. } catch (e) {
  219. console.log(225225, e);
  220. }
  221. },
  222. //缴费说明隐藏显示
  223. top_display() {
  224. this.init_ch = !this.init_ch;
  225. },
  226. // 唤起键盘
  227. clickShowKeyboard(index) {
  228. if (this.carType !== 1 && index === 7) return
  229. this.ind = index;
  230. this.active = index;
  231. if (index === 0) {
  232. this.$refs['plateKeyboard'].openKeyboardCN();
  233. } else {
  234. this.$refs['plateKeyboard'].closeKeyboardCN();
  235. this.$refs['plateKeyboard'].openKeyboardEN();
  236. }
  237. },
  238. // 接收子组件数据
  239. updateCarno(val) {
  240. this.numArr = [...val.numArr];
  241. this.vehicleNumber = this.numArr.join('');
  242. this.active = val.active;
  243. this.ind = val.ind;
  244. },
  245. // 节流函数
  246. throttle(fc, waitTime = 500, imme = true) {
  247. if (imme) {
  248. if (!this.flag) {
  249. this.flag = true;
  250. typeof fc === 'function' && fc();
  251. this.timer = setTimeout(() => {
  252. this.flag = false;
  253. }, waitTime);
  254. }
  255. } else {
  256. if (!this.flag) {
  257. this.flag = true;
  258. this.timer = setTimeout(() => {
  259. this.flag = false;
  260. typeof fc === 'function' && fc();
  261. }, waitTime);
  262. }
  263. }
  264. },
  265. // 校验车牌号
  266. preHandleSearch() {
  267. if (this.disabledBtn) return
  268. uni.setStorageSync('carList', [
  269. ...new Set([this.vehicleNumber, ...this.carList]),
  270. ].slice(0, 6));
  271. this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  272. name: 'parkingFeeDetail',
  273. });
  274. this.$store.commit('SET_REGRESH_PAGE_KEY')
  275. this.$nextTick(() => {
  276. const query = {
  277. ...this.$route.query,
  278. vehicleNo: this.vehicleNumber,
  279. }
  280. // fromPage && format && unlicensed
  281. query.fromPage = ''
  282. query.format = ''
  283. query.unlicensed = ''
  284. this.$router.push({
  285. path: 'parkingFeeDetail',
  286. query,
  287. });
  288. })
  289. },
  290. // 历史车牌快速查询
  291. toHandleSearch(vehicleNo) {
  292. uni.setStorageSync('carList', [...new Set([vehicleNo, ...this.carList])].slice(0, 6));
  293. this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  294. name: 'parkingFeeDetail',
  295. });
  296. this.$store.commit('SET_REGRESH_PAGE_KEY')
  297. this.$nextTick(() => {
  298. const query = {
  299. ...this.$route.query,
  300. vehicleNo: vehicleNo,
  301. }
  302. // fromPage && format && unlicensed
  303. query.fromPage = ''
  304. query.format = ''
  305. query.unlicensed = ''
  306. this.$router.push({
  307. path: 'parkingFeeDetail',
  308. query,
  309. });
  310. });
  311. },
  312. // 查询车费信息
  313. async handleSearch(carno, clickEvent = '$ClickQueryAndPayment') {
  314. this.vehicleNumber = carno;
  315. const params = {
  316. carno,
  317. mallid: this.mallId,
  318. openid: this.openid,
  319. vipcode: this.member?.vipcode,
  320. mobile: this.mobile,
  321. groupId: this.groupId,
  322. createuser: 'sys_miniprogram',
  323. };
  324. // 查询缴费按钮埋点
  325. let [carTypeName, redirectUrl, parkTime] = ['ordinary', '', ''];
  326. switch (this.carType) {
  327. case 0:
  328. carTypeName = 'ordinary';
  329. break;
  330. case 1:
  331. carTypeName = 'newEnergy';
  332. break;
  333. case 2:
  334. carTypeName = 'special';
  335. break;
  336. }
  337. this.$md(params);
  338. this.$request({
  339. // url: this.$baseURL + 'api/1.0/park/checkCarIsInPark',
  340. url: this.$baseURL + 'api/1.0/park/checkCarIsInParkAndCarFee',
  341. // url: 'http://172.21.90.87:8083/xcrm-api/api/1.0/park/checkCarIsInParkAndCarFee',
  342. data: params,
  343. method: 'POST',
  344. header: JSON.parse(uni.getStorageSync('handleUser')),
  345. timeout: 60000 * 2, // 120S
  346. showLoading: {
  347. title: '加载中',
  348. duration: 0,
  349. },
  350. })
  351. .then((res) => {
  352. // console.log(555555, res);
  353. // ToastObj.clear();
  354. // uni.hideLoading();
  355. if (res.data.code === 0) {
  356. // 清理旧数据
  357. this.parkingFeeDetailInit();
  358. uni.setStorageSync('isReload', '3');
  359. // this.$destroy();
  360. const query = {
  361. ...this.$route.query,
  362. vehicleNo: carno,
  363. }
  364. // fromPage && format && unlicensed
  365. query.fromPage = ''
  366. query.format = ''
  367. query.unlicensed = ''
  368. this.$router.push({
  369. path: 'parkingFeeDetail',
  370. query,
  371. });
  372. parkTime = res.data?.data?.serviceMin;
  373. redirectUrl = '/pages/parkingFee/parkingFeeDetail.vue';
  374. } else if (res.data.code === 1) {
  375. // 当前车辆没有查到账单
  376. this.$router.push({
  377. path: 'parkingFeePayment',
  378. query: {
  379. ...this.$route.query,
  380. msg: res.data.msg,
  381. carno,
  382. },
  383. });
  384. redirectUrl = '/pages/parkingFee/parkingFeePayment.vue';
  385. } else if (res.data.code === 2) {
  386. // 月租车
  387. this.$router.push({
  388. path: './parkingFeeHint/parkingFeeHint',
  389. query: {
  390. ...this.$route.query,
  391. carno,
  392. },
  393. });
  394. redirectUrl = '/pages/parkingFee/parkingFeeHint/parkingFeeHint.vue';
  395. } else {
  396. uni.showToast({
  397. title: res.data.msg,
  398. duration: 2000,
  399. icon: 'none',
  400. });
  401. }
  402. })
  403. .catch((err) => {
  404. // uni.hideLoading();
  405. uni.showToast({
  406. title: '网络超时请稍后再试',
  407. duration: 2000,
  408. icon: 'none',
  409. });
  410. console.log(err);
  411. });
  412. },
  413. // 页面初始清空缓存
  414. parkingFeeDetailInit() {
  415. console.log('清理数据');
  416. // 优惠减免(首停、会员、消费)
  417. uni.removeStorageSync('checkedList'); // 选中list
  418. uni.removeStorageSync('checkedTotal'); // 选中count数
  419. uni.removeStorageSync('discountTotal'); // 减免信息(时长、费用)
  420. // 停车减免(优惠、积分、停车券)
  421. uni.removeStorageSync('parkFee');
  422. // 电子券优惠信息
  423. uni.removeStorageSync('checkedCouponList'); // 选中list
  424. uni.removeStorageSync('couponInfo'); // 减免信息(时长、费用)
  425. uni.removeStorageSync('list'); // 电子券list
  426. // 总停车优惠信息(时长、费用)
  427. uni.removeStorageSync('parkingTotal');
  428. // 应缴金额
  429. uni.removeStorageSync('servicefee');
  430. // 订单号
  431. uni.removeStorageSync('orderno');
  432. // 纸质优惠券
  433. uni.removeStorageSync('paperCouponInfo');
  434. },
  435. // 缴费记录
  436. doRouter: function () {
  437. const query = {
  438. ...this.$route.query,
  439. // vehicleNo: vehicleNo,
  440. }
  441. // fromPage && format && unlicensed
  442. query.fromPage = ''
  443. query.format = ''
  444. query.loginCount = ''
  445. // uni.setStorageSync('loadData', '');
  446. // if (this.$store.state.isLogin === 'loginDenied') {
  447. // this.$router.push({ path: 'login' });
  448. // return;
  449. // }
  450. this.$store.commit('SET_REGRESH_PAGE_KEY')
  451. this.$router.push({path: 'parkingFeeList', query});
  452. },
  453. // 车牌管理
  454. doRouter2: function () {
  455. this.$store.dispatch('clearUnlicensed');
  456. // window?.toWXSendMsg({
  457. // type: 'uni_func',
  458. // funcName: 'setStorageSync',
  459. // options: {
  460. // key: 'noLoginParkingFeeWebViewPath',
  461. // value: ''
  462. // },
  463. // });
  464. this.$store.commit('SET_REGRESH_PAGE_KEY')
  465. uni.setStorageSync('loadData', '');
  466. // if (this.$store.state.isLogin === 'loginDenied') {
  467. // this.$router.push({ path: 'login' });
  468. // return;
  469. // }
  470. const query = {
  471. ...this.$route.query,
  472. // vehicleNo: vehicleNo,
  473. }
  474. // fromPage && format && unlicensed
  475. query.fromPage = ''
  476. query.format = ''
  477. query.loginCount = ''
  478. uni.removeStorageSync('passLogin');
  479. this.$router.push({path: 'vehicleManagement', query});
  480. },
  481. async jumpToPreJudgmentOfParkingInvoice() {
  482. return new Promise(async (resolve) => {
  483. try {
  484. // 判断是否启用停车发票
  485. uni.showLoading()
  486. // const res = await getAccessH5(`${this.mallId}-invoice`);
  487. const res = await getConfValueOfKey('HEJIInvoiceSwitch')
  488. const lbsId = uni.getStorageSync('lbsId')
  489. if (res?.switch && res.lbsId.length && res.lbsId.indexOf(lbsId) > -1) {
  490. uni.hideLoading();
  491. // console.log(474, this.Dialog);
  492. this.$dialog({
  493. title: '温馨提示',
  494. // message: '小程序“停车开票”功能将从2023年8月10日起提供服务,支持开具3个月内停车记录的发票,如需停车开票,请稍后尝试或咨询服务台',
  495. message: res.message,
  496. confirmButtonColor: this.$theme[this.theme].primaryColor
  497. })
  498. // 提示用户
  499. // uni.showToast({
  500. // title:'尽请期待!'
  501. // })
  502. resolve(true)
  503. }
  504. resolve(false)
  505. } catch (err) {
  506. console.log(err);
  507. resolve(false)
  508. }
  509. })
  510. // return false
  511. },
  512. //停车发票
  513. doRouter1: async function () {
  514. const isJump = await this.jumpToPreJudgmentOfParkingInvoice();
  515. if (isJump) return
  516. uni.hideLoading()
  517. uni.removeStorageSync('invoiceindex');
  518. this.$store.dispatch('clearUnlicensed');
  519. this.$store.commit('SET_REGRESH_PAGE_KEY')
  520. // window?.toWXSendMsg({
  521. // type: 'uni_func',
  522. // funcName: 'setStorageSync',
  523. // options: {
  524. // key: 'noLoginParkingFeeWebViewPath',
  525. // value: ''
  526. // },
  527. // });
  528. const query = {
  529. ...this.$route.query,
  530. // vehicleNo: vehicleNo,
  531. }
  532. // fromPage && format && unlicensed
  533. query.fromPage = ''
  534. query.format = ''
  535. query.loginCount = ''
  536. uni.setStorageSync('loadData', '');
  537. // if (this.$store.state.isLogin === 'loginDenied') {
  538. // this.$router.push({ path: 'login' });
  539. // return;
  540. // }
  541. // uni.removeStorageSync('passLogin');
  542. // TODO: 北京停车场开票
  543. /* if (this.parkInfoEntity.parkMallCode === 3) {
  544. uni.navigateToMiniProgram({
  545. appId: this.$etcpAppId,
  546. path: this.$etcpAppInvoicePath,
  547. envVersion: 'release',
  548. })
  549. return
  550. }
  551. */
  552. this.$router.push({path: 'parkingReceipt', query});
  553. },
  554. //停车券兑换
  555. doRouter3: function () {
  556. this.$store.dispatch('clearUnlicensed');
  557. // window?.toWXSendMsg({
  558. // type: 'uni_func',
  559. // funcName: 'setStorageSync',
  560. // options: {
  561. // key: 'noLoginParkingFeeWebViewPath',
  562. // value: ''
  563. // },
  564. // });
  565. uni.setStorageSync('loadData', '');
  566. // window.toWXSendMsg({
  567. // type: 'toPage',
  568. // options: {
  569. // fnName: 'navigateTo',
  570. // url: '/pages/pointsMall/pointsMall?exchangeTypes=2',
  571. // },
  572. // });
  573. wx.miniProgram.navigateTo({
  574. "url": "/pages/pointsMall/pointsMall?exchangeTypes=2" // 去 login 页面 1 去登录
  575. })
  576. },
  577. blueComChange(value) {
  578. console.log('blueComChange', value);
  579. },
  580. tabbarActiveEvent(name) {
  581. this.tabbarActive = name
  582. if (name === '无牌缴费') {
  583. this.$store.dispatch('order/unlicensedRule', (code) => {
  584. // CAR_NOT_FOUND 车场扫描道闸入口,发现无车
  585. if (code === 'CAR_NOT_FOUND') {
  586. }
  587. // CAR_HAS_PLATE 车场扫描道闸入口,发现有牌车
  588. if (code === 'CAR_HAS_PLATE') {
  589. }
  590. })
  591. }
  592. },
  593. // 无牌车闸机扫码
  594. async scanCarCode() {
  595. try {
  596. const runScanFn = (res) => {
  597. if (res.scanType && res.scanType == 'QR_CODE') {
  598. console.log(res.result);
  599. // 获取二维码参数之后,模拟提取参数
  600. const url = res.result;
  601. const {path} = getUrlParams(res.result)
  602. let params = null
  603. if (path) {
  604. params = getUrlParams(decodeURIComponent(path))
  605. }
  606. /*
  607. 微信扫码之后,处理过的参数 {"code": "e41d4d9dd5534f4aa3de88326a2e6f85", "type": "unlicensedIn#wechat-redirect"}
  608. */
  609. if (params?.type.indexOf('wechat-redirect') > -1) {
  610. params.type = params.type.replace('#wechat-redirect', '');
  611. }
  612. console.log('微信扫码之后,处理过的参数', params);
  613. this.$store.commit('SET_UNLICENSED_INFO', params);
  614. this.$nextTick(() => {
  615. this.qrCodesRule(params.code, 'scan');
  616. })
  617. return
  618. }
  619. /*
  620. 针对微信的小程序码进行的兼容改造
  621. 微信扫码结束之后的返回参数 {"errMsg": "scanCode:ok", "scanType": "WX_CODE", "charSet": "ISO8859-1", "rawData": "bGsoP3gyT1Aud3QpbW1JeHRfVHJsUjg4JnR5cGU9dW5saWNlbnNlZElu", "path": "pages/automatic/automaticIndex?scene=code%3D9988%26type%3DunlicensedIn"}
  622. */
  623. if (res.scanType && res.scanType === 'WX_CODE' && res.path) {
  624. const params = getUrlParams(`?${decodeURIComponent(res.path.replace(/.*scene=/g, ''))}`)
  625. this.$store.commit('SET_UNLICENSED_INFO', params);
  626. this.$nextTick(() => {
  627. this.qrCodesRule(params.code, 'scan');
  628. })
  629. }
  630. // 兜底逻辑,如果是其他小程序扫描,则提取rawData,进行解析提取入参
  631. if (res.scanType && res.scanType === 'WX_CODE' && !res?.path) {
  632. let path = atob(res.rawData)
  633. path = path.replace(/.*([a-z0-9]{6}&type)/g, '8b$1')
  634. const regex = /(\w+)&type=(\w+)/;
  635. const match = path.match(regex);
  636. const obj = {code: match[1], type: match[2]};
  637. this.$store.commit('SET_UNLICENSED_INFO', obj);
  638. this.$nextTick(() => {
  639. this.qrCodesRule(obj.code, 'scan');
  640. })
  641. }
  642. };
  643. // 微信小程序
  644. // const platform = getPlatform();
  645. if (isAlipayClient) {
  646. // 判断微信小程序与 h5 是否正常通信
  647. // const isReload = await theCommunicationBetweenWechatAndH5IsNormal()
  648. // if(!isReload) {
  649. // uni.setStorageSync('isReload', 1)
  650. // window.location.reload()
  651. // return
  652. // }
  653. window.toWXSendMsg({
  654. type: 'scanQRCode',
  655. });
  656. // TODO 兼容支付宝无牌车扫码
  657. window.subscribe('scanQRCodeOver', (options) => {
  658. console.log('微信扫码结束之后的返回参数', options);
  659. runScanFn(options.options);
  660. });
  661. } else {
  662. this.$wx.scanQRCode({
  663. onlyFromCamera: false,
  664. // desc: 'scanQRCode desc',
  665. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  666. // scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  667. success: (res) => {
  668. console.log('H5页面扫码获取到的参数——成功1', res);
  669. // const res = {"resultStr": "lo$Qed.3YuVi*D7vXilrrV0571a1&type=unlicensedIn", "errMsg": "scanQRCode:ok"}
  670. // const test = {"resultStr": "lp$Qed.3YuVi*D7vXilrrV0571a2&type=unlicensedOut", "errMsg": "scanQRCode:ok"}
  671. let path = res.resultStr.replace(/.*([a-z0-9]{6}&type)/g, '8b$1')
  672. console.log(614, path);
  673. const regex = /(\w+)&type=(\w+)/;
  674. const match = path.match(regex);
  675. const obj = {code: match[1], type: match[2]};
  676. console.log(618, obj);
  677. console.log(696, this.qrCodesRule);
  678. this.$store.commit('SET_UNLICENSED_INFO', obj);
  679. this.$nextTick(() => {
  680. this.qrCodesRule(obj.code, 'scan');
  681. })
  682. // runScanFn(res);
  683. // this.formMsg.deviceCode = res.resultStr;
  684. },
  685. error: (res) => {
  686. console.log('H5页面扫码获取到的参数——失败', res);
  687. // console.log(242, res);
  688. },
  689. });
  690. }
  691. } catch (err) {
  692. console.log(624, err);
  693. }
  694. },
  695. // 处理扫码结果: 组装参数,剩余流程,在 缴费支付页面 实现
  696. async qrCodesRule(code, source = '') {
  697. console.log(717, code, source);
  698. // source 是为了避免重复刷新
  699. if (this.$store.state.pageHistory.parkingFeeMsg && !source) {
  700. return
  701. }
  702. try {
  703. if (this.qrCodeHistory && this.qrCodeHistory === code) {
  704. return
  705. }
  706. this.qrCodeHistory = code
  707. const qrCodesres = await qrCodes(code); // 无牌车扫码
  708. // 记录buildingId,确保 buildingId 是最新的数据
  709. window.localStorage.setItem('buildingId', qrCodesres.buildingId);
  710. // 如果是无牌车扫码:出场
  711. // console.log('模拟出场', this.unlicensedInfo.type);
  712. this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  713. name: 'parkingFeeDetail',
  714. });
  715. console.log(735);
  716. // return
  717. if (this.unlicensedInfo?.type === 'unlicensedOut') {
  718. const query = {
  719. ...this.$route.query,
  720. gateId: qrCodesres.gateId,
  721. vehicleNo: '',
  722. type: this.unlicensedInfo.type
  723. }
  724. // fromPage && format && unlicensed
  725. query.fromPage = ''
  726. query.format = ''
  727. query.unlicensed = ''
  728. query.code = ''
  729. this.$router.push({
  730. path: 'parkingFeeDetail',
  731. query
  732. })
  733. return
  734. }
  735. // 如果是无牌车扫码:入场
  736. const unlicensedCarCheckInres = await unlicensedCarCheckIn({ // 获取无牌车牌
  737. gateId: qrCodesres.gateId
  738. });
  739. const query = {
  740. ...this.$route.query,
  741. type: 'success',
  742. vehicleNo: unlicensedCarCheckInres.vehicleNo
  743. }
  744. // fromPage && format && unlicensed
  745. query.fromPage = ''
  746. query.format = ''
  747. query.unlicensed = ''
  748. query.code = ''
  749. this.$store.commit('setPageHistory', {
  750. parkingFeeMsg: 1
  751. })
  752. // 前往 缴费支付页面
  753. this.$router.push({
  754. path: 'parkingFeeMsg',
  755. query: query
  756. })
  757. } catch (err) {
  758. // 车场扫描道闸入口,发现无车/车场扫描道闸入口,发现有牌车 >>> 停止往下执行,默认提示报错信息
  759. if (/CAR_HAS_PLATE/.test(err.code)) {
  760. return
  761. }
  762. if (/CAR_NOT_FOUND|INOUT_FAILED|UNLICENSED_PLATE_ACQUISITION_FAILED/.test(err.code)) {
  763. const query = {
  764. ...this.$route.query,
  765. type: 'fail'
  766. }
  767. // fromPage && format && unlicensed
  768. query.fromPage = ''
  769. query.format = ''
  770. query.unlicensed = ''
  771. query.code = ''
  772. this.$store.commit('setPageHistory', {
  773. parkingFeeMsg: 1
  774. })
  775. // 如果是其他错误的话,则继续往下执行
  776. this.$router.push({
  777. path: 'parkingFeeMsg',
  778. query
  779. })
  780. }
  781. }
  782. },
  783. // 前往支付
  784. unlicensedToPay() {
  785. // 无牌车这边去支付的时候,属于场内缴费,需要调用场内缴费的接口 /parking/check-out
  786. this.$store.commit('SET_ENDLESS_LOOP', '');
  787. this.toHandleSearch(this.unlicensedCar);
  788. },
  789. // 获取会员绑定的车牌列表
  790. async getVehiclesINTMP() {
  791. /*杭州*/
  792. if (!isHZ(this.mallId)) return
  793. try {
  794. let vehicles = []
  795. // 获取用户车场在停车辆数据集
  796. vehicles = await parkingRecord({
  797. userId: this.kipUserId,
  798. lbsId: this.mallId
  799. })
  800. // 获取用户的所有车牌
  801. const userVehicles = await getVehicles(this.kipUserId)
  802. if (!vehicles.length) {
  803. vehicles = userVehicles.content
  804. }
  805. if (vehicles.length) {
  806. const vehicleNo = vehicles[0].vehicleNo
  807. // 设置车牌类型
  808. this.setVehicleNoType(vehicleNo, userVehicles.content)
  809. // 赋值
  810. this.numArr = vehicles[0].vehicleNo.split('');
  811. this.vehicleNumber = vehicles[0].vehicleNo;
  812. } else {
  813. throw new Error('202')
  814. }
  815. } catch (e) {
  816. // 设置默认参数
  817. this.numArr = '浙,A,,,,,'.split(',')
  818. }
  819. },
  820. setVehicleNoType(vehicleNo, vehicles) {
  821. if(vehicleNo.indexOf('临') === 0) {
  822. this.tabbarActive = '无牌缴费'
  823. return
  824. }
  825. const item = vehicles.filter(e => e.vehicleNo === vehicleNo)
  826. if(item.length) {
  827. let label = LICENSE_PLATE_TYPE_ARR.filter(e => e.value == item[0].licensePlateType)
  828. const index = ['燃油车牌', '新能源', '特殊车牌'].indexOf(label[0].name)
  829. this.$refs['k-tab'].changeTab(index)
  830. return true
  831. }
  832. return false
  833. },
  834. setLicensePlateList(arr) {
  835. var array = []
  836. arr.forEach(element => {
  837. array.push(element.vehicleNo)
  838. });
  839. return array
  840. },
  841. },
  842. };