parkingFeeDiscounts.js 26 KB

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