index.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. import { Toast } from "vant";
  2. import { mapState } from 'vuex';
  3. import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
  4. import { cloneDeep } from 'lodash'
  5. import baseMixins from '../mixins/base';
  6. import { waitByTime } from "@/utils";
  7. // import uni from '@/utils/uniHooks';
  8. // const app = getApp()
  9. export default {
  10. mixins: [baseMixins],
  11. components: { uniNumberBox },
  12. created() {
  13. // 超限提示
  14. // this.crossMessage();
  15. },
  16. // beforeRouteLeave(to, from, next) {
  17. // console.log(251251251251251251, to, from,);
  18. // // 设置下一个路由的 meta
  19. // to.meta.keepAlive = true; // 让 A 不缓存,即刷新
  20. // next();
  21. // },
  22. data() {
  23. return {
  24. checkedList: [], // 已选优惠列表
  25. oldCheckedList: [], // 已选优惠列表备份
  26. isMember: true, // member
  27. isReduces: true, // reduces
  28. memberLevelReduce: [],
  29. memberGrade: {},
  30. consume: {},
  31. // todayReduceDiscountMessage: '',
  32. isMemberDiscountDisabled: false,
  33. maxDiscountTime: 0,
  34. enableConsumeSplit: false,
  35. maxReduceDiscount: 0,
  36. reduceHours: 0,
  37. remainPrice: 0,
  38. isInit: 1,
  39. };
  40. },
  41. computed: {
  42. ...mapState({
  43. orderDetail: (state) => state.order.orderDetail,
  44. custTypeId: (state) => state.custTypeId,
  45. groupId: (state) => state.groupId,
  46. enableConsume: (state) => state.order.enableConsume,
  47. actualPayFee: (state) => state.order.actualPayFee,
  48. usingTotalDiscount: (state) => state.order.usingTotalDiscount,
  49. memberLevelDiscount: (state) => state.order.memberLevelDiscount,
  50. checkedTotal: (state) => state.order.checkedTotal,
  51. parkMallCode: (state) => state.order.parkMallCode,
  52. paperDiscountTime: (state) => state.order.paperDiscountTime,
  53. paperDiscountFee: (state) => state.order.paperDiscountTime,
  54. availableDiscountFee: (state) => state.order.availableDiscountFee,
  55. }),
  56. enableConsumeNonSplit() {
  57. return this.orderDetail.parkingRule.enableConsumeNonSplit
  58. },
  59. stepperMin() {
  60. // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
  61. if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
  62. return this.reduceHours || 0
  63. }
  64. // 如果不存消费减免,默认展示0
  65. if (JSON.stringify(this.consume) === '{}') {
  66. return 0
  67. }
  68. // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
  69. return 1
  70. },
  71. stepperMax() {
  72. if (this.parkMallCode === 4 || this.parkMallCode === 6) {
  73. // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
  74. return this.maxReduceDiscount
  75. }
  76. // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
  77. if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
  78. return this.reduceHours || 0
  79. }
  80. // 如果不存消费减免,默认展示0
  81. if (JSON.stringify(this.consume) === '{}') {
  82. return 0
  83. }
  84. // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
  85. return this.maxReduceDiscount
  86. },
  87. // maxReduceDiscount() {
  88. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  89. // let newMaxConsumeTime = maxConsumeTime
  90. // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice
  91. // console.log(52, this.remainPrice)
  92. // if ( this.remainPrice + (newMaxConsumeTime * hourPrice) > maxOneTimeDiscountFee ) {
  93. // newMaxConsumeTime = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice
  94. // }
  95. // return maxConsumeTime
  96. // },
  97. // remainPrice() {
  98. // let remainPrice = this.usingTotalDiscount
  99. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  100. // let newMaxConsumeTime = maxConsumeTime
  101. // if ( this.checkedList.indexOf('member') > -1) {
  102. // remainPrice = remainPrice + this.memberGrade.discountFee
  103. // }
  104. // if ( this.checkedList.indexOf('reduces') > -1) {
  105. //
  106. // }
  107. //
  108. //
  109. //
  110. //
  111. // return remainPrice
  112. // }
  113. // 消费减免(拆分部分)提示文本
  114. reduceSplitMessage() {
  115. // console.log(106, this.reduceHours);
  116. if (!this.enableConsumeNonSplit) {
  117. return `选择${this.reduceHours}小时,`;
  118. }
  119. return '';
  120. },
  121. // 消费减免金额
  122. reducesDiscountFee() {
  123. return this.reduceHours * this.orderDetail.parkingRule.hourPrice;
  124. },
  125. // 消费减免说明文案
  126. todayReduceDiscountMessage() {
  127. // 静安浦东没有内容
  128. if (this.parkMallCode === 0 || this.parkMallCode === 1) {
  129. return ''
  130. }
  131. // 消费减免余额为 0 时
  132. if (!this.orderDetail.parkingRule.remainConsumeTime || !this.consume.hasOwnProperty('redeemSalesAmount')) {
  133. return `您暂无可用的消费减免`
  134. // return `您今日消费减免已达${this.orderDetail.parkingRule.maxConsumeTime}小时上限`
  135. }
  136. // 消费减免不存在时
  137. if (JSON.stringify(this.consume) === '{}') {
  138. return '消费金额未达到最低优惠要求'
  139. }
  140. // 静安存在消费减免时
  141. if (this.parkMallCode === 0) {
  142. return `今日可减免${this.consume.defaultDiscountTime}小时`;
  143. }
  144. // 沈阳提示信息
  145. if (this.parkMallCode === 4 || this.parkMallCode === 6) {
  146. return `未达上限时今日可减免${this.stepperMax}小时`;
  147. }
  148. if (this.consume.defaultDiscountTime > this.orderDetail.parkingRule.remainConsumeTime) {
  149. return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。超出优惠上限,可减免${this.maxReduceDiscount}小时,${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
  150. }
  151. return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
  152. }
  153. },
  154. mounted() {
  155. try {
  156. this.isCheck(() => this.pageInit()); // 验证是否可选
  157. } catch (err) {
  158. // console.log(err);
  159. this.$router.back();
  160. }
  161. },
  162. watch: {
  163. remainPrice() {
  164. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  165. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  166. // console.log('hourPrice + this.remainPrice',this.remainPrice)
  167. // 单日上限
  168. // if ( oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee ) {
  169. // return Toast({
  170. // message: `每日最高可抵扣${ maxOneDayDiscountFee }元`,
  171. // icon: 'none',
  172. // });
  173. //
  174. // }
  175. // 单次上限限制
  176. if (oneTimeLimitation) {
  177. if (this.remainPrice <= maxOneTimeDiscountFee) {
  178. if (this.isMember) {
  179. this.isMember = !this.isMember;
  180. }
  181. if (this.isReduces) {
  182. this.isReduces = false;
  183. // console.log(109);
  184. }
  185. } else {
  186. this.isMember = this.checkedList.indexOf('member') < 0;
  187. this.isReduces = this.checkedList.indexOf('reduces') < 0;
  188. }
  189. }
  190. },
  191. checkedList(newVal, oldVal) {
  192. // console.log(190, { newVal, oldVal });
  193. if ((this.parkMallCode === 4 || this.parkMallCode === 6) && this.isInit > 1) {
  194. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  195. // 会员等级选中了
  196. if (newVal.indexOf('member') > -1 && oldVal.indexOf('member') < 0) {
  197. // console.log(193, '会员等级选中了');
  198. // this.remainPrice = this.remainPrice + this.memberGrade.discountFee;
  199. // this.maxReduceDiscountInit();
  200. }
  201. if (oldVal.indexOf('member') > -1 && newVal.indexOf('member') < 0) {
  202. // 会员等级未选中了
  203. // console.log(193, '会员等级未选中了');
  204. // this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  205. // this.maxReduceDiscountInit();
  206. }
  207. // 消费减免选中了
  208. if (newVal.indexOf('reduces') > -1 && oldVal.indexOf('reduces') < 0) {
  209. // console.log(193, '消费减免选中了');
  210. this.consume.discountFee = this.reduceHours * hourPrice
  211. this.remainPrice = this.remainPrice + this.consume.discountFee;
  212. }
  213. if (oldVal.indexOf('reduces') > -1 && newVal.indexOf('reduces') < 0) {
  214. // 消费减免未选中了
  215. // console.log(193, '消费减免未选中了');
  216. this.consume.discountFee = this.reduceHours * hourPrice
  217. this.remainPrice = this.remainPrice - this.consume.discountFee;
  218. }
  219. }
  220. // const {hourPrice} = this.orderDetail.parkingRule;
  221. // if ( this.checkedList.indexOf('reduces') > -1 ) {
  222. // this.remainPrice = this.reduceHours * hourPrice + this.remainPrice
  223. // } else {
  224. // this.remainPrice = this.remainPrice - this.reduceHours * hourPrice
  225. // }
  226. },
  227. },
  228. methods: {
  229. pageInit() {
  230. if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
  231. this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
  232. }
  233. this.checkedList = [];
  234. const { memberGrade = [{}], consume = [], memberLevelDiscount, points = [{}] } = this.orderDetail.discountInfo;
  235. const { maxConsumeTime, remainConsumeTime, hourPrice } = this.orderDetail.parkingRule;
  236. // 如果积分存在的话,则移除积分的优惠
  237. if (points.length && JSON.stringify(points[0]) !== "{}") {
  238. this.remainPrice = this.parkMallCode !== 1 ? this.usingTotalDiscount - points[0].discountFee : this.usingTotalDiscount;
  239. }
  240. this.memberGrade = { ...memberGrade[0] };
  241. this.consume = { ...consume[0] };
  242. if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
  243. this.checkedList.push('member');
  244. }
  245. this.isMember = JSON.stringify(this.memberGrade) === '{}';
  246. // console.log(140, this.consume, this.consume.hasOwnProperty('selected'), JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected, this.consume.defaultSelected)
  247. // console.log(143, JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected !== undefined : this.consume.defaultSelected !== undefined);
  248. if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
  249. this.checkedList.push('reduces');
  250. // this.isReduces = false;
  251. // 如果存在拆分逻辑的话
  252. // this.consume.
  253. }
  254. this.isReduces = this.consume.hasOwnProperty('selected') || this.consume.hasOwnProperty('defaultSelected') ? false : true;
  255. this.reduceHours = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / this.orderDetail.parkingRule.hourPrice : Math.min(this.consume.defaultDiscountTime, this.consume.maxDiscountTime);
  256. if (JSON.stringify(this.consume) !== '{}') {
  257. const isSelected = this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected;
  258. this.maxReduceDiscount = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / hourPrice : Math.min(this.consume.defaultDiscountTime, this.consume.maxDiscountTime);
  259. // const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee) / hourPrice
  260. // if (remainingLimitToIncrease) {
  261. // this.maxReduceDiscountInit();
  262. // }
  263. this.maxReduceDiscountInit();
  264. }
  265. this.oldCheckedList = [...this.checkedList];
  266. // 如果是杭州、沈阳可以选择
  267. // if (this.parkMallCode === 2 || this.parkMallCode === 4 || this.parkMallCode === 7) {
  268. // this.isReduces = JSON.stringify(this.consume) === '{}';
  269. // }
  270. // https://kerryprops.atlassian.net/browse/SCRM-4016?focusedCommentId=117842: 只要存在消费减免情况,都允许用户进行操作
  271. this.isReduces = JSON.stringify(this.consume) === '{}';
  272. this.discountInit()
  273. setTimeout(() => {
  274. this.isInit = this.isInit + 1
  275. }, 300)
  276. },
  277. discountInit() {
  278. if(this.parkMallCode === 4 || this.parkMallCode === 6 ) {
  279. const { maxConsumeTime, remainConsumeTime, hourPrice } = this.orderDetail.parkingRule;
  280. const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee) / hourPrice
  281. if(!remainingLimitToIncrease) {
  282. this.isMember = this.memberGrade.hasOwnProperty('selected')? !this.memberGrade.selected : !this.memberGrade.defaultSelected
  283. this.isReduces = this.consume.hasOwnProperty('selected')? !this.consume.selected : !this.consume.defaultSelected
  284. }
  285. }
  286. },
  287. maxReduceDiscountInit() {
  288. const {maxDiscountTime, couponCodes, defaultDiscountTime} = this.consume
  289. if(JSON.stringify(this.consume) === '{}' || !this.consume.hasOwnProperty('redeemSalesAmount')) {
  290. return
  291. }
  292. const { maxConsumeTime, remainConsumeTime, hourPrice, maxOneTimeDiscountTime } = this.orderDetail.parkingRule;
  293. const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee || 0) / hourPrice;
  294. // 如果是浦东的话, 重新计算优惠
  295. if (this.parkMallCode === 1 || this.parkMallCode === 0) {
  296. /*
  297. * 消费减免真实可用优惠的计算逻辑
  298. * 消费减免可能选择的情况: X
  299. * 其余已使用的优惠:W
  300. * 当前可使用优惠的上限:B
  301. * 当前消费减免最高可用优惠:D = B - ( W - X )
  302. * 当前消费减免用户可用优惠上限:Z
  303. * 消费减免真实可用优惠: D > Z ? Z : D
  304. * */
  305. const isSelected = this.checkedList.indexOf('reduces') > -1;
  306. // const reduceHours = isSelected ? this.reduceHours : 0
  307. const remainHour = this.remainPrice / hourPrice
  308. // 当前订单的总可用余额: remainConsumeTime
  309. const couponCodesLength = couponCodes?.split('#')?.length || 0; // 上限
  310. // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  311. // 实际上限
  312. // remainConsumeTime - this.reduceHours 剩余优惠
  313. // couponCodesLength - this.reduceHours 剩余上限
  314. // 实际上限 = 剩余优惠 <= 剩余上限
  315. // this.maxReduceDiscount = remainConsumeTime - this.reduceHours <= couponCodesLength - this.reduceHours
  316. // 转化公式之后
  317. // this.maxReduceDiscount = remainConsumeTime > couponCodesLength ? couponCodesLength : remainConsumeTime
  318. // console.log(319, this.remainPrice >= maxOneTimeDiscountFee)
  319. // this.maxReduceDiscount = couponCodesLength > defaultDiscountTime ? defaultDiscountTime> remainHour > defaultDiscountTime ? defaultDiscountTime : remainHour : remainHour > couponCodesLength?couponCodesLength:remainHour;
  320. this.maxReduceDiscount = defaultDiscountTime;
  321. // 323323323 3 2 2 2
  322. // 323323323 3 1 2 1
  323. // console.log('323323323', couponCodesLength, remainHour, defaultDiscountTime, this.reduceHours )
  324. // this.reduceHours = this.maxReduceDiscount
  325. !isSelected && remainConsumeTime - remainHour > 0 && defaultDiscountTime && (this.reduceHours = 1)
  326. // remainConsumeTime - remainHour > 0 && defaultDiscountTime && (this.reduceHours = 1)
  327. return
  328. // 如果超过限制就置灰
  329. // const maxOneTimeDiscountTimeFee = (couponCodes.split('#').length) * hourPrice
  330. // const isSelected = this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected;
  331. // const isCheckedListSelected = this.checkedList.indexOf('consume') > -1;
  332. // if(maxOneTimeDiscountTimeFee > this.remainPrice) {
  333. // // 优惠计算公式: 剩余可用优惠 + 已经选择的优惠 = 总的消费减免的优惠(小时)
  334. // const maxReduceDiscount = (maxOneTimeDiscountTimeFee - this.remainPrice) / hourPrice + (isSelected ? this.reduceHours : 0)
  335. // this.maxReduceDiscount = maxReduceDiscount > maxOneTimeDiscountTime ? maxOneTimeDiscountTime: maxReduceDiscount
  336. // !isSelected && (this.reduceHours = this.maxReduceDiscount)
  337. // return
  338. // }
  339. // if(maxOneTimeDiscountTimeFee == this.remainPrice && !isSelected && isCheckedListSelected) {
  340. // this.maxReduceDiscount = 0
  341. // this.reduceHours = this.maxReduceDiscount
  342. // return
  343. // } else {
  344. // this.maxReduceDiscount = this.reduceHours
  345. // }
  346. return
  347. }
  348. if (!remainingLimitToIncrease) {
  349. // if(!this.consume.selected) {
  350. // this.isReduces = true
  351. // }
  352. return
  353. }
  354. this.isReduces = false
  355. if (this.remainPrice >= this.availableDiscountFee) {
  356. // console.log('过大', this.maxReduceDiscount, remainingLimitToIncrease);
  357. this.maxReduceDiscount = this.maxReduceDiscount - remainingLimitToIncrease > maxDiscountTime ? maxDiscountTime : this.maxReduceDiscount - remainingLimitToIncrease
  358. this.consume.discountFee = this.consume.discountFee - (remainingLimitToIncrease * hourPrice)
  359. this.remainPrice = this.remainPrice - (remainingLimitToIncrease * hourPrice);
  360. this.reduceHours = this.maxReduceDiscount
  361. }
  362. if(this.checkedList.indexOf('reduces') < 0) {
  363. // 如果没被选中
  364. this.maxReduceDiscount = remainingLimitToIncrease > maxDiscountTime ? maxDiscountTime : remainingLimitToIncrease
  365. this.reduceHours = this.maxReduceDiscount
  366. this.consume.discountFee = remainingLimitToIncrease * hourPrice
  367. return
  368. }
  369. // 如果被选中
  370. // console.log('过小?', this.consume.discountFee, remainingLimitToIncrease);
  371. const maxReduceDiscount = this.consume.discountFee / hourPrice + remainingLimitToIncrease
  372. // console.log('过小', maxReduceDiscount);
  373. this.maxReduceDiscount = maxReduceDiscount <= remainConsumeTime ? maxReduceDiscount : remainConsumeTime
  374. this.maxReduceDiscount = this.maxReduceDiscount > maxDiscountTime ? maxDiscountTime: this.maxReduceDiscount
  375. },
  376. setIsMemberDiscountDisabled() {
  377. this.todayReduceDiscountMessage = '当日';
  378. },
  379. checkboxChange() { },
  380. onReduceHoursChange(type) {
  381. if (this.checkedList.indexOf('reduces') < 0) {
  382. return;
  383. }
  384. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  385. // console.log(133,this.reduceHours)
  386. // console.log(166, this.maxReduceDiscount);
  387. if (type === 'plus') {
  388. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage('onReduceHoursChange');
  389. if (isCrossMessage) {
  390. // this.remainPrice = this.remainPrice - hourPrice;
  391. // this.reduceHours = this.reduceHours - 1;
  392. return
  393. }
  394. this.remainPrice = this.remainPrice + hourPrice;
  395. this.reduceHours = this.reduceHours + 1;
  396. this.consume.discountFee = this.reduceHours * hourPrice
  397. return;
  398. }
  399. if (type === 'minus' && this.reduceHours > 1) {
  400. this.reduceHours = this.reduceHours - 1;
  401. this.remainPrice = this.remainPrice - hourPrice;
  402. this.consume.discountFee = this.reduceHours * hourPrice
  403. return;
  404. }
  405. },
  406. async memberClick() {
  407. await waitByTime(200)
  408. // 没有优惠时不做多余的事情
  409. if(JSON.stringify(this.memberGrade) === '{}') {
  410. return;
  411. }
  412. if(!this.actualPayFee) {
  413. Toast('当前无需追加优惠')
  414. this.checkedList = this.checkedList.filter(elm => elm !== 'member')
  415. return;
  416. }
  417. const { maxConsumeTime, remainConsumeTime, availableDiscountFee, hourPrice } = this.orderDetail.parkingRule;
  418. if (this.checkedList.indexOf('member') > -1) {
  419. /* 浦东 */
  420. if(this.parkMallCode === 1 || this.parkMallCode === 0) {
  421. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  422. if (!isCrossMessage) {
  423. this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
  424. } else {
  425. this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
  426. // this.remainPrice = this.remainPrice - this.memberGrade.discountFee
  427. this.isMember = false;
  428. }
  429. this.maxReduceDiscountInit();
  430. return
  431. }
  432. this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
  433. // 沈阳
  434. if (this.parkMallCode === 4 || this.parkMallCode === 6) {
  435. this.maxReduceDiscountInit();
  436. }
  437. } else if (!this.isMember) {
  438. // 浦东单独处理
  439. if(this.parkMallCode === 1 && this.parkMallCode === 0) {
  440. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  441. this.maxReduceDiscountInit();
  442. return
  443. }
  444. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  445. // 如果不是沈阳,重新计算优惠
  446. if (this.parkMallCode !== 4 && this.parkMallCode !== 6 && JSON.stringify(this.consume) !== '{}') {
  447. this.maxReduceDiscount = remainConsumeTime;
  448. }
  449. // 如果不是沈阳,重新计算优惠
  450. if (this.parkMallCode === 4 || this.parkMallCode === 6) {
  451. this.maxReduceDiscountInit();
  452. }
  453. }
  454. // 如果不是沈阳
  455. if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
  456. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  457. if (isCrossMessage) {
  458. this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
  459. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  460. this.isMember = false;
  461. }
  462. }
  463. },
  464. async reducesClick() {
  465. await waitByTime(200)
  466. if(!this.actualPayFee) {
  467. Toast('当前无需追加优惠')
  468. this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
  469. return;
  470. }
  471. // 没有优惠时不做多余的事情
  472. if(JSON.stringify(this.consume) === '{}') {
  473. return;
  474. }
  475. // 浦东
  476. if((this.parkMallCode === 1 || this.parkMallCode === 0) && (this.isReduces || !this.maxReduceDiscount) ) {
  477. return;
  478. }
  479. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime, remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee, availableDiscountFee } = this.orderDetail.parkingRule;
  480. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  481. if (this.checkedList.indexOf('reduces') > -1) {
  482. if(this.parkMallCode === 1 || this.parkMallCode === 0) {
  483. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  484. if(isCrossMessage) {
  485. this.checkedList = this.checkedList.filter((elm) => elm !== 'reduces');
  486. // this.remainPrice = this.remainPrice - this.memberGrade.discountFee
  487. // this.isReduces = false;
  488. return
  489. }
  490. // 如果还有剩余优惠的话,给一个默认值
  491. const {defaultDiscountTime} = this.consume
  492. const remainHour = this.remainPrice / hourPrice
  493. if(remainConsumeTime - remainHour > 0 && defaultDiscountTime){
  494. this.reduceHours = 1
  495. this.remainPrice = this.remainPrice + hourPrice
  496. }
  497. return;
  498. }
  499. if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
  500. // 如果不是沈阳,重新计算计算最大上限
  501. this.remainPrice = hourPrice + this.remainPrice;
  502. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  503. }
  504. } else {
  505. // this.remainPrice = this.remainPrice - hourPrice;
  506. // 如果不是沈阳,重新计算计算最大上限
  507. if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
  508. this.remainPrice = this.remainPrice - hourPrice;
  509. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  510. }
  511. }
  512. if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
  513. const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
  514. if (isCrossMessage) {
  515. this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
  516. }
  517. }
  518. },
  519. // 超限提示
  520. crossMessage(type) {
  521. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee, remainConsumeTime } = this.orderDetail.parkingRule;
  522. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  523. // console.log(373, this.remainPrice, this.availableDiscountFee);
  524. // 单日上限
  525. if (oneDayLimitation && this.remainPrice >= this.availableDiscountFee) {
  526. Toast({
  527. message: `每日最高可抵扣${maxOneDayDiscountFee}元`,
  528. icon: 'none',
  529. });
  530. return [true, (maxOneDayDiscountFee - (this.reduceHours - 1) * hourPrice) / hourPrice];
  531. }
  532. // 单次上限限制
  533. if (oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee) {
  534. Toast({
  535. message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
  536. icon: 'none',
  537. });
  538. // return [true,( maxOneTimeDiscountFee - (this.reduceHours - 1) * hourPrice ) / hourPrice]
  539. return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
  540. }
  541. // 单次上限限制 浦东
  542. const remainHour = this.remainPrice / hourPrice
  543. if (oneTimeLimitation && maxOneTimeDiscountTime - remainHour < 1) {
  544. Toast({
  545. message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
  546. icon: 'none',
  547. });
  548. return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
  549. }
  550. return [false, 0];
  551. },
  552. // 验证当前的选项是否可选择
  553. isCheck(callback) {
  554. if (!this?.orderDetail?.parkingRule) {
  555. return;
  556. }
  557. // const {parkInfo,parkingRule,discountInfo} = this.orderDetail
  558. const { maxOneTimeDiscountTime, maxOneDayDiscountFee, oneTimeLimitation, oneDayLimitation, hourPrice, remainConsumeTime } = this.orderDetail.parkingRule;
  559. // 浦东
  560. if (this.parkMallCode === 1 || this.parkMallCode === 0) {
  561. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  562. const remainConsumeTimeFee = remainConsumeTime * hourPrice;
  563. // TODO: 统计纸质优惠券的总金额, usingTotalDiscount,才是用户当前订单使用的优惠总数
  564. this.isMember = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.memberLevelDiscount);
  565. this.isReduces = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.enableConsume);
  566. }
  567. if (callback) callback();
  568. },
  569. reducesChange(value) {
  570. // console.log(149,value)
  571. },
  572. async confirm() {
  573. let orderDetail = cloneDeep(this.orderDetail);
  574. // 如果初次进来操作的跟原来的不一样则重新计算优惠
  575. if (this.checkedList.length !== this.checkedTotal || true) {
  576. ['member', 'reduces'].forEach((key) => {
  577. if (key === 'member' && JSON.stringify(this.memberGrade) !== '{}') {
  578. this.memberGrade = {
  579. ...this.memberGrade,
  580. selected: this.checkedList.indexOf(key) > -1,
  581. };
  582. orderDetail.discountInfo.memberGrade = [this.memberGrade];
  583. }
  584. if (key === 'reduces' && JSON.stringify(this.consume) !== '{}') {
  585. this.consume = {
  586. ...this.consume,
  587. discountTime: this.reduceHours,
  588. discountFee: this.reduceHours * this.orderDetail.parkingRule.hourPrice,
  589. selected: this.checkedList.indexOf(key) > -1,
  590. };
  591. orderDetail.discountInfo.consume = [this.consume];
  592. }
  593. });
  594. await this.$store.dispatch('order/saveDiscounts', { orderDetail, callback: () => this.$router.back() });
  595. } else {
  596. this.$router.back();
  597. }
  598. },
  599. },
  600. };