123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- import { Toast } from "vant";
- import { mapState } from 'vuex';
- import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
- import { cloneDeep } from 'lodash'
- // import uni from '@/utils/uniHooks';
- // const app = getApp()
- export default {
- 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,
- };
- },
- 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,
- }),
- 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 === 7 || this.enableConsumeNonSplit) {
- return this.reduceHours || 0
- }
- // 如果不存消费减免,默认展示0
- if(JSON.stringify(this.consume) === '{}') {
- return 0
- }
- // 如果存在消费减免并且是可拆分的,则设置最低拆分单位是 1
- return 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
- // }
- },
- mounted() {
- try {
- this.isCheck(() => this.pageInit()); // 验证是否可选
- } catch (err) {
- console.log(err);
- this.$router.back();
- }
- },
- watch: {
- remainPrice() {
- const { maxOneDayCoupons, maxonedaydiscountFee, maxOneTimeDiscountTime, remainConsumeTime, hourPrice, availableDiscountFee, 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() {
- // 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() {
- this.remainPrice = this.usingTotalDiscount;
- if (this.orderDetail?.parkingRule?.enableConsumeSplit) {
- this.enableConsumeSplit = this.orderDetail.parkingRule.enableConsumeSplit;
- }
- this.checkedList = [];
- const { memberGrade = [{}], consume = [], memberLevelDiscount } = this.orderDetail.discountInfo;
- const { maxConsumeTime,remainConsumeTime } = this.orderDetail.parkingRule;
- 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 : this.consume.defaultDiscountTime;
- if (remainConsumeTime) {
- this.maxReduceDiscount = remainConsumeTime;
- }
- this.oldCheckedList = [...this.checkedList];
- // 如果是杭州、沈阳和合集可以选择
- // if (this.parkMallCode === 2 || this.parkMallCode === 4 || this.parkMallCode === 7) {
- // this.isReduces = JSON.stringify(this.consume) === '{}';
- // }
- this.isReduces = JSON.stringify(this.consume) === '{}';
- },
- 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' && this.reduceHours < this.maxReduceDiscount) {
-
- const [isCrossMessage = false, maxReduceDiscount = this.maxReduceDiscount] = this.crossMessage();
- if (isCrossMessage) {
- // this.remainPrice = this.remainPrice - hourPrice;
- // this.reduceHours = this.reduceHours - 1;
- return
- }
- this.remainPrice = this.remainPrice + hourPrice;
- this.reduceHours = this.reduceHours + 1;
- return;
- }
- if (type === 'minus' && this.reduceHours > 1) {
- this.reduceHours = this.reduceHours - 1;
- this.remainPrice = this.remainPrice - hourPrice;
- return;
- }
- },
- memberClick() {
- const { maxConsumeTime, remainConsumeTime } = this.orderDetail.parkingRule;
- if (this.checkedList.indexOf('member') > -1) {
- this.remainPrice = this.memberGrade.discountFee + this.remainPrice;
- } else if (!this.isMember) {
- this.remainPrice = this.remainPrice - this.memberGrade.discountFee;
- this.maxReduceDiscount = remainConsumeTime;
- }
- 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;
- }
- },
- reducesClick() {
- const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, maxConsumeTime,remainConsumeTime, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- /*if ( oneTimeLimitation && this.remainPrice >= maxOneTimeDiscountFee ) {
- this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
- Toast({
- message: `超出抵扣上限,每次最高可抵扣${ maxOneTimeDiscountTime }小时`,
- icon: 'none',
- });
- return false
- }*/
- const reduceHours = (maxOneTimeDiscountFee - this.remainPrice) / hourPrice;
- if (this.checkedList.indexOf('reduces') > -1) {
- this.remainPrice = hourPrice + this.remainPrice;
- // 计算最大上限
- this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
- } else {
- this.remainPrice = this.remainPrice - hourPrice;
- this.maxReduceDiscount = remainConsumeTime > maxOneTimeDiscountFee / hourPrice ? maxOneTimeDiscountFee / hourPrice : remainConsumeTime;
- // this.reduceHours = maxConsumeTime;
- }
- const [isCrossMessage = false, maxReduceDiscount = 0] = this.crossMessage();
- if (isCrossMessage) {
- // console.log(215, maxReduceDiscount)
- // console.log(207, this.reduceHours)
- // this.maxReduceDiscount = maxReduceDiscount ? 0 : maxReduceDiscount * -1
- // console.log(217, this.maxReduceDiscount)
- this.remainPrice = this.remainPrice - maxReduceDiscount * hourPrice;
- //
- // this.reduceHours = this.maxReduceDiscount
- }
- },
- // 超限提示
- crossMessage() {
- const { maxOneTimeDiscountTime, hourPrice, oneTimeLimitation, oneDayLimitation, maxOneDayDiscountFee } = this.orderDetail.parkingRule;
- const maxOneTimeDiscountFee = maxOneTimeDiscountTime * hourPrice;
- // 单日上限
- if (oneDayLimitation && this.remainPrice >= maxOneDayDiscountFee) {
- 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];
- }
- 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) {
- 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') {
- this.memberGrade = {
- ...this.memberGrade,
- selected: this.checkedList.indexOf(key) > -1,
- };
- orderDetail.discountInfo.memberGrade = [this.memberGrade];
- }
- if (key === 'reduces') {
- 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();
- }
- },
- },
- };
|