parkingFeeDiscounts.js 13 KB

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