|
@@ -0,0 +1,354 @@
|
|
|
+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},
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ checkedList: [], // 已选优惠列表
|
|
|
+ oldCheckedList: [], // 已选优惠列表备份
|
|
|
+ isMember: false, // member
|
|
|
+ isReduces: false, // reduces
|
|
|
+ memberLevelReduce: [],
|
|
|
+ memberGrade: {},
|
|
|
+ consume: {},
|
|
|
+ // todayReduceDiscountMessage: '',
|
|
|
+ isMemberDiscountDisabled: false,
|
|
|
+ maxDiscountTime: 0,
|
|
|
+ enableConsumeSplit: false,
|
|
|
+ maxReduceDiscount: 0,
|
|
|
+ reduceHours: 0,
|
|
|
+ remainPrice: 0,
|
|
|
+ reduceFee: 0, // 消费减免金额
|
|
|
+ isInit: 1,
|
|
|
+ isDiscountDisabled: false,
|
|
|
+ remainReduceTime: 0,
|
|
|
+ //
|
|
|
+ usingTotalDiscount: 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,
|
|
|
+ availableDiscountFee: (state) => state.order.availableDiscountFee,
|
|
|
+ paperDiscountFee: (state) => state.order.paperDiscountFee, // 纸质优惠券
|
|
|
+ }),
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ // 消费减免(拆分部分)提示文本
|
|
|
+ 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.remainConsumeTime}小时`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 沈阳提示信息
|
|
|
+ if (this.parkMallCode === 4 || this.parkMallCode === 6) {
|
|
|
+ return `未达上限时今日可减免${this.orderDetail.parkingRule.remainConsumeTime}小时`;
|
|
|
+ }
|
|
|
+ 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}元`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async mounted() {
|
|
|
+ try {
|
|
|
+ await waitByTime(200);
|
|
|
+
|
|
|
+ const {usingTotalDiscount, memberGrade = [], consume = []} = this.orderDetail.discountInfo;
|
|
|
+ if (memberGrade.length) {
|
|
|
+ this.memberGrade = memberGrade[0]
|
|
|
+ }
|
|
|
+ if (consume.length) {
|
|
|
+ this.consume = consume[0]
|
|
|
+ }
|
|
|
+ // 开始初始化
|
|
|
+ this.pageInit()
|
|
|
+ } catch (err) {
|
|
|
+ this.$router.back()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ async pageInit() {
|
|
|
+ await waitByTime(200);
|
|
|
+ const {hourPrice = 0, remainConsumeTime = 0, maxOneTimeDiscountTime = 0} = this.orderDetail.parkingRule;
|
|
|
+ const {usingTotalDiscount} = this.orderDetail.discountInfo;
|
|
|
+ this.usingTotalDiscount = usingTotalDiscount
|
|
|
+ /*页面的默认展示*/
|
|
|
+ /*会员等级减免是否选中*/
|
|
|
+ if (JSON.stringify(this.memberGrade) !== '{}' && this.memberGrade && this.memberGrade.hasOwnProperty('selected') ? this.memberGrade.selected : this.memberGrade.defaultSelected) {
|
|
|
+ this.checkedList.push('member');
|
|
|
+ }
|
|
|
+ /*消费减免是否选中*/
|
|
|
+ if (JSON.stringify(this.consume) !== '{}' && this.consume.hasOwnProperty('selected') ? this.consume.selected : this.consume.defaultSelected !== undefined) {
|
|
|
+ this.checkedList.push('reduces');
|
|
|
+ }
|
|
|
+ // 已用优惠时长 已经拿到了 usingTotalDiscount
|
|
|
+ // 剩余可用优惠时长 remainConsumeTime
|
|
|
+ /*
|
|
|
+ 1、浦东每次上限处理
|
|
|
+ 如果 剩余可用优惠时长 > 当前可用上限时间
|
|
|
+ 则
|
|
|
+ 剩余可用优惠时长 = 当前可用上限时间
|
|
|
+ */
|
|
|
+ if (this.parkMallCode === 1 && remainConsumeTime > maxOneTimeDiscountTime) {
|
|
|
+ this.remainConsumeTime = maxOneTimeDiscountTime;
|
|
|
+ }
|
|
|
+ if (this.parkMallCode === 1 && remainConsumeTime > maxOneTimeDiscountTime) {
|
|
|
+ this.remainConsumeTime = maxOneTimeDiscountTime;
|
|
|
+ }
|
|
|
+ // 沈阳、天津上限处理
|
|
|
+ if (this.parkMallCode === 4 || this.parkMallCode === 6) {
|
|
|
+ this.remainReduceTime = this.consume.maxDiscountTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 消费减免可拆分上限
|
|
|
+ this.maxReduceDiscount = this.consume.defaultDiscountTime;
|
|
|
+ if (this.maxReduceDiscount > remainConsumeTime) {
|
|
|
+ this.maxReduceDiscount = remainConsumeTime;
|
|
|
+ }
|
|
|
+ this.reduceHours = this.maxReduceDiscount;
|
|
|
+
|
|
|
+ // 反显处理
|
|
|
+ if (this.consume.discountFee) {
|
|
|
+ this.reduceHours = (this.consume.discountFee / hourPrice) || 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 浦东上限控制
|
|
|
+ if (this.parkMallCode === 1 || this.parkMallCode === 4 || this.parkMallCode === 6) {
|
|
|
+ if (this.memberGrade.discountFee) {
|
|
|
+ this.maxReduceDiscount = remainConsumeTime - (this.memberGrade.discountFee / hourPrice);
|
|
|
+ if ((this.parkMallCode === 4 || this.parkMallCode === 6) && this.maxReduceDiscount > this.consume.defaultDiscountTime) {
|
|
|
+ this.maxReduceDiscount = this.consume.defaultDiscountTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // this.reduceHours = this.maxReduceDiscount;
|
|
|
+ if (this.crossMessage()) {
|
|
|
+ if (this.isCheck('reduces')) {
|
|
|
+ this.maxReduceDiscount = this.reduceHours;
|
|
|
+ } else {
|
|
|
+ this.maxReduceDiscount = 0;
|
|
|
+ this.reduceHours = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!this.isCheck('reduces')) {
|
|
|
+ this.reduceHours = this.maxReduceDiscount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ discountInit() {
|
|
|
+
|
|
|
+ },
|
|
|
+ maxReduceDiscountInit() {
|
|
|
+ },
|
|
|
+ setIsMemberDiscountDisabled() {
|
|
|
+ this.todayReduceDiscountMessage = '当日';
|
|
|
+ },
|
|
|
+ async checkboxChange() {
|
|
|
+ const {hourPrice = 0, remainConsumeTime = 0, maxOneTimeDiscountTime = 0} = this.orderDetail.parkingRule;
|
|
|
+ // const {usingTotalDiscount} = this.orderDetail.discountInfo;
|
|
|
+ // 浦东上限控制
|
|
|
+ if (this.parkMallCode === 1) {
|
|
|
+ if (this.isCheck('member')) {
|
|
|
+ this.maxReduceDiscount = remainConsumeTime - ((this.usingTotalDiscount - this.paperDiscountFee - this.memberGrade?.discountFee || 0) / hourPrice)
|
|
|
+ this.usingTotalDiscount -= this.reduceHours * hourPrice
|
|
|
+ await waitByTime()
|
|
|
+ this.reduceHours = this.maxReduceDiscount
|
|
|
+ this.usingTotalDiscount += this.reduceHours * hourPrice
|
|
|
+ } else {
|
|
|
+ if (this.isCheck('reduces')) {
|
|
|
+ this.maxReduceDiscount = remainConsumeTime - ((this.usingTotalDiscount - this.paperDiscountFee - this.reduceFee) / hourPrice);
|
|
|
+ this.reduceHours = this.maxReduceDiscount;
|
|
|
+ this.usingTotalDiscount += this.reduceHours * hourPrice
|
|
|
+ } else {
|
|
|
+ this.usingTotalDiscount -= this.reduceHours * hourPrice
|
|
|
+ this.maxReduceDiscount = remainConsumeTime - ((this.usingTotalDiscount - this.paperDiscountFee) / hourPrice);
|
|
|
+ this.reduceHours = this.maxReduceDiscount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await waitByTime()
|
|
|
+ // 沈阳、天津上限控制
|
|
|
+ if (this.parkMallCode === 4 || this.parkMallCode === 6) {
|
|
|
+ if (this.isCheck('member')) {
|
|
|
+ this.usingTotalDiscount += this.memberGrade.discountFee
|
|
|
+ } else {
|
|
|
+ this.usingTotalDiscount -= this.memberGrade.discountFee
|
|
|
+ this.maxReduceDiscount = this.consume?.defaultDiscountTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(2525, this.reduceHours, this.maxReduceDiscount)
|
|
|
+ // 超限设置
|
|
|
+ this.crossMessage();
|
|
|
+ },
|
|
|
+ onReduceHoursChange(type) {
|
|
|
+ if (this.isCheck('reduces')) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const {hourPrice = 0, remainConsumeTime = 0, maxOneTimeDiscountTime = 0} = this.orderDetail.parkingRule;
|
|
|
+ if (type === 'minus') {
|
|
|
+ this.reduceHours = this.reduceHours - 1
|
|
|
+ this.usingTotalDiscount -= hourPrice
|
|
|
+ console.log(276, this.reduceHours)
|
|
|
+ }
|
|
|
+ if (type === 'plus' && !this.crossMessage()) {
|
|
|
+ this.reduceHours++
|
|
|
+ this.usingTotalDiscount += hourPrice
|
|
|
+ }
|
|
|
+ },
|
|
|
+ memberClick(e) {
|
|
|
+ if((!this.isCheck('member') && this.isDiscountDisabled) || !this.memberGrade.discountFee) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.isCheck('member')) {
|
|
|
+ this.checkedList = [...this.checkedList, 'member']
|
|
|
+ } else {
|
|
|
+ this.checkedList = this.checkedList.filter(elm => elm !== 'member')
|
|
|
+ }
|
|
|
+ this.checkboxChange()
|
|
|
+ },
|
|
|
+ reducesClick() {
|
|
|
+ if((!this.isCheck('reduces') && this.isDiscountDisabled) || !this.consume.defaultDiscountTime) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // && !this.crossMessage()
|
|
|
+ if (!this.isCheck('reduces')) {
|
|
|
+ this.checkedList = [...this.checkedList, 'reduces']
|
|
|
+ } else {
|
|
|
+ this.checkedList = this.checkedList.filter(elm => elm !== 'reduces')
|
|
|
+ }
|
|
|
+ this.checkboxChange()
|
|
|
+ },
|
|
|
+ // 超限提示
|
|
|
+ crossMessage(type) {
|
|
|
+ const {
|
|
|
+ hourPrice = 0,
|
|
|
+ remainConsumeTime = 0,
|
|
|
+ maxOneTimeDiscountFee = 0,
|
|
|
+ oneTimeLimitation,
|
|
|
+ oneDayLimitation,
|
|
|
+ maxOneTimeDiscountTime,
|
|
|
+ maxOneDayDiscountFee
|
|
|
+ } = this.orderDetail.parkingRule;
|
|
|
+ // const {usingTotalDiscount} = this.orderDetail.discountInfo;
|
|
|
+ this.isDiscountDisabled = false;
|
|
|
+ // 浦东每次总优惠上限
|
|
|
+ if (oneTimeLimitation && (this.usingTotalDiscount - this.paperDiscountFee) / hourPrice >= maxOneTimeDiscountTime) {
|
|
|
+ this.isDiscountDisabled = true;
|
|
|
+ uni.showToast({
|
|
|
+ title: `超出抵扣上限,每次最高可抵扣${maxOneTimeDiscountTime}小时`,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ // 沈阳、天津
|
|
|
+ if (oneDayLimitation && this.usingTotalDiscount - this.paperDiscountFee >= maxOneDayDiscountFee) {
|
|
|
+ this.isDiscountDisabled = true;
|
|
|
+ uni.showToast({
|
|
|
+ title: `超出抵扣上限,每次最高可抵扣${maxOneDayDiscountFee / hourPrice}小时`,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ // 消费每天优惠上限(非浦东、沈阳)
|
|
|
+ if (this.parkMallCode !== 1 && this.parkMallCode !== 4 && this.parkMallCode !== 6 && this.reduceHours * hourPrice >= remainConsumeTime) {
|
|
|
+ this.reduces = remainConsumeTime;
|
|
|
+ uni.showToast({
|
|
|
+ title: `超出抵扣上限,消费减免每天最高可抵扣${this.parkInfoEntity.dateReduceUpperliLimit}小时,可使用${this.parkInfoEntity.remainReduceTime}小时`,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ },
|
|
|
+ // 验证当前的选项是否可选择
|
|
|
+ isCheck(val) {
|
|
|
+ return this.checkedList.findIndex(e => e == val) > -1;
|
|
|
+ },
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|