123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- import { Toast } from "vant";
- import { mapState } from 'vuex';
- import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
- import { cloneDeep } from 'lodash'
- import baseMixins from '../mixins/base';
- import { waitByTime } from "@/utils";
- // import uni from '@/utils/uniHooks';
- // const app = getApp()
- export default {
- mixins: [baseMixins],
- components: { uniNumberBox },
- created() {
- // 超限提示
- // this.crossMessage();
- },
- // beforeRouteLeave(to, from, next) {
- // console.log(251251251251251251, to, from,);
- // // 设置下一个路由的 meta
- // to.meta.keepAlive = true; // 让 A 不缓存,即刷新
- // next();
- // },
- data() {
- return {
- checkedList: [], // 已选优惠列表
- oldCheckedList: [], // 已选优惠列表备份
- isMember: true, // member
- isReduces: true, // reduces
- memberLevelReduce: [],
- memberGrade: {},
- consume: {},
- // todayReduceDiscountMessage: '',
- isMemberDiscountDisabled: false,
- maxDiscountTime: 0,
- enableConsumeSplit: false,
- maxReduceDiscount: 0,
- reduceHours: 0,
- remainPrice: 0,
- isInit: 1,
- };
- },
- computed: {
- ...mapState({
- orderDetail: (state) => state.order.orderDetail,
- custTypeId: (state) => state.custTypeId,
- groupId: (state) => state.groupId,
- enableConsume: (state) => state.order.enableConsume,
- actualPayFee: (state) => state.order.actualPayFee,
- usingTotalDiscount: (state) => state.order.usingTotalDiscount,
- memberLevelDiscount: (state) => state.order.memberLevelDiscount,
- checkedTotal: (state) => state.order.checkedTotal,
- parkMallCode: (state) => state.order.parkMallCode,
- paperDiscountTime: (state) => state.order.paperDiscountTime,
- paperDiscountFee: (state) => state.order.paperDiscountTime,
- availableDiscountFee: (state) => state.order.availableDiscountFee,
- }),
- enableConsumeNonSplit() {
- return this.orderDetail.parkingRule.enableConsumeNonSplit
- },
- stepperMin() {
- // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
- if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
- return this.reduceHours || 0
- }
- // 如果不存消费减免,默认展示0
- if (JSON.stringify(this.consume) === '{}') {
- return 0
- }
- // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
- return 1
- },
- stepperMax() {
- if (this.parkMallCode === 4 || this.parkMallCode === 6) {
- // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
- return this.maxReduceDiscount
- }
- // 如果是合集车场,不存在拆分,默认返回用户可使用的消费抵扣时间
- if (this.parkMallCode === 7 || this.enableConsumeNonSplit) {
- return this.reduceHours || 0
- }
- // 如果不存消费减免,默认展示0
- if (JSON.stringify(this.consume) === '{}') {
- return 0
- }
- // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
- return this.maxReduceDiscount
- },
- // maxReduceDiscount() {
- // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
- // let newMaxConsumeTime = maxConsumeTime
- // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice
- // console.log(52, this.remainPrice)
- // if ( this.remainPrice + (newMaxConsumeTime * hourPrice) > maxOneTimeDiscountFee ) {
- // newMaxConsumeTime = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice
- // }
- // return maxConsumeTime
- // },
- // remainPrice() {
- // let remainPrice = this.usingTotalDiscount
- // const {maxOneDayCoupons,maxConsumeTime,maxonedaydiscountFee,maxOneTimeDiscountTime,remainConsumeTime,hourPrice,availableDiscountFee,oneTimeLimitation,oneDayLimitation,maxOneDayDiscountFee} = this.orderDetail.parkingRule;
- // let newMaxConsumeTime = maxConsumeTime
- // if ( this.checkedList.indexOf('member') > -1) {
- // remainPrice = remainPrice + this.memberGrade.discountFee
- // }
- // if ( this.checkedList.indexOf('reduces') > -1) {
- //
- // }
- //
- //
- //
- //
- // return remainPrice
- // }
- // 消费减免(拆分部分)提示文本
- reduceSplitMessage() {
- // console.log(106, this.reduceHours);
- if (!this.enableConsumeNonSplit) {
- return `选择${this.reduceHours}小时,`;
- }
- return '';
- },
- // 消费减免金额
- reducesDiscountFee() {
- return this.reduceHours * this.orderDetail.parkingRule.hourPrice;
- },
- // 消费减免说明文案
- todayReduceDiscountMessage() {
- // 静安浦东没有内容
- if (this.parkMallCode === 0 || this.parkMallCode === 1) {
- return ''
- }
- // 消费减免余额为 0 时
- if (!this.orderDetail.parkingRule.remainConsumeTime || !this.consume.hasOwnProperty('redeemSalesAmount')) {
- return `您暂无可用的消费减免`
- // return `您今日消费减免已达${this.orderDetail.parkingRule.maxConsumeTime}小时上限`
- }
- // 消费减免不存在时
- if (JSON.stringify(this.consume) === '{}') {
- return '消费金额未达到最低优惠要求'
- }
- // 静安存在消费减免时
- if (this.parkMallCode === 0) {
- return `今日可减免${this.consume.defaultDiscountTime}小时`;
- }
- // 沈阳提示信息
- if (this.parkMallCode === 4 || this.parkMallCode === 6) {
- return `未达上限时今日可减免${this.stepperMax}小时`;
- }
- if (this.consume.defaultDiscountTime > this.orderDetail.parkingRule.remainConsumeTime) {
- return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。超出优惠上限,可减免${this.maxReduceDiscount}小时,${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
- }
- return `消费已满${this.consume.redeemSalesAmount}元,减免${this.consume.defaultDiscountTime}小时。${this.reduceSplitMessage}可优惠${this.reducesDiscountFee}元`
- }
- },
- mounted() {
- try {
- this.isCheck(() => this.pageInit()); // 验证是否可选
- } catch (err) {
- // console.log(err);
- this.$router.back();
- }
- },
- watch: {
- remainPrice() {
- const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- // console.log('hourPrice + this.remainPrice',this.remainPrice)
- // 单日上限
- // if ( oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee ) {
- // return Toast({
- // message: `每日最高可抵扣${ maxOneDayDiscountFee }元`,
- // icon: 'none',
- // });
- //
- // }
- // 单次上限限制
- if (oneTimeLimitation) {
- if (this.remainPrice <= maxOneTimeDiscountFee) {
- if (this.isMember) {
- this.isMember = !this.isMember;
- }
- if (this.isReduces) {
- this.isReduces = false;
- // console.log(109);
- }
- } else {
- this.isMember = this.checkedList.indexOf('member') < 0;
- this.isReduces = this.checkedList.indexOf('reduces') < 0;
- }
- }
- },
- checkedList(newVal, oldVal) {
- // console.log(190, { newVal, oldVal });
- if ((this.parkMallCode === 4 || this.parkMallCode === 6) && this.isInit > 1) {
- const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
- // 会员等级选中了
- if (newVal.indexOf('member') > -1 && oldVal.indexOf('member') < 0) {
- // console.log(193, '会员等级选中了');
- // this.remainPrice = this.remainPrice + this.memberGrade.discountFee;
- // this.maxReduceDiscountInit();
- }
- if (oldVal.indexOf('member') > -1 && newVal.indexOf('member') < 0) {
- // 会员等级未选中了
- // console.log(193, '会员等级未选中了');
- // this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
- // this.maxReduceDiscountInit();
- }
- // 消费减免选中了
- if (newVal.indexOf('reduces') > -1 && oldVal.indexOf('reduces') < 0) {
- // console.log(193, '消费减免选中了');
- this.consume.discountFee = this.reduceHours * hourPrice
- this.remainPrice = this.remainPrice + this.consume.discountFee;
- }
- if (oldVal.indexOf('reduces') > -1 && newVal.indexOf('reduces') < 0) {
- // 消费减免未选中了
- // console.log(193, '消费减免未选中了');
- this.consume.discountFee = this.reduceHours * hourPrice
- this.remainPrice = this.remainPrice - this.consume.discountFee;
- }
- }
- // const {hourPrice} = this.orderDetail.parkingRule;
- // if ( this.checkedList.indexOf('reduces') > -1 ) {
- // this.remainPrice = this.reduceHours * hourPrice + this.remainPrice
- // } else {
- // this.remainPrice = this.remainPrice - this.reduceHours * hourPrice
- // }
- },
- },
- methods: {
- pageInit() {
- if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
- this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
- }
- this.checkedList = [];
- const { memberGrade = [{}], consume = [], memberLevelDiscount, points = [{}] } = this.orderDetail.discountInfo;
- const { maxConsumeTime, remainConsumeTime, hourPrice } = this.orderDetail.parkingRule;
- // 如果积分存在的话,则移除积分的优惠
- if (points.length && JSON.stringify(points[0]) !== "{}") {
- this.remainPrice = this.parkMallCode !== 1 ? this.usingTotalDiscount - points[0].discountFee : this.usingTotalDiscount;
- }
- this.memberGrade = { ...memberGrade[0] };
- this.consume = { ...consume[0] };
- if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
- this.checkedList.push('member');
- }
- this.isMember = JSON.stringify(this.memberGrade) === '{}';
- // 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)
- // console.log(143, JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected !== undefined : this.consume.defaultSelected !== undefined);
- if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
- this.checkedList.push('reduces');
- // this.isReduces = false;
- // 如果存在拆分逻辑的话
- // this.consume.
- }
- this.isReduces = this.consume.hasOwnProperty('selected') || this.consume.hasOwnProperty('defaultSelected') ? false : true;
- this.reduceHours = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / this.orderDetail.parkingRule.hourPrice : Math.min(this.consume.defaultDiscountTime, this.consume.maxDiscountTime);
- if (JSON.stringify(this.consume) !== '{}') {
- const isSelected = this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected;
- this.maxReduceDiscount = this.consume.hasOwnProperty('discountFee') ? this.consume.discountFee / hourPrice : Math.min(this.consume.defaultDiscountTime, this.consume.maxDiscountTime);
- // const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee) / hourPrice
- // if (remainingLimitToIncrease) {
- // this.maxReduceDiscountInit();
- // }
- this.maxReduceDiscountInit();
-
- }
- this.oldCheckedList = [...this.checkedList];
- // 如果是杭州、沈阳可以选择
- // if (this.parkMallCode === 2 || this.parkMallCode === 4 || this.parkMallCode === 7) {
- // this.isReduces = JSON.stringify(this.consume) === '{}';
- // }
- // https://kerryprops.atlassian.net/browse/SCRM-4016?focusedCommentId=117842: 只要存在消费减免情况,都允许用户进行操作
- this.isReduces = JSON.stringify(this.consume) === '{}';
- this.discountInit()
- setTimeout(() => {
- this.isInit = this.isInit + 1
- }, 300)
- },
- discountInit() {
- if(this.parkMallCode === 4 || this.parkMallCode === 6 ) {
- const { maxConsumeTime, remainConsumeTime, hourPrice } = this.orderDetail.parkingRule;
- const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee) / hourPrice
- if(!remainingLimitToIncrease) {
- this.isMember = this.memberGrade.hasOwnProperty('selected')? !this.memberGrade.selected : !this.memberGrade.defaultSelected
- this.isReduces = this.consume.hasOwnProperty('selected')? !this.consume.selected : !this.consume.defaultSelected
- }
- }
- },
- maxReduceDiscountInit() {
- const {maxDiscountTime, couponCodes, defaultDiscountTime} = this.consume
- if(JSON.stringify(this.consume) === '{}' || !this.consume.hasOwnProperty('redeemSalesAmount')) {
- return
- }
- const { maxConsumeTime, remainConsumeTime, hourPrice, maxOneTimeDiscountTime } = this.orderDetail.parkingRule;
-
- const remainingLimitToIncrease = Math.abs(this.remainPrice - this.availableDiscountFee || 0) / hourPrice;
- // 如果是浦东的话, 重新计算优惠
- if (this.parkMallCode === 1 || this.parkMallCode === 0) {
- /*
- * 消费减免真实可用优惠的计算逻辑
- * 消费减免可能选择的情况: X
- * 其余已使用的优惠:W
- * 当前可使用优惠的上限:B
- * 当前消费减免最高可用优惠:D = B - ( W - X )
- * 当前消费减免用户可用优惠上限:Z
- * 消费减免真实可用优惠: D > Z ? Z : D
- * */
- const isSelected = this.checkedList.indexOf('reduces') > -1;
- // const reduceHours = isSelected ? this.reduceHours : 0
- const remainHour = this.remainPrice / hourPrice
- // 当前订单的总可用余额: remainConsumeTime
- const couponCodesLength = couponCodes?.split('#')?.length || 0; // 上限
- // const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- // 实际上限
- // remainConsumeTime - this.reduceHours 剩余优惠
- // couponCodesLength - this.reduceHours 剩余上限
- // 实际上限 = 剩余优惠 <= 剩余上限
- // this.maxReduceDiscount = remainConsumeTime - this.reduceHours <= couponCodesLength - this.reduceHours
- // 转化公式之后
- // this.maxReduceDiscount = remainConsumeTime > couponCodesLength ? couponCodesLength : remainConsumeTime
- // console.log(319, this.remainPrice >= maxOneTimeDiscountFee)
- // this.maxReduceDiscount = couponCodesLength > defaultDiscountTime ? defaultDiscountTime> remainHour > defaultDiscountTime ? defaultDiscountTime : remainHour : remainHour > couponCodesLength?couponCodesLength:remainHour;
- this.maxReduceDiscount = defaultDiscountTime;
- // 323323323 3 2 2 2
- // 323323323 3 1 2 1
- // console.log('323323323', couponCodesLength, remainHour, defaultDiscountTime, this.reduceHours )
-
- // this.reduceHours = this.maxReduceDiscount
- !isSelected && remainConsumeTime - remainHour > 0 && defaultDiscountTime && (this.reduceHours = 1)
- // remainConsumeTime - remainHour > 0 && defaultDiscountTime && (this.reduceHours = 1)
- return
- // 如果超过限制就置灰
- // const maxOneTimeDiscountTimeFee = (couponCodes.split('#').length) * hourPrice
- // const isSelected = this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected;
- // const isCheckedListSelected = this.checkedList.indexOf('consume') > -1;
- // if(maxOneTimeDiscountTimeFee > this.remainPrice) {
- // // 优惠计算公式: 剩余可用优惠 + 已经选择的优惠 = 总的消费减免的优惠(小时)
- // const maxReduceDiscount = (maxOneTimeDiscountTimeFee - this.remainPrice) / hourPrice + (isSelected ? this.reduceHours : 0)
- // this.maxReduceDiscount = maxReduceDiscount > maxOneTimeDiscountTime ? maxOneTimeDiscountTime: maxReduceDiscount
- // !isSelected && (this.reduceHours = this.maxReduceDiscount)
- // return
- // }
- // if(maxOneTimeDiscountTimeFee == this.remainPrice && !isSelected && isCheckedListSelected) {
- // this.maxReduceDiscount = 0
- // this.reduceHours = this.maxReduceDiscount
- // return
- // } else {
- // this.maxReduceDiscount = this.reduceHours
- // }
- return
- }
- if (!remainingLimitToIncrease) {
- // if(!this.consume.selected) {
- // this.isReduces = true
- // }
- return
- }
- this.isReduces = false
- if (this.remainPrice >= this.availableDiscountFee) {
- // console.log('过大', this.maxReduceDiscount, remainingLimitToIncrease);
- this.maxReduceDiscount = this.maxReduceDiscount - remainingLimitToIncrease > maxDiscountTime ? maxDiscountTime : this.maxReduceDiscount - remainingLimitToIncrease
- this.consume.discountFee = this.consume.discountFee - (remainingLimitToIncrease * hourPrice)
- this.remainPrice = this.remainPrice - (remainingLimitToIncrease * hourPrice);
- this.reduceHours = this.maxReduceDiscount
- }
- if(this.checkedList.indexOf('reduces') < 0) {
- // 如果没被选中
- this.maxReduceDiscount = remainingLimitToIncrease > maxDiscountTime ? maxDiscountTime : remainingLimitToIncrease
- this.reduceHours = this.maxReduceDiscount
- this.consume.discountFee = remainingLimitToIncrease * hourPrice
- return
- }
- // 如果被选中
- // console.log('过小?', this.consume.discountFee, remainingLimitToIncrease);
- const maxReduceDiscount = this.consume.discountFee / hourPrice + remainingLimitToIncrease
- // console.log('过小', maxReduceDiscount);
- this.maxReduceDiscount = maxReduceDiscount <= remainConsumeTime ? maxReduceDiscount : remainConsumeTime
- this.maxReduceDiscount = this.maxReduceDiscount > maxDiscountTime ? maxDiscountTime: this.maxReduceDiscount
- },
- setIsMemberDiscountDisabled() {
- this.todayReduceDiscountMessage = '当日';
- },
- checkboxChange() { },
- onReduceHoursChange(type) {
- if (this.checkedList.indexOf('reduces') < 0) {
- return;
- }
- const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
- // console.log(133,this.reduceHours)
- // console.log(166, this.maxReduceDiscount);
- if (type === 'plus') {
- const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage('onReduceHoursChange');
- if (isCrossMessage) {
- // this.remainPrice = this.remainPrice - hourPrice;
- // this.reduceHours = this.reduceHours - 1;
- return
- }
- this.remainPrice = this.remainPrice + hourPrice;
- this.reduceHours = this.reduceHours + 1;
- this.consume.discountFee = this.reduceHours * hourPrice
- return;
- }
- if (type === 'minus' && this.reduceHours > 1) {
- this.reduceHours = this.reduceHours - 1;
- this.remainPrice = this.remainPrice - hourPrice;
- this.consume.discountFee = this.reduceHours * hourPrice
- return;
- }
- },
- async memberClick() {
- await waitByTime(200)
- // 没有优惠时不做多余的事情
- if(JSON.stringify(this.memberGrade) === '{}') {
- return;
- }
- if(!this.actualPayFee) {
- Toast('当前无需追加优惠')
- this.checkedList = this.checkedList.filter(elm => elm !== 'member')
- return;
- }
- const { maxConsumeTime, remainConsumeTime, availableDiscountFee, hourPrice } = this.orderDetail.parkingRule;
- if (this.checkedList.indexOf('member') > -1) {
- /* 浦东 */
- if(this.parkMallCode === 1 || this.parkMallCode === 0) {
- const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
- if (!isCrossMessage) {
- this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
- } else {
- this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
- // this.remainPrice = this.remainPrice - this.memberGrade.discountFee
- this.isMember = false;
- }
- this.maxReduceDiscountInit();
- return
- }
- this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
- // 沈阳
- if (this.parkMallCode === 4 || this.parkMallCode === 6) {
- this.maxReduceDiscountInit();
- }
- } else if (!this.isMember) {
- // 浦东单独处理
- if(this.parkMallCode === 1 && this.parkMallCode === 0) {
- this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
- this.maxReduceDiscountInit();
- return
- }
- this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
- // 如果不是沈阳,重新计算优惠
- if (this.parkMallCode !== 4 && this.parkMallCode !== 6 && JSON.stringify(this.consume) !== '{}') {
- this.maxReduceDiscount = remainConsumeTime;
- }
- // 如果不是沈阳,重新计算优惠
- if (this.parkMallCode === 4 || this.parkMallCode === 6) {
- this.maxReduceDiscountInit();
- }
- }
- // 如果不是沈阳
- if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
- const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
- if (isCrossMessage) {
- this.checkedList = this.checkedList.filter((elm) => elm !== 'member');
- this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
- this.isMember = false;
- }
- }
- },
- async reducesClick() {
- await waitByTime(200)
- if(!this.actualPayFee) {
- Toast('当前无需追加优惠')
- this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
- return;
- }
- // 没有优惠时不做多余的事情
- if(JSON.stringify(this.consume) === '{}') {
- return;
- }
- // 浦东
- if((this.parkMallCode === 1 || this.parkMallCode === 0) && (this.isReduces || !this.maxReduceDiscount) ) {
- return;
- }
- const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime, remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee, availableDiscountFee } = this.orderDetail.parkingRule;
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- if (this.checkedList.indexOf('reduces') > -1) {
- if(this.parkMallCode === 1 || this.parkMallCode === 0) {
- const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
- if(isCrossMessage) {
- this.checkedList = this.checkedList.filter((elm) => elm !== 'reduces');
- // this.remainPrice = this.remainPrice - this.memberGrade.discountFee
- // this.isReduces = false;
- return
- }
- // 如果还有剩余优惠的话,给一个默认值
- const {defaultDiscountTime} = this.consume
- const remainHour = this.remainPrice / hourPrice
- if(remainConsumeTime - remainHour > 0 && defaultDiscountTime){
- this.reduceHours = 1
- this.remainPrice = this.remainPrice + hourPrice
- }
- return;
- }
- if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
- // 如果不是沈阳,重新计算计算最大上限
- this.remainPrice = hourPrice + this.remainPrice;
- this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
- }
- } else {
- // this.remainPrice = this.remainPrice - hourPrice;
- // 如果不是沈阳,重新计算计算最大上限
- if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
- this.remainPrice = this.remainPrice - hourPrice;
- this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
- }
- }
- if (this.parkMallCode !== 4 && this.parkMallCode !== 6) {
- const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
- if (isCrossMessage) {
- this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
- }
- }
- },
- // 超限提示
- crossMessage(type) {
- const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee, remainConsumeTime } = this.orderDetail.parkingRule;
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- // console.log(373, this.remainPrice, this.availableDiscountFee);
- // 单日上限
- if (oneDayLimitation && this.remainPrice >= this.availableDiscountFee) {
- Toast({
- message: `每日最高可抵扣${maxOneDayDiscountFee}元`,
- icon: 'none',
- });
- return [true, (maxOneDayDiscountFee - (this.reduceHours - 1) * hourPrice) / hourPrice];
- }
- // 单次上限限制
- if (oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee) {
- Toast({
- message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
- icon: 'none',
- });
- // return [true,( maxOneTimeDiscountFee - (this.reduceHours - 1) * hourPrice ) / hourPrice]
- return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
- }
- // 单次上限限制 浦东
- const remainHour = this.remainPrice / hourPrice
- if (oneTimeLimitation && maxOneTimeDiscountTime - remainHour < 1) {
- Toast({
- message: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
- icon: 'none',
- });
- return [true, (this.remainPrice - maxOneTimeDiscountFee) / hourPrice];
- }
- return [false, 0];
- },
- // 验证当前的选项是否可选择
- isCheck(callback) {
- if (!this?.orderDetail?.parkingRule) {
- return;
- }
- // const {parkInfo,parkingRule,discountInfo} = this.orderDetail
- const { maxOneTimeDiscountTime, maxOneDayDiscountFee, oneTimeLimitation, oneDayLimitation, hourPrice, remainConsumeTime } = this.orderDetail.parkingRule;
- // 浦东
- if (this.parkMallCode === 1 || this.parkMallCode === 0) {
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- const remainConsumeTimeFee = remainConsumeTime * hourPrice;
- // TODO: 统计纸质优惠券的总金额, usingTotalDiscount,才是用户当前订单使用的优惠总数
- this.isMember = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.memberLevelDiscount);
- this.isReduces = !(this.usingTotalDiscount < (oneTimeLimitation ? maxOneTimeDiscountFee : maxOneDayDiscountFee) && this.enableConsume);
- }
- if (callback) callback();
- },
- reducesChange(value) {
- // console.log(149,value)
- },
- async confirm() {
- let orderDetail = cloneDeep(this.orderDetail);
- // 如果初次进来操作的跟原来的不一样则重新计算优惠
- if (this.checkedList.length !== this.checkedTotal || true) {
- ['member', 'reduces'].forEach((key) => {
- if (key === 'member' && JSON.stringify(this.memberGrade) !== '{}') {
- this.memberGrade = {
- ...this.memberGrade,
- selected: this.checkedList.indexOf(key) > -1,
- };
- orderDetail.discountInfo.memberGrade = [this.memberGrade];
- }
- if (key === 'reduces' && JSON.stringify(this.consume) !== '{}') {
- this.consume = {
- ...this.consume,
- discountTime: this.reduceHours,
- discountFee: this.reduceHours * this.orderDetail.parkingRule.hourPrice,
- selected: this.checkedList.indexOf(key) > -1,
- };
- orderDetail.discountInfo.consume = [this.consume];
- }
- });
- await this.$store.dispatch('order/saveDiscounts', { orderDetail, callback: () => this.$router.back() });
- } else {
- this.$router.back();
- }
- },
- },
- };
|