order.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. import { checkOut, calculateDiscount, ordersAndPrepay, currentUnlicensedPlate, unlicensedCarCheckIn, unlicensedCarCheckout } from '@/api/parking';
  2. // import checkOutQHResponse from '@/api/mockData/checkout.qh3.response.json'
  3. // import checkOutQHResponse from '@/api/mockData/checkout.hz.response.json';
  4. import checkOutQHResponse from '@/api/mockData/checkout.qh7.response.json'
  5. // import unlicensedCarCheckInResponse from '@/api/mockData/unlicensedCarCheckIn.qh.response.json';
  6. /*
  7. ([a-z]*):(.*),
  8. state.$1 =$2;
  9. */
  10. // 大于等于停车费
  11. // 微服务接口字段
  12. const state = {
  13. // 微服务接口字段
  14. orderDetail: {}, // 订单原始数据
  15. isShowDiscounts: false, // 是否展示会员登记优惠
  16. discountDesc: '', // 停车优惠(首停、会员减免、消费减免)
  17. checkedTotal: 0, // 选中count数
  18. enableNewMemberPoints: false, // 是否开启新会员积分
  19. enablePoints: false, // 是否开启积分减免
  20. usePoints: 0, // 用户已选择的积分
  21. isFirst: 0, // 判断用户是否首次进入
  22. integralDesc: '', // 积分减免说明文案
  23. pointsPerHour: 0, // 每小时兑换积分
  24. enableCoupon: false, // 电子优惠券是否启用
  25. maxOneDayCoupons: 0, // 单日可选优惠券上限
  26. coupons: [], // 可选优惠券数量
  27. couponCount: 0, // 已选择优惠券
  28. couponDesc: '', // 优惠券说明文案
  29. enablePaperCoupons: false, // 启动纸质优惠券
  30. usingTotalDiscount: 0, // 优惠金额
  31. actualPayFee: 0, // 应付金额
  32. availableDiscountFee: 0, // 当日剩余可使用优惠金额
  33. // 积分相关
  34. available: 0, // 用户可用积分
  35. maxPointsTime: '', // 积分最大兑换时长
  36. pointsTime: '', // 已兑换的积分时间
  37. unitAmount: 0,
  38. // 停车优惠:会员等级和消费减免
  39. memberLevelDiscount: false, // 是否开启会员等级
  40. enableConsume: false, // 是否开启消费减免
  41. pointsPerUnit: 0, //
  42. // unlicensed: false // true: 临时车牌;false:普通车牌
  43. // 无牌车逻辑
  44. unlicensedCar: '',
  45. };
  46. const mutations = {
  47. setOrderDetail(state, payload) {
  48. state.orderDetail = payload;
  49. },
  50. setIsShowDiscounts(state, payload) {
  51. state.isShowDiscounts = payload;
  52. },
  53. setCheckedTotal(state, payload) {
  54. state.checkedTotal = payload;
  55. },
  56. setDiscountDesc(state, payload) {
  57. state.discountDesc = payload;
  58. },
  59. setEnableNewMemberPoints(state, payload) {
  60. state.enableNewMemberPoints = payload;
  61. },
  62. setEnablePoints(state, payload) {
  63. state.enablePoints = payload;
  64. },
  65. setIsFirst(state, payload) {
  66. state.isFirst = payload;
  67. },
  68. setIntegralDesc(state, payload) {
  69. state.integralDesc = payload;
  70. },
  71. setUsePoints(state, payload) {
  72. state.usePoints = payload;
  73. },
  74. setEnableCoupon(state, payload) {
  75. state.enableCoupon = payload;
  76. },
  77. setMaxOneDayCoupons(state, payload) {
  78. state.maxOneDayCoupons = payload;
  79. },
  80. setCoupons(state, payload) {
  81. state.coupons = payload;
  82. },
  83. setCouponCount(state, payload) {
  84. state.couponCount = payload;
  85. },
  86. setCouponDesc(state, payload) {
  87. state.couponDesc = payload;
  88. },
  89. setEnablePaperCoupons(state, payload) {
  90. state.enablePaperCoupons = payload;
  91. },
  92. setUsingTotalDiscount(state, payload) {
  93. state.usingTotalDiscount = payload;
  94. },
  95. setActualPayFee(state, payload) {
  96. state.actualPayFee = payload;
  97. },
  98. setAvailableDiscountFee(state, payload) {
  99. state.availableDiscountFee = payload;
  100. },
  101. setPointsPerHour(state, payload) {
  102. state.pointsPerHour = payload;
  103. },
  104. setAvailable(state, payload) {
  105. state.available = payload;
  106. },
  107. setMaxPointsTime(state, payload) {
  108. state.maxPointsTime = payload;
  109. },
  110. setPointsTime(state, payload) {
  111. state.pointsTime = payload;
  112. },
  113. setEnableConsume(state, payload) {
  114. state.enableConsume = payload;
  115. },
  116. setMemberLevelDiscount(state, payload) {
  117. state.memberLevelDiscount = payload;
  118. },
  119. setPointsPerUnit(state, payload) {
  120. state.pointsPerUnit = payload;
  121. },
  122. setMaxOneDayDiscountFee(state, payload) {
  123. state.maxOneDayDiscountFee = payload;
  124. },
  125. setUnitAmount(state, payload) {
  126. state.unitAmount = payload;
  127. },
  128. setMaxDiscountFee(state, payload) {
  129. state.maxDiscountFee = payload;
  130. },
  131. setUnlicensedCar(state, payload) {
  132. state.unlicensedCar = payload;
  133. },
  134. // 订单初始化
  135. clearOrderInfo(state) {
  136. state.orderDetail = {}; // 订单原始数据
  137. state.isShowDiscounts = false; // 是否展示会员登记优惠
  138. state.discountDesc = ''; // 停车优惠(首停、会员减免、消费减免)
  139. state.checkedTotal = 0; // 选中count数
  140. state.enableNewMemberPoints = false; // 是否开启新会员积分
  141. state.enablePoints = false; // 是否开启积分减免
  142. state.usePoints = 0; // 用户已选择的积分
  143. state.isFirst = 0; // 判断用户是否首次进入
  144. state.integralDesc = ''; // 积分减免说明文案
  145. state.pointsPerHour = 0; // 每小时兑换积分
  146. state.enableCoupon = false; // 电子优惠券是否启用
  147. state.maxOneDayCoupons = 0; // 单日可选优惠券上限
  148. state.coupons = []; // 可选优惠券数量
  149. state.couponCount = 0; // 已选择优惠券
  150. state.couponDesc = ''; // 优惠券说明文案
  151. state.enablePaperCoupons = false; // 启动纸质优惠券
  152. state.usingTotalDiscount = 0; // 优惠金额
  153. state.actualPayFee = 0; // 应付金额
  154. state.availableDiscountFee = 0; // 当日剩余可使用优惠金额
  155. // 积分相关
  156. state.available = 0; // 用户可用积分
  157. state.maxPointsTime = ''; // 积分最大兑换时长
  158. state.pointsTime = ''; // 已兑换的积分时间
  159. state.unitAmount = 0;
  160. // 停车优惠:会员等级和消费减免
  161. state.memberLevelDiscount = false; // 是否开启会员等级
  162. state.enableConsume = false; // 是否开启消费减免
  163. state.pointsPerUnit = 0; //
  164. // unlicensed: false // true: 临时车牌;false:普通车牌
  165. // 无牌车逻辑
  166. state.unlicensedCar = '';
  167. }
  168. };
  169. const actions = {
  170. /**
  171. * 车辆订单的缴费信息初始化
  172. * @param {*} param0
  173. * @param {*} param1.gateId 车场闸机口ID
  174. * @param {*} param1.vehicleNo 车牌号(包含临牌)
  175. * @param {*} param1.callback 回调函数,用于接口报错时,展示对应的信息
  176. * @param {*} param1.endlessLoop 用于判断当前用户是否扫码进入
  177. */
  178. async orderInit({ commit, dispatch, state }, { gateId = '124p3LK1', vehicleNo = '浙A616A1', callback, endlessLoop }) {
  179. try {
  180. commit('clearOrderInfo');
  181. const unlicensed = vehicleNo.indexOf('临') > -1 || !vehicleNo; // true: 临时车牌;false:普通车牌
  182. // const res = await checkOut('浙A616A1');
  183. // const res = await checkOut('闽AAQ5519', unlicensed);
  184. // const res = await checkOut('粤A51113');
  185. // const res = await checkOut('沪DCJ986');
  186. // console.log('无牌车扫码出场', endlessLoop);
  187. // 场内缴费,调 check-out 接口,
  188. const method = unlicensed && endlessLoop || !vehicleNo ? unlicensedCarCheckout : checkOut
  189. const res = await method(vehicleNo, unlicensed, gateId);
  190. // const res = checkOutQHResponse
  191. if (res?.parkingRecord?.totalFee <= 0) {
  192. callback && callback({
  193. unlicensed,
  194. endlessLoop,
  195. code: endlessLoop,
  196. orderDetail: res,
  197. }); // 统一处理错误原因
  198. return
  199. }
  200. // console.log(vehicleNo, res);
  201. // 所有的优惠时间长转为金额
  202. console.log(112, '所有的优惠时间长转为金额');
  203. // dispatch('orderInitRule', checkOutQHResponse);
  204. dispatch('orderInitRule', res);
  205. } catch (error) {
  206. console.log('151151151151151', error);
  207. /* if (/NOT_FOUND|PARKING_RECORD_NOT_FOUND/.test(error.code)) {
  208. callback && callback(error)
  209. } */
  210. callback && callback(error); // 统一处理错误原因
  211. }
  212. },
  213. orderInitRule({ commit, dispatch, state }, checkOutResponse) {
  214. console.log(119, checkOutResponse);
  215. // 记录buildingId
  216. if (checkOutResponse?.parkInfo?.buildingId) {
  217. window.localStorage.setItem('buildingId', checkOutResponse.parkInfo.buildingId);
  218. }
  219. commit('setOrderDetail', checkOutResponse);
  220. const isShowDiscounts = checkOutResponse?.parkingRule?.enableCoupon || false;
  221. // 是否展示优惠
  222. commit('setIsShowDiscounts', isShowDiscounts);
  223. if (checkOutResponse.parkingRule) {
  224. // 会员等级减免
  225. // 停车优惠(首停、会员减免、消费减免)
  226. dispatch('getCheckedTotal', checkOutResponse);
  227. // 是否开启新会员积分(hold)
  228. commit('setEnableNewMemberPoints', checkOutResponse.parkingRule.enableNewMemberPoints);
  229. // 积分减免
  230. dispatch('pointsRule', checkOutResponse);
  231. // dispatch('getIntegralDesc', checkOutResponse.parkingRule.enablePoints);
  232. // 电子优惠券:是否启用
  233. // 处理电子优惠券相关逻辑
  234. dispatch('couponRule', checkOutResponse);
  235. // 纸质优惠券(hold)
  236. commit('setEnablePaperCoupons', checkOutResponse?.parkingRule?.enablePaperCoupons || false);
  237. // 其他数据收集
  238. commit('setUsingTotalDiscount', checkOutResponse?.discountInfo?.usingTotalDiscount || 0);
  239. // console.log(191, checkOutResponse?.parkingRecord.hasOwnProperty(actualPayFee));
  240. }
  241. if (checkOutResponse?.parkingRecord?.hasOwnProperty('actualPayFee')) {
  242. commit('setActualPayFee', checkOutResponse.parkingRecord?.actualPayFee);
  243. } else {
  244. commit('setActualPayFee', checkOutResponse.parkingRecord?.totalFeeInYuan);
  245. }
  246. },
  247. // 停车优惠(首停、会员减免、消费减免)
  248. getCheckedTotal({ commit, dispatch }, orderDetail) {
  249. let checkedTotal = 0;
  250. console.log(orderDetail);
  251. if (orderDetail?.discountInfo?.memberLevelDiscount && orderDetail?.discountInfo?.memberGrade.length) {
  252. orderDetail.discountInfo.memberGrade.forEach((elm) => {
  253. if (elm.defaultSelected) {
  254. checkedTotal++;
  255. }
  256. });
  257. }
  258. if (orderDetail?.discountInfo?.consume?.length) {
  259. orderDetail.discountInfo.consume.forEach((elm) => {
  260. if (elm.defaultSelected) {
  261. checkedTotal++;
  262. }
  263. });
  264. }
  265. commit('setMemberLevelDiscount', orderDetail.discountInfo.memberLevelDiscount);
  266. commit('setCheckedTotal', checkedTotal);
  267. dispatch('getDiscountDesc', {
  268. orderDetail,
  269. checkedTotal,
  270. });
  271. },
  272. getDiscountDesc({ commit, dispatch }, { orderDetail, checkedTotal }) {
  273. if (orderDetail.parkingRule.enableConsume) {
  274. commit('setEnableConsume', orderDetail.parkingRule.enableConsume);
  275. if (checkedTotal > 0) {
  276. return commit('setDiscountDesc', `已选择${checkedTotal}项优惠`);
  277. }
  278. return commit('setDiscountDesc', `立即使用`);
  279. } else {
  280. return commit('setDiscountDesc', `暂无可用优惠`);
  281. }
  282. },
  283. // 积分相关计算(仅计算用户可使用的积分)
  284. pointsRule({ commit, dispatch, state }, checkOutResponse) {
  285. const { discountInfo, parkingRule, parkInfo } = checkOutResponse
  286. const {
  287. points,
  288. usingTotalDiscount, // 当前车辆的已使用优惠的总上限
  289. } = discountInfo;
  290. const {
  291. maxPointsTime = 0, // 最大积分
  292. enablePoints,
  293. availableDiscountFee,
  294. maxOneDayDiscountFee, // 每日最大优惠金额(深圳车场)
  295. remainConsumeTime, // 当前订单剩余可使用的优惠
  296. } = parkingRule;
  297. if ( !points ) return commit('setIntegralDesc', '暂无可用积分'); // 积分优惠处的描述
  298. const [
  299. {
  300. pointsPerHour,
  301. available, // 用户可用的积分(当前车辆在) available是用户选择抵扣N小时后剩余的可用积分
  302. maxDiscountFee, // 单次上限(元)
  303. unitAmount, // 兑换值(元)
  304. pointsPerUnit = 0, // 500积分对应的价值
  305. discountFee,
  306. label,
  307. },
  308. ] = points;
  309. commit('setAvailableDiscountFee', availableDiscountFee);
  310. dispatch('maxPointsTimeMath', checkOutResponse) // 剩余积分可兑换上限
  311. commit('setEnablePoints', enablePoints);
  312. commit('setAvailable', available);
  313. commit('setMaxPointsTime', maxPointsTime);
  314. commit('setMaxDiscountFee', maxDiscountFee);
  315. commit('setPointsTime', discountFee || 0);
  316. commit('setPointsPerUnit', pointsPerUnit);
  317. commit('setMaxOneDayDiscountFee', maxOneDayDiscountFee);
  318. commit('setPointsPerHour', pointsPerUnit);
  319. commit('setUnitAmount', unitAmount);
  320. commit('setIntegralDesc', discountFee ? `已选择兑换${discountFee}元` : available > pointsPerUnit ? `${available}积分可减免` : `${pointsPerUnit}积分可停车1小时`); // 积分优惠处的描述
  321. },
  322. // 当前最大可选优惠时间
  323. /*
  324. * 当前最大可选优惠时间
  325. * 1、不能超过积分上限
  326. * 2、
  327. * */
  328. maxPointsTimeMath({ commit, dispatch, state }, checkOutResponse) {
  329. const { discountInfo, parkingRule, parkInfo } = checkOutResponse
  330. const { points: [{
  331. available, // 用户可用的积分(当前车辆在) available是用户选择抵扣N小时后剩余的可用积分
  332. unitAmount, // 兑换值(元)
  333. pointsPerUnit = 0, // 500 积分对应的价值
  334. discountFee,
  335. maxDiscountFee,
  336. }] } = discountInfo
  337. // 总积分
  338. const max = available / pointsPerUnit * unitAmount;
  339. const timeNum = maxDiscountFee / unitAmount;
  340. console.log(';999988888;', timeNum);
  341. /**
  342. * maxDiscountFee 单次最大可使用金额
  343. * availableDiscountFee 当日剩余可使用优惠金额
  344. * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
  345. *
  346. */
  347. // if ( !state.maxPointsTime ) {
  348. // commit('setMaxPointsTime', discountFee || max)
  349. // }
  350. // if (
  351. // parkInfo.parkMallCode === 3 &&
  352. // enablePoints && !maxPointsTime
  353. // ) {
  354. // return commit('setIntegralDesc', `今日已达上限`);
  355. // }
  356. // return commit('setIntegralDesc', `${available}积分可减免`);
  357. },
  358. // 积分减免
  359. pointsMath({ commit, dispatch, state }, { type, callback }) {
  360. /**
  361. * maxDiscountFee 单次最大可使用金额
  362. * availableDiscountFee 当日剩余可使用优惠金额
  363. * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
  364. */
  365. // 计算用户当前的最大可使用积分的总数(单位:元)
  366. let maxPointsTime = state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime;
  367. if (maxPointsTime > state.maxDiscountFee) {
  368. maxPointsTime = state.maxDiscountFee
  369. }
  370. let msg = ''
  371. // 验证最大积分的总数(单位:元)
  372. if (maxPointsTime > state.availableDiscountFee) {
  373. maxPointsTime = state.availableDiscountFee
  374. }
  375. if (type === 'add' && state.pointsTime >= maxPointsTime) {
  376. // 以下是深圳积分上限规则
  377. // 超出抵扣上限,每日最高可抵扣${this.parkFee.parkInfoEntity.maxOneDayHour}元 '优惠金额' >= '每日最高可抵扣'
  378. if (state.usingTotalDiscount >= state.maxOneDayDiscountFee && !msg) {
  379. msg = `超出抵扣上限,每日最高可抵扣${state.maxOneDayDiscountFee}元`
  380. }
  381. // 超出抵扣上限,每次最高可抵扣${this.integralMaxMoney}元 '积分兑换时长' >= '深圳前海停车积分上限'q
  382. if (state.pointsTime >= maxPointsTime && !msg) {
  383. msg = `超出抵扣上限,每次最高可抵扣${state.maxDiscountFee}元`
  384. }
  385. callback({
  386. message: msg
  387. });
  388. return
  389. }
  390. if (type === 'add' && state.pointsTime < maxPointsTime) {
  391. const pointsTime = state.pointsTime + state.unitAmount;
  392. const available = state.available - state.pointsPerUnit;
  393. const usingTotalDiscount = state.usingTotalDiscount + state.unitAmount; // 重新计算已经使用的优惠逻辑
  394. if (available > -1) {
  395. // 如果是深圳车场
  396. commit('setAvailable', available);
  397. commit('setPointsTime', pointsTime);
  398. commit('setUsingTotalDiscount', usingTotalDiscount);
  399. }
  400. }
  401. if (type === 'minus' && state.pointsTime > 0) {
  402. const pointsTime = state.pointsTime - state.unitAmount;
  403. // 如果是深圳车场
  404. commit('setAvailable', state.available + state.pointsPerUnit);
  405. commit('setPointsTime', pointsTime);
  406. }
  407. },
  408. cancelPointsMath({ commit, dispatch, state }, callback) {
  409. const {
  410. discountInfo: { points },
  411. parkingRule,
  412. } = state.orderDetail;
  413. if(!points) {
  414. callback && callback();
  415. return
  416. }
  417. const [{ pointsPerHour, available, discountFee }] = points;
  418. const { maxPointsTime, enablePoints } = parkingRule;
  419. commit('setAvailable', available);
  420. commit('setPointsTime', discountFee || 0);
  421. callback && callback();
  422. },
  423. async savePointsMath({ commit, dispatch, state }, callback) {
  424. try {
  425. const orderDetail = { ...state.orderDetail };
  426. // 如果是重复提交,则不做重新计算
  427. if (orderDetail.discountInfo.points[0].available === state.available) {
  428. callback && callback();
  429. return
  430. }
  431. // 计算积分修改之后的金额,返回给后端
  432. // orderDetail.discountInfo.points[0].discountFee = state.pointsTime * orderDetail.discountInfo.points[0].unitAmount;
  433. orderDetail.discountInfo.points[0].discountFee = state.pointsTime;
  434. orderDetail.discountInfo.points[0].available = state.available;
  435. orderDetail.discountInfo.points[0].selected = true;
  436. /* 其他优惠统计 */
  437. // 优惠券: 如果没有添加 selected 字段,则增加 selected; 默认取 defaultSelected;
  438. if (orderDetail?.discountInfo?.hasOwnProperty('coupons') && !orderDetail?.discountInfo?.coupons[0]?.hasOwnProperty('selected')) {
  439. orderDetail.discountInfo.coupons = orderDetail.discountInfo.coupons.map(elm => {
  440. elm.selected = elm.defaultSelected || false;
  441. return elm;
  442. })
  443. }
  444. const res = await calculateDiscount({
  445. ...orderDetail,
  446. });
  447. console.log('积分修改失败', { res });
  448. dispatch('orderInitRule', res);
  449. callback && callback();
  450. } catch (err) {
  451. console.log('积分修改失败!', err);
  452. callback && callback();
  453. }
  454. //
  455. },
  456. async saveCouponMath({ commit, dispatch, state }, { couponList, callback }) {
  457. const orderDetail = { ...state.orderDetail };
  458. orderDetail.discountInfo.coupons = couponList;
  459. if (orderDetail?.discountInfo?.points[0]?.discountFee) {
  460. orderDetail.discountInfo.points[0].selected = true;
  461. } else {
  462. orderDetail.discountInfo.points[0].selected = false;
  463. }
  464. try {
  465. const res = await calculateDiscount({
  466. ...orderDetail,
  467. });
  468. dispatch('orderInitRule', res);
  469. callback && callback();
  470. } catch (err) {
  471. console.log('积分修改失败!', err);
  472. callback && callback();
  473. }
  474. // commit('setCoupons', checkOutResponse.discountInfo.coupons);
  475. },
  476. getIntegralDesc() {
  477. // 自动勾选积分优惠
  478. // 深圳是最大抵扣金额
  479. // available
  480. /*
  481. if (this.duration > 0) {
  482. // 深圳特殊处理(单位:金额)
  483. if (this.parkMallCode === 5) {
  484. return `已选择兑换${this.duration}元`;
  485. }
  486. return `已选择兑换${this.duration}小时`;
  487. }
  488. if (this.bonusCopy < this.integral) {
  489. return `${this.integral}积分可停车1小时`;
  490. }
  491. if (
  492. this.parkMallCode === 3 &&
  493. this.member?.currnentintegral >= this.integral &&
  494. !this.bonus
  495. ) {
  496. return `今日已达上限`;
  497. }
  498. return `${this.bonus}积分可减免`;
  499. */
  500. },
  501. // 电子优惠券
  502. couponRule({ commit, dispatch, state }, checkOutResponse) {
  503. commit('setEnableCoupon', checkOutResponse.parkingRule.enableCoupon);
  504. if (checkOutResponse.parkingRule.enableCoupon) {
  505. // const {maxOneDayCoupons, remainConsumeTime, hourPrice} = checkOutResponse.parkingRule;
  506. // const {
  507. // usingTotalDiscount, // 使用总抵扣
  508. // coupons
  509. // } = checkOutResponse.discountInfo;
  510. // const {
  511. // totalFee, // 应缴
  512. // actualPayFee // 应付金额
  513. // } = checkOutResponse.parkingRecord;
  514. // // 剩余可使用的优惠金额,支持动态计算; 优惠时长,不可能全部使用,不能超过车费减去优惠的金额;不能超过单次的应付金额
  515. // let remainPrice = remainConsumeTime * hourPrice;
  516. // if ( remainPrice > actualPayFee ) {
  517. // remainPrice = actualPayFee;
  518. // }
  519. // let couponPrice = 0
  520. // // 确认优惠券是否可选择
  521. // let couponsList = coupons.sort((itema,itemb) => itema.discountFee - itemb.discountFee)
  522. // couponsList = couponsList.map(elm => {
  523. // if ( !elm.defaultSelected ) {
  524. // if ( elm.discountFee <= remainPrice && couponPrice <= remainPrice) {
  525. // elm.disabled = false
  526. // } else {
  527. // elm.disabled = true
  528. // }
  529. // }
  530. // })
  531. // console.log(343, {couponsList});
  532. // commit('setCoupons', couponsList);
  533. commit('setMaxOneDayCoupons', checkOutResponse.parkingRule.maxOneDayCoupons); // 仅在杭州使用
  534. // 根据时间排序电子兑换券
  535. const couponSort = (a,b) => {
  536. let aTime = new Date(`${a.expirationDate}`.replace(/-/g, '/'));
  537. let bTime = new Date(`${b.expirationDate}`.replace(/-/g, '/'));
  538. let aN = aTime.getTime(aTime) // 方法1
  539. let bN = bTime.getTime(bTime) // 方法2
  540. return aN - bN;
  541. }
  542. const coupons = checkOutResponse.discountInfo.coupons.sort(couponSort)
  543. commit('setCoupons', coupons);
  544. // 统计已选择优惠券
  545. let couponCount = 0;
  546. checkOutResponse.discountInfo.coupons.forEach((elm) => {
  547. const selected = elm.hasOwnProperty('selected') ? elm.selected : elm.defaultSelected;
  548. if (selected) {
  549. couponCount++;
  550. }
  551. });
  552. commit('setCouponCount', couponCount);
  553. console.log(479, couponCount);
  554. if (couponCount > 0) {
  555. return commit('setCouponDesc', `已选择${couponCount}张优惠劵`);
  556. } else {
  557. if (checkOutResponse.discountInfo.coupons.length) {
  558. return commit('setCouponDesc', `您有${checkOutResponse.discountInfo.coupons.length}张可用优惠劵`);
  559. }
  560. return commit('setCouponDesc', `暂无可用优惠券`);
  561. }
  562. } else {
  563. commit('setCouponDesc', `暂无可用优惠券`);
  564. }
  565. },
  566. // 无牌车逻辑
  567. async unlicensedRule({ commit, dispatch, state }, callback) {
  568. try {
  569. // const res = await currentUnlicensedPlate(); // 无牌车查询
  570. // const res = await unlicensedCarCheckIn({gateId: 1}); // 无牌车入场
  571. /**
  572. * CAR_NOT_FOUND 车场扫描道闸入口,发现无车
  573. * CAR_HAS_PLATE 车场扫描道闸入口,发现有牌车
  574. */
  575. // const res = unlicensedCarCheckInResponse;
  576. const res = await currentUnlicensedPlate();
  577. console.log('无牌车的查询记录', res);
  578. commit('setUnlicensedCar', res.vehicleNo);
  579. // 如果是扫码进入的用户,在出场时需要重新扫码,这时会在此处传入的一个回调函数,在获取到临牌时,返回给 qrCodesRule 函数
  580. if (res.vehicleNo && callback) {
  581. callback(res.vehicleNo);
  582. } else {
  583. callback('error');
  584. }
  585. } catch (err) {
  586. console.log(err);
  587. }
  588. },
  589. // 是否展示优惠
  590. // getIsShowDiscounts({commit, dispatch}, orderDetail) {
  591. // params?.parkingRule?.enableCoupon
  592. // }
  593. // calculateDiscount
  594. /*
  595. 如果积分发生变化
  596. */
  597. };
  598. export default {
  599. //开启命名模块
  600. namespaced: true,
  601. state: state,
  602. mutations,
  603. actions,
  604. };