parkingFeeDiscounts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. // maxReduceDiscount() {
  52. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  53. // let newMaxConsumeTime = maxConsumeTime
  54. // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice
  55. // console.log(52, this.remainPrice)
  56. // if ( this.remainPrice + (newMaxConsumeTime * hourPrice) > maxOneTimeDiscountFee ) {
  57. // newMaxConsumeTime = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice
  58. // }
  59. // return maxConsumeTime
  60. // },
  61. // remainPrice() {
  62. // let remainPrice = this.usingTotalDiscount
  63. // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
  64. // let newMaxConsumeTime = maxConsumeTime
  65. // if ( this.checkedList.indexOf('member') > -1) {
  66. // remainPrice = remainPrice + this.memberGrade.discountFee
  67. // }
  68. // if ( this.checkedList.indexOf('reduces') > -1) {
  69. //
  70. // }
  71. //
  72. //
  73. //
  74. //
  75. // return remainPrice
  76. // }
  77. },
  78. mounted() {
  79. try {
  80. this.isCheck(() => this.pageInit()); // 验证是否可选
  81. } catch (err) {
  82. console.log(err);
  83. this.$router.back();
  84. }
  85. },
  86. watch: {
  87. remainPrice() {
  88. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  89. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  90. // console.log('hourPrice + this.remainPrice',this.remainPrice)
  91. // 单日上限
  92. // if ( oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee ) {
  93. // return Toast({
  94. // message: `每日最高可抵扣${ maxOneDayDiscountFee }元`,
  95. // icon: 'none',
  96. // });
  97. //
  98. // }
  99. // 单次上限限制
  100. if (oneTimeLimitation) {
  101. if (this.remainPrice <= maxOneTimeDiscountFee) {
  102. if (this.isMember) {
  103. this.isMember = !this.isMember;
  104. }
  105. if (this.isReduces) {
  106. this.isReduces = false;
  107. console.log(109);
  108. }
  109. } else {
  110. this.isMember = this.checkedList.indexOf('member') < 0;
  111. this.isReduces = this.checkedList.indexOf('reduces') < 0;
  112. }
  113. }
  114. },
  115. checkedList() {
  116. // const {hourPrice} = this.orderDetail.parkingRule;
  117. // if ( this.checkedList.indexOf('reduces') > -1 ) {
  118. // this.remainPrice = this.reduceHours * hourPrice + this.remainPrice
  119. // } else {
  120. // this.remainPrice = this.remainPrice - this.reduceHours * hourPrice
  121. // }
  122. },
  123. },
  124. methods: {
  125. pageInit() {
  126. this.remainPrice = this.usingTotalDiscount;
  127. if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
  128. this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
  129. }
  130. this.checkedList = [];
  131. const { memberGrade = [{}], consume = [], memberLevelDiscount } = this.orderDetail.discountInfo;
  132. const { maxConsumeTime,remainConsumeTime } = this.orderDetail.parkingRule;
  133. this.memberGrade = { ...memberGrade[0] };
  134. this.consume = { ...consume[0] };
  135. if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
  136. this.checkedList.push('member');
  137. }
  138. this.isMember = JSON.stringify(this.memberGrade) === '{}';
  139. // 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)
  140. // console.log(143, JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected !== undefined : this.consume.defaultSelected !== undefined);
  141. if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
  142. this.checkedList.push('reduces');
  143. // this.isReduces = false;
  144. // 如果存在拆分逻辑的话
  145. // this.consume.
  146. }
  147. this.isReduces = this.consume.hasOwnProperty('selected') || this.consume.hasOwnProperty('defaultSelected') ? false : true;
  148. this.reduceHours = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / this.orderDetail.parkingRule.hourPrice : this.consume.defaultDiscountTime;
  149. if (remainConsumeTime) {
  150. this.maxReduceDiscount = remainConsumeTime;
  151. }
  152. this.oldCheckedList = [...this.checkedList];
  153. },
  154. setIsMemberDiscountDisabled() {
  155. this.todayReduceDiscountMessage = '当日';
  156. },
  157. checkboxChange() {},
  158. onReduceHoursChange(type) {
  159. if (this.checkedList.indexOf('reduces') < 0) {
  160. return;
  161. }
  162. const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  163. // console.log(133,this.reduceHours)
  164. console.log(166, this.maxReduceDiscount);
  165. if (type === 'plus' && this.reduceHours < this.maxReduceDiscount) {
  166. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  167. if (isCrossMessage) {
  168. // this.remainPrice = this.remainPrice - hourPrice;
  169. // this.reduceHours = this.reduceHours - 1;
  170. return
  171. }
  172. this.remainPrice = this.remainPrice + hourPrice;
  173. this.reduceHours = this.reduceHours + 1;
  174. return;
  175. }
  176. if (type === 'minus' && this.reduceHours > 1) {
  177. this.reduceHours = this.reduceHours - 1;
  178. this.remainPrice = this.remainPrice - hourPrice;
  179. return;
  180. }
  181. },
  182. memberClick() {
  183. const { maxConsumeTime, remainConsumeTime } = this.orderDetail.parkingRule;
  184. if (this.checkedList.indexOf('member') > -1) {
  185. this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
  186. } else if (!this.isMember) {
  187. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  188. this.maxReduceDiscount = remainConsumeTime;
  189. }
  190. const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
  191. if (isCrossMessage) {
  192. this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
  193. this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
  194. this.isMember = false;
  195. }
  196. },
  197. reducesClick() {
  198. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime,remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  199. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  200. /*if ( oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee ) {
  201. this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
  202. Toast({
  203. message: `超出抵扣上限,每次最高可抵扣${ maxOneTimeDiscountTime }小时`,
  204. icon: 'none',
  205. });
  206. return false
  207. }*/
  208. const reduceHours = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice;
  209. if (this.checkedList.indexOf('reduces') > -1) {
  210. this.remainPrice = hourPrice + this.remainPrice;
  211. // 计算最大上限
  212. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  213. } else {
  214. this.remainPrice = this.remainPrice - hourPrice;
  215. this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
  216. // this.reduceHours = maxConsumeTime;
  217. }
  218. const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
  219. if (isCrossMessage) {
  220. // console.log(215, maxReduceDiscount)
  221. // console.log(207, this.reduceHours)
  222. // this.maxReduceDiscount = maxReduceDiscount ? 0 : maxReduceDiscount * -1
  223. // console.log(217, this.maxReduceDiscount)
  224. this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
  225. //
  226. // this.reduceHours = this.maxReduceDiscount
  227. }
  228. },
  229. // 超限提示
  230. crossMessage() {
  231. const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
  232. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  233. // 单日上限
  234. if (oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee) {
  235. Toast({
  236. message: `每日最高可抵扣${maxOneDayDiscountFee}元`,
  237. icon: 'none',
  238. });
  239. return [true, (maxOneDayDiscountFee - (this.reduceHours - 1) * hourPrice) / hourPrice];
  240. }
  241. // 单次上限限制
  242. if (oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee) {
  243. Toast({
  244. message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
  245. icon: 'none',
  246. });
  247. // return [true,( maxOneTimeDiscountFee - (this.reduceHours - 1) * hourPrice ) / hourPrice]
  248. return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
  249. }
  250. return [false, 0];
  251. },
  252. // 验证当前的选项是否可选择
  253. isCheck(callback) {
  254. if (!this?.orderDetail?.parkingRule) {
  255. return;
  256. }
  257. // const {parkInfo,parkingRule,discountInfo} = this.orderDetail
  258. const { maxOneTimeDiscountTime, maxOneDayDiscountFee, oneTimeLimitation, oneDayLimitation, hourPrice, remainConsumeTime } = this.orderDetail.parkingRule;
  259. // 浦东
  260. if (this.parkMallCode === 1) {
  261. const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
  262. const remainConsumeTimeFee = remainConsumeTime * hourPrice;
  263. // TODO: 统计纸质优惠券的总金额, usingTotalDiscount,才是用户当前订单使用的优惠总数
  264. this.isMember = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.memberLevelDiscount);
  265. this.isReduces = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.enableConsume);
  266. }
  267. if (callback) callback();
  268. },
  269. reducesChange(value) {
  270. // console.log(149,value)
  271. },
  272. async confirm() {
  273. let orderDetail = cloneDeep(this.orderDetail);
  274. // 如果初次进来操作的跟原来的不一样则重新计算优惠
  275. if (this.checkedList.length !== this.checkedTotal || true) {
  276. ['member', 'reduces'].forEach((key) => {
  277. if (key === 'member') {
  278. this.memberGrade = {
  279. ...this.memberGrade,
  280. selected: this.checkedList.indexOf(key) > -1,
  281. };
  282. orderDetail.discountInfo.memberGrade = [this.memberGrade];
  283. }
  284. if (key === 'reduces') {
  285. this.consume = {
  286. ...this.consume,
  287. discountTime: this.reduceHours,
  288. discountFee: this.reduceHours * this.orderDetail.parkingRule.hourPrice,
  289. selected: this.checkedList.indexOf(key) > -1,
  290. };
  291. orderDetail.discountInfo.consume = [this.consume];
  292. }
  293. });
  294. await this.$store.dispatch('order/saveDiscounts', { orderDetail, callback: () => this.$router.back() });
  295. } else {
  296. this.$router.back();
  297. }
  298. },
  299. },
  300. };