parkingFeeDiscounts.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 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. mounted() {
  106. try {
  107. this.isCheck(() => this.pageInit()); // 验证是否可选
  108. } catch (err) {
  109. console.log(err);
  110. this.$router.back();
  111. }
  112. },
  113. watch: {
  114. remainPrice() {
  115. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  116. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  117. // console.log('hourPrice + this.remainPrice',this.remainPrice)
  118. // 单日上限
  119. // if ( oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee ) {
  120. // return Toast({
  121. // message: `每日最高可抵扣${ maxOneDayDiscountFee }元`,
  122. // icon: 'none',
  123. // });
  124. //
  125. // }
  126. // 单次上限限制
  127. if (oneTimeLimitation) {
  128. if (this.remainPrice <= maxOneTimeDiscountFee) {
  129. if (this.isMember) {
  130. this.isMember = !this.isMember;
  131. }
  132. if (this.isReduces) {
  133. this.isReduces = false;
  134. console.log(109);
  135. }
  136. } else {
  137. this.isMember = this.checkedList.indexOf('member') < 0;
  138. this.isReduces = this.checkedList.indexOf('reduces') < 0;
  139. }
  140. }
  141. },
  142. checkedList() {
  143. // const {hourPrice} = this.orderDetail.parkingRule;
  144. // if ( this.checkedList.indexOf('reduces') > -1 ) {
  145. // this.remainPrice = this.reduceHours * hourPrice + this.remainPrice
  146. // } else {
  147. // this.remainPrice = this.remainPrice - this.reduceHours * hourPrice
  148. // }
  149. },
  150. },
  151. methods: {
  152. pageInit() {
  153. this.remainPrice = this.usingTotalDiscount;
  154. if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
  155. this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
  156. }
  157. this.checkedList = [];
  158. const { memberGrade = [{}], consume = [], memberLevelDiscount } = this.orderDetail.discountInfo;
  159. const { maxConsumeTime,remainConsumeTime } = this.orderDetail.parkingRule;
  160. this.memberGrade = { ...memberGrade[0] };
  161. this.consume = { ...consume[0] };
  162. if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
  163. this.checkedList.push('member');
  164. }
  165. this.isMember = JSON.stringify(this.memberGrade) === '{}';
  166. // 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)
  167. // console.log(143, JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected !== undefined : this.consume.defaultSelected !== undefined);
  168. if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
  169. this.checkedList.push('reduces');
  170. // this.isReduces = false;
  171. // 如果存在拆分逻辑的话
  172. // this.consume.
  173. }
  174. this.isReduces = this.consume.hasOwnProperty('selected') || this.consume.hasOwnProperty('defaultSelected') ? false : true;
  175. this.reduceHours = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / this.orderDetail.parkingRule.hourPrice : this.consume.defaultDiscountTime;
  176. if (remainConsumeTime) {
  177. this.maxReduceDiscount = remainConsumeTime;
  178. }
  179. this.oldCheckedList = [...this.checkedList];
  180. // 如果是杭州、沈阳和合集可以选择
  181. // if (this.parkMallCode === 2 || this.parkMallCode === 4 || this.parkMallCode === 7) {
  182. // this.isReduces = JSON.stringify(this.consume) === '{}';
  183. // }
  184. this.isReduces = JSON.stringify(this.consume) === '{}';
  185. },
  186. setIsMemberDiscountDisabled() {
  187. this.todayReduceDiscountMessage = '当日';
  188. },
  189. checkboxChange() {},
  190. onReduceHoursChange(type) {
  191. if (this.checkedList.indexOf('reduces') < 0) {
  192. return;
  193. }
  194. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  195. // console.log(133,this.reduceHours)
  196. console.log(166, this.maxReduceDiscount);
  197. if (type === 'plus' && this.reduceHours < this.maxReduceDiscount) {
  198. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  199. if (isCrossMessage) {
  200. // this.remainPrice = this.remainPrice - hourPrice;
  201. // this.reduceHours = this.reduceHours - 1;
  202. return
  203. }
  204. this.remainPrice = this.remainPrice + hourPrice;
  205. this.reduceHours = this.reduceHours + 1;
  206. return;
  207. }
  208. if (type === 'minus' && this.reduceHours > 1) {
  209. this.reduceHours = this.reduceHours - 1;
  210. this.remainPrice = this.remainPrice - hourPrice;
  211. return;
  212. }
  213. },
  214. memberClick() {
  215. const { maxConsumeTime, remainConsumeTime } = this.orderDetail.parkingRule;
  216. if (this.checkedList.indexOf('member') > -1) {
  217. this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
  218. } else if (!this.isMember) {
  219. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  220. this.maxReduceDiscount = remainConsumeTime;
  221. }
  222. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  223. if (isCrossMessage) {
  224. this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
  225. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  226. this.isMember = false;
  227. }
  228. },
  229. reducesClick() {
  230. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime,remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  231. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  232. /*if ( oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee ) {
  233. this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
  234. Toast({
  235. message: `超出抵扣上限,每次最高可抵扣${ maxOneTimeDiscountTime }小时`,
  236. icon: 'none',
  237. });
  238. return false
  239. }*/
  240. const reduceHours = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice;
  241. if (this.checkedList.indexOf('reduces') > -1) {
  242. this.remainPrice = hourPrice + this.remainPrice;
  243. // 计算最大上限
  244. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  245. } else {
  246. this.remainPrice = this.remainPrice - hourPrice;
  247. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  248. // this.reduceHours = maxConsumeTime;
  249. }
  250. const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
  251. if (isCrossMessage) {
  252. // console.log(215, maxReduceDiscount)
  253. // console.log(207, this.reduceHours)
  254. // this.maxReduceDiscount = maxReduceDiscount ? 0 : maxReduceDiscount * -1
  255. // console.log(217, this.maxReduceDiscount)
  256. this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
  257. //
  258. // this.reduceHours = this.maxReduceDiscount
  259. }
  260. },
  261. // 超限提示
  262. crossMessage() {
  263. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  264. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  265. // 单日上限
  266. if (oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee) {
  267. Toast({
  268. message: `每日最高可抵扣${maxOneDayDiscountFee}元`,
  269. icon: 'none',
  270. });
  271. return [true, (maxOneDayDiscountFee - (this.reduceHours - 1) * hourPrice) / hourPrice];
  272. }
  273. // 单次上限限制
  274. if (oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee) {
  275. Toast({
  276. message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
  277. icon: 'none',
  278. });
  279. // return [true,( maxOneTimeDiscountFee - (this.reduceHours - 1) * hourPrice ) / hourPrice]
  280. return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
  281. }
  282. return [false, 0];
  283. },
  284. // 验证当前的选项是否可选择
  285. isCheck(callback) {
  286. if (!this?.orderDetail?.parkingRule) {
  287. return;
  288. }
  289. // const {parkInfo,parkingRule,discountInfo} = this.orderDetail
  290. const { maxOneTimeDiscountTime, maxOneDayDiscountFee, oneTimeLimitation, oneDayLimitation, hourPrice, remainConsumeTime } = this.orderDetail.parkingRule;
  291. // 浦东
  292. if (this.parkMallCode === 1) {
  293. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  294. const remainConsumeTimeFee = remainConsumeTime * hourPrice;
  295. // TODO: 统计纸质优惠券的总金额, usingTotalDiscount,才是用户当前订单使用的优惠总数
  296. this.isMember = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.memberLevelDiscount);
  297. this.isReduces = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.enableConsume);
  298. }
  299. if (callback) callback();
  300. },
  301. reducesChange(value) {
  302. // console.log(149,value)
  303. },
  304. async confirm() {
  305. let orderDetail = cloneDeep(this.orderDetail);
  306. // 如果初次进来操作的跟原来的不一样则重新计算优惠
  307. if (this.checkedList.length !== this.checkedTotal || true) {
  308. ['member', 'reduces'].forEach((key) => {
  309. if (key === 'member') {
  310. this.memberGrade = {
  311. ...this.memberGrade,
  312. selected: this.checkedList.indexOf(key) > -1,
  313. };
  314. orderDetail.discountInfo.memberGrade = [this.memberGrade];
  315. }
  316. if (key === 'reduces') {
  317. this.consume = {
  318. ...this.consume,
  319. discountTime: this.reduceHours,
  320. discountFee: this.reduceHours * this.orderDetail.parkingRule.hourPrice,
  321. selected: this.checkedList.indexOf(key) > -1,
  322. };
  323. orderDetail.discountInfo.consume = [this.consume];
  324. }
  325. });
  326. await this.$store.dispatch('order/saveDiscounts', { orderDetail, callback: () => this.$router.back() });
  327. } else {
  328. this.$router.back();
  329. }
  330. },
  331. },
  332. };