parkingFeeDiscounts.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. };
  36. },
  37. computed: {
  38. ...mapState({
  39. orderDetail: (state) => state.order.orderDetail,
  40. custTypeId: (state) => state.custTypeId,
  41. groupId: (state) => state.groupId,
  42. enableConsume: (state) => state.order.enableConsume,
  43. actualPayFee: (state) => state.order.actualPayFee,
  44. usingTotalDiscount: (state) => state.order.usingTotalDiscount,
  45. memberLevelDiscount: (state) => state.order.memberLevelDiscount,
  46. checkedTotal: (state) => state.order.checkedTotal,
  47. parkMallCode: (state) => state.order.parkMallCode,
  48. paperDiscountTime: (state) => state.order.paperDiscountTime,
  49. paperDiscountFee: (state) => state.order.paperDiscountTime,
  50. }),
  51. enableConsumeNonSplit() {
  52. return this.orderDetail.parkingRule.enableConsumeNonSplit
  53. },
  54. stepperMin() {
  55. // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
  56. if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
  57. return this.reduceHours || 0
  58. }
  59. // 如果不存消费减免,默认展示0
  60. if(JSON.stringify(this.consume) === '{}') {
  61. return 0
  62. }
  63. // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
  64. return 1
  65. },
  66. stepperMax() {
  67. // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
  68. if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
  69. return this.reduceHours || 0
  70. }
  71. // 如果不存消费减免,默认展示0
  72. if(JSON.stringify(this.consume) === '{}') {
  73. return 0
  74. }
  75. // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
  76. return this.maxReduceDiscount
  77. },
  78. // maxReduceDiscount() {
  79. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  80. // let newMaxConsumeTime = maxConsumeTime
  81. // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice
  82. // console.log(52, this.remainPrice)
  83. // if ( this.remainPrice + (newMaxConsumeTime * hourPrice) > maxOneTimeDiscountFee ) {
  84. // newMaxConsumeTime = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice
  85. // }
  86. // return maxConsumeTime
  87. // },
  88. // remainPrice() {
  89. // let remainPrice = this.usingTotalDiscount
  90. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  91. // let newMaxConsumeTime = maxConsumeTime
  92. // if ( this.checkedList.indexOf('member') > -1) {
  93. // remainPrice = remainPrice + this.memberGrade.discountFee
  94. // }
  95. // if ( this.checkedList.indexOf('reduces') > -1) {
  96. //
  97. // }
  98. //
  99. //
  100. //
  101. //
  102. // return remainPrice
  103. // }
  104. // 消费减免(拆分部分)提示文本
  105. reduceSplitMessage() {
  106. console.log(106, this.reduceHours);
  107. if (!this.enableConsumeNonSplit) {
  108. return `选择${this.reduceHours}小时,`;
  109. }
  110. return '';
  111. },
  112. // 消费减免金额
  113. reducesDiscountFee() {
  114. return this.reduceHours * this.orderDetail.parkingRule.hourPrice;
  115. },
  116. // 消费减免说明文案
  117. todayReduceDiscountMessage() {
  118. // 静安浦东没有内容
  119. if (this.parkMallCode === 0 || this.parkMallCode === 1) {
  120. return ''
  121. }
  122. // 消费减免余额为 0 时
  123. if(!this.orderDetail.parkingRule.remainConsumeTime) {
  124. return `您今日消费减免已达${this.orderDetail.parkingRule.maxConsumeTime}小时上限`
  125. }
  126. // 消费减免不存在时
  127. if(JSON.stringify(this.consume) === '{}') {
  128. return '消费金额未达到最低优惠要求'
  129. }
  130. // 静安存在消费减免时
  131. if (this.parkMallCode === 0) {
  132. return `今日可减免${this.consume.defaultDiscountTime}小时`;
  133. }
  134. // 沈阳提示信息
  135. if (this.parkMallCode === 4 || this.parkMallCode === 6) {
  136. return `未达上限时今日可减免${this.consume.defaultDiscountTime}小时`;
  137. }
  138. if (this.consume.defaultDiscountTime > this.orderDetail.parkingRule.remainConsumeTime) {
  139. return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。超出优惠上限,可减免${this.maxReduceDiscount}小时,${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
  140. }
  141. return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
  142. }
  143. },
  144. mounted() {
  145. try {
  146. this.isCheck(() => this.pageInit()); // 验证是否可选
  147. } catch (err) {
  148. console.log(err);
  149. this.$router.back();
  150. }
  151. },
  152. watch: {
  153. remainPrice() {
  154. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  155. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  156. // console.log('hourPrice + this.remainPrice',this.remainPrice)
  157. // 单日上限
  158. // if ( oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee ) {
  159. // return Toast({
  160. // message: `每日最高可抵扣${ maxOneDayDiscountFee }元`,
  161. // icon: 'none',
  162. // });
  163. //
  164. // }
  165. // 单次上限限制
  166. if (oneTimeLimitation) {
  167. if (this.remainPrice <= maxOneTimeDiscountFee) {
  168. if (this.isMember) {
  169. this.isMember = !this.isMember;
  170. }
  171. if (this.isReduces) {
  172. this.isReduces = false;
  173. console.log(109);
  174. }
  175. } else {
  176. this.isMember = this.checkedList.indexOf('member') < 0;
  177. this.isReduces = this.checkedList.indexOf('reduces') < 0;
  178. }
  179. }
  180. },
  181. checkedList() {
  182. // const {hourPrice} = this.orderDetail.parkingRule;
  183. // if ( this.checkedList.indexOf('reduces') > -1 ) {
  184. // this.remainPrice = this.reduceHours * hourPrice + this.remainPrice
  185. // } else {
  186. // this.remainPrice = this.remainPrice - this.reduceHours * hourPrice
  187. // }
  188. },
  189. },
  190. methods: {
  191. pageInit() {
  192. this.remainPrice = this.usingTotalDiscount;
  193. if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
  194. this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
  195. }
  196. this.checkedList = [];
  197. const { memberGrade = [{}], consume = [], memberLevelDiscount } = this.orderDetail.discountInfo;
  198. const { maxConsumeTime,remainConsumeTime } = this.orderDetail.parkingRule;
  199. this.memberGrade = { ...memberGrade[0] };
  200. this.consume = { ...consume[0] };
  201. if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
  202. this.checkedList.push('member');
  203. }
  204. this.isMember = JSON.stringify(this.memberGrade) === '{}';
  205. // 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)
  206. // console.log(143, JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected !== undefined : this.consume.defaultSelected !== undefined);
  207. if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
  208. this.checkedList.push('reduces');
  209. // this.isReduces = false;
  210. // 如果存在拆分逻辑的话
  211. // this.consume.
  212. }
  213. this.isReduces = this.consume.hasOwnProperty('selected') || this.consume.hasOwnProperty('defaultSelected') ? false : true;
  214. this.reduceHours = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / this.orderDetail.parkingRule.hourPrice : this.consume.defaultDiscountTime;
  215. if (this.consume?.defaultDiscountTime) {
  216. this.maxReduceDiscount = this.consume.defaultDiscountTime;
  217. }
  218. this.oldCheckedList = [...this.checkedList];
  219. // 如果是杭州、沈阳可以选择
  220. // if (this.parkMallCode === 2 || this.parkMallCode === 4 || this.parkMallCode === 7) {
  221. // this.isReduces = JSON.stringify(this.consume) === '{}';
  222. // }
  223. // https://kerryprops.atlassian.net/browse/SCRM-4016?focusedCommentId=117842: 只要存在消费减免情况,都允许用户进行操作
  224. this.isReduces = JSON.stringify(this.consume) === '{}';
  225. },
  226. setIsMemberDiscountDisabled() {
  227. this.todayReduceDiscountMessage = '当日';
  228. },
  229. checkboxChange() {},
  230. onReduceHoursChange(type) {
  231. if (this.checkedList.indexOf('reduces') < 0) {
  232. return;
  233. }
  234. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  235. // console.log(133,this.reduceHours)
  236. console.log(166, this.maxReduceDiscount);
  237. if (type === 'plus' && this.reduceHours < this.maxReduceDiscount) {
  238. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  239. if (isCrossMessage) {
  240. // this.remainPrice = this.remainPrice - hourPrice;
  241. // this.reduceHours = this.reduceHours - 1;
  242. return
  243. }
  244. this.remainPrice = this.remainPrice + hourPrice;
  245. this.reduceHours = this.reduceHours + 1;
  246. return;
  247. }
  248. if (type === 'minus' && this.reduceHours > 1) {
  249. this.reduceHours = this.reduceHours - 1;
  250. this.remainPrice = this.remainPrice - hourPrice;
  251. return;
  252. }
  253. },
  254. memberClick() {
  255. const { maxConsumeTime, remainConsumeTime } = this.orderDetail.parkingRule;
  256. if (this.checkedList.indexOf('member') > -1) {
  257. this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
  258. } else if (!this.isMember) {
  259. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  260. this.maxReduceDiscount = remainConsumeTime;
  261. }
  262. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  263. if (isCrossMessage) {
  264. this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
  265. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  266. this.isMember = false;
  267. }
  268. },
  269. reducesClick() {
  270. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime,remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  271. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  272. /*if ( oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee ) {
  273. this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
  274. Toast({
  275. message: `超出抵扣上限,每次最高可抵扣${ maxOneTimeDiscountTime }小时`,
  276. icon: 'none',
  277. });
  278. return false
  279. }*/
  280. const reduceHours = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice;
  281. if (this.checkedList.indexOf('reduces') > -1) {
  282. this.remainPrice = hourPrice + this.remainPrice;
  283. // 计算最大上限
  284. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  285. } else {
  286. this.remainPrice = this.remainPrice - hourPrice;
  287. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  288. // this.reduceHours = maxConsumeTime;
  289. }
  290. const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
  291. if (isCrossMessage) {
  292. // console.log(215, maxReduceDiscount)
  293. // console.log(207, this.reduceHours)
  294. // this.maxReduceDiscount = maxReduceDiscount ? 0 : maxReduceDiscount * -1
  295. // console.log(217, this.maxReduceDiscount)
  296. this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
  297. //
  298. // this.reduceHours = this.maxReduceDiscount
  299. }
  300. },
  301. // 超限提示
  302. crossMessage() {
  303. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  304. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  305. // 单日上限
  306. if (oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee) {
  307. Toast({
  308. message: `每日最高可抵扣${maxOneDayDiscountFee}元`,
  309. icon: 'none',
  310. });
  311. return [true, (maxOneDayDiscountFee - (this.reduceHours - 1) * hourPrice) / hourPrice];
  312. }
  313. // 单次上限限制
  314. if (oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee) {
  315. Toast({
  316. message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
  317. icon: 'none',
  318. });
  319. // return [true,( maxOneTimeDiscountFee - (this.reduceHours - 1) * hourPrice ) / hourPrice]
  320. return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
  321. }
  322. return [false, 0];
  323. },
  324. // 验证当前的选项是否可选择
  325. isCheck(callback) {
  326. if (!this?.orderDetail?.parkingRule) {
  327. return;
  328. }
  329. // const {parkInfo,parkingRule,discountInfo} = this.orderDetail
  330. const { maxOneTimeDiscountTime, maxOneDayDiscountFee, oneTimeLimitation, oneDayLimitation, hourPrice, remainConsumeTime } = this.orderDetail.parkingRule;
  331. // 浦东
  332. if (this.parkMallCode === 1) {
  333. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  334. const remainConsumeTimeFee = remainConsumeTime * hourPrice;
  335. // TODO: 统计纸质优惠券的总金额, usingTotalDiscount,才是用户当前订单使用的优惠总数
  336. this.isMember = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.memberLevelDiscount);
  337. this.isReduces = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.enableConsume);
  338. }
  339. if (callback) callback();
  340. },
  341. reducesChange(value) {
  342. // console.log(149,value)
  343. },
  344. async confirm() {
  345. let orderDetail = cloneDeep(this.orderDetail);
  346. // 如果初次进来操作的跟原来的不一样则重新计算优惠
  347. if (this.checkedList.length !== this.checkedTotal || true) {
  348. ['member', 'reduces'].forEach((key) => {
  349. if (key === 'member') {
  350. this.memberGrade = {
  351. ...this.memberGrade,
  352. selected: this.checkedList.indexOf(key) > -1,
  353. };
  354. orderDetail.discountInfo.memberGrade = [this.memberGrade];
  355. }
  356. if (key === 'reduces') {
  357. this.consume = {
  358. ...this.consume,
  359. discountTime: this.reduceHours,
  360. discountFee: this.reduceHours * this.orderDetail.parkingRule.hourPrice,
  361. selected: this.checkedList.indexOf(key) > -1,
  362. };
  363. orderDetail.discountInfo.consume = [this.consume];
  364. }
  365. });
  366. await this.$store.dispatch('order/saveDiscounts', { orderDetail, callback: () => this.$router.back() });
  367. } else {
  368. this.$router.back();
  369. }
  370. },
  371. },
  372. };