diff --git a/package1/buyFood/buyFood.vue b/package1/buyFood/buyFood.vue index b1a678d..61e6395 100644 --- a/package1/buyFood/buyFood.vue +++ b/package1/buyFood/buyFood.vue @@ -247,6 +247,22 @@ + + + 优惠券 + + + -¥{{selectedCoupon.discountAmount.toFixed(2)}} + + + 有 {{availableCoupons.length}} 张可用 + + + 无可用券 + + + @@ -368,6 +384,41 @@ + + + + + 选择优惠券 + + + + + + + {{item.discountAmount}} + + + {{item.couponName}} + 满{{item.minAmount}}可用 + 无门槛使用 + + + + + + + 暂无可用优惠券 + + + + + + 不使用优惠券 + + + + > @@ -404,7 +455,9 @@ backendTotalAmount: 0, currentOrderId: '', createdOrderInfo: null, - isPaymentSuccessGroupInitiate: false + isPaymentSuccessGroupInitiate: false, + availableCoupons: [], + selectedCoupon: null } }, components: { @@ -508,6 +561,13 @@ return commission + this.highFloorFeeCalc; }, totalAmountCalc() { + let total = this.preDiscountTotal; + if (this.selectedCoupon) { + total -= parseFloat(this.selectedCoupon.discountAmount); + } + return total > 0 ? total : 0; + }, + preDiscountTotal() { if(this.isPaotui==true){ return this.goodsAmountCalc + this.packageFee + this.deliveryFeeCalc; }else{ @@ -515,6 +575,13 @@ } } }, + watch: { + preDiscountTotal(newVal, oldVal) { + if (newVal !== oldVal) { + this.fetchCoupons(); + } + } + }, onShow() { this.menuButtonInfo = uni.getMenuButtonBoundingClientRect() this.initAddress() @@ -627,9 +694,36 @@ url: `/package1/index/deliveryPersonList?orderType=0&shopAreaId=${shopArea}&putAreaId=${putArea}` }) }, + openCouponPopup() { + this.fetchCoupons(); + this.$refs.couponPopup.open('bottom'); + }, + fetchCoupons() { + let userId = uni.getStorageSync('id'); + if (!userId) return; + let amount = this.preDiscountTotal; + this.tui.request('/mall/coupon/available', 'GET', { + userId: userId, + regionId:JSON.parse(uni.getStorageSync('area')).id, + applyScene: 1, + amount: amount, + merchantId: this.shopItem.shopId || '0' + }, false, true).then((res) => { + if (res.code == 200 && res.result) { + this.availableCoupons = res.result; + if (this.selectedCoupon) { + let stillValid = this.availableCoupons.find(c => c.id === this.selectedCoupon.id); + if (!stillValid) this.selectedCoupon = null; + } + } + }); + }, + selectCoupon(item) { + this.selectedCoupon = item; + this.$refs.couponPopup.close(); + }, openAddressBook() { this.$refs.bookPopup.open('bottom') - }, checkTime(type) { if (type === this.formData.isImmediately) { @@ -841,6 +935,8 @@ payload.getAreaId = this.shopItem.shopArea || null; payload.putAreaId = this.formData.address ? this.formData.address.areaId : null; } + + payload.userCouponId = this.selectedCoupon ? this.selectedCoupon.id : null; if (this.isGroupBuy && this.groupItem) { if (this.groupItem.groupId) { diff --git a/package1/group/groupBuySingle.vue b/package1/group/groupBuySingle.vue index bf750c8..1fcb19c 100644 --- a/package1/group/groupBuySingle.vue +++ b/package1/group/groupBuySingle.vue @@ -340,6 +340,22 @@ + + + + 优惠券 + + + -¥{{selectedCoupon.discountAmount.toFixed(2)}} + + + 有 {{availableCoupons.length}} 张可用 + + + 无可用券 + + + @@ -428,6 +444,9 @@ 打包费 {{currentItem.lunchBox}} 元 + + 优惠券抵扣 -¥{{selectedCoupon.discountAmount.toFixed(2)}} + 若拼团失败,将会为您自动退款 @@ -479,6 +498,42 @@ + + + + + + 选择优惠券 + + + + + + + {{item.discountAmount}} + + + {{item.couponName}} + 满{{item.minAmount}}可用 + 无门槛使用 + + + + + + + 暂无可用优惠券 + + + + + + 不使用优惠券 + + + + @@ -546,7 +601,9 @@ id: '1', checked: true }], - shopRecommend:[] + shopRecommend:[], + availableCoupons: [], + selectedCoupon: null } }, components: { @@ -631,6 +688,7 @@ }, onShow() { this.menuButtonInfo = uni.getMenuButtonBoundingClientRect(); + //this.fetchCoupons(); // 计算导航栏高度用于sticky offset:statusBarHeight + 40px内容区 const info = uni.getSystemInfoSync(); this.navBarHeight = info.statusBarHeight + 40; @@ -905,7 +963,9 @@ this.$refs.pintuanGroupPopup.close(); this.groupId = item.id; this.targetMembers = parseInt(item.targetMembers); + this.selectedCoupon = null; if(this.chooseWaitType){ + this.fetchCoupons(); this.$refs.pintuanPopup.open('bottom'); } }, @@ -936,6 +996,7 @@ if (index == 'pintuan') { this.isPintuan = true; + this.selectedCoupon = null; if (this.groupId) { // Determine best price match given targetMembers @@ -976,6 +1037,7 @@ } this.selectedGroupRule.groupPriceAndMore = Number(this.selectedGroupRule.groupPrice) + moreBuyPrice + this.fetchCoupons(); this.$refs.pintuanPopup.open('bottom'); } else { this.isPintuan = false; @@ -1082,7 +1144,8 @@ shopName: this.shopItem.shopName, shopPhone: this.shopItem.shopPhone || '', shopAddress: this.shopItem.shopAddress || '', - groupId: this.groupId + groupId: this.groupId, + userCouponId: this.selectedCoupon ? this.selectedCoupon.id : null }; payload.regionId = JSON.parse(uni.getStorageSync('area')).id uni.showLoading({ title: '创建订单中...' }); @@ -1332,6 +1395,34 @@ }); } }, + fetchCoupons() { + let userId = uni.getStorageSync('id'); + if (!userId) return; + let amount = this.selectedGroupRule && this.selectedGroupRule.groupPriceAndMore ? this.selectedGroupRule.groupPriceAndMore : 0; + this.tui.request('/mall/coupon/available', 'GET', { + userId: userId, + applyScene: 1, + regionId:JSON.parse(uni.getStorageSync('area')).id, + amount: amount, + merchantId: this.shopItem.id || '0' + }, false, true).then((res) => { + if (res.code == 200 && res.result) { + this.availableCoupons = res.result; + if (this.selectedCoupon) { + let stillValid = this.availableCoupons.find(c => c.id === this.selectedCoupon.id); + if (!stillValid) this.selectedCoupon = null; + } + } + }); + }, + selectCoupon(item) { + this.selectedCoupon = item; + this.$refs.couponPopup.close(); + }, + openCouponPopup() { + this.fetchCoupons(); + this.$refs.couponPopup.open('bottom'); + }, back() { uni.navigateBack() } diff --git a/package1/runErrand/runErrand.vue b/package1/runErrand/runErrand.vue index b63a54a..2eaa0b5 100644 --- a/package1/runErrand/runErrand.vue +++ b/package1/runErrand/runErrand.vue @@ -217,6 +217,21 @@ ¥{{deliveryFeeCalc.toFixed(2)}} + + + 优惠券 + + + -¥{{selectedCoupon.discountAmount.toFixed(2)}} + + + 有 {{availableCoupons.length}} 张可用 + + + 无可用券 + + + 合计 ¥{{totalAmountCalc.toFixed(2)}} @@ -300,6 +315,41 @@ 指定配送员 + + + + + 选择优惠券 + + + + + + + {{item.discountAmount}} + + + {{item.couponName}} + 满{{item.minAmount}}可用 + 无门槛使用 + + + + + + + 暂无可用优惠券 + + + + + + 不使用优惠券 + + + + @@ -337,7 +387,9 @@ immediateTimeStr: '', backendTotalAmount: 0, currentOrderId: '', - warnPopup: '' + warnPopup: '', + availableCoupons: [], + selectedCoupon: null } }, components: { @@ -367,17 +419,27 @@ return commission + this.highFloorFeeCalc; }, totalAmountCalc() { - return this.deliveryFeeCalc; + let total = this.deliveryFeeCalc; + if (this.selectedCoupon) { + total = total - parseFloat(this.selectedCoupon.discountAmount); + } + return total > 0 ? total : 0; + } + }, + watch: { + deliveryFeeCalc(newVal, oldVal) { + if (newVal !== oldVal) { + this.fetchCoupons(); + } } }, onLoad() { - + //this.getShopArea() }, onShow() { - this.getShopArea() this.menuButtonInfo = uni.getMenuButtonBoundingClientRect() this.initAddress() - + const now = new Date(); const startTime = new Date(now); const endTime = new Date(now); @@ -398,6 +460,34 @@ uni.removeStorageSync('pendingAssignWorker'); }, methods: { + openCouponPopup() { + this.fetchCoupons(); + this.$refs.couponPopup.open('bottom'); + }, + fetchCoupons() { + let userId = uni.getStorageSync('id'); + if (!userId) return; + let amount = this.deliveryFeeCalc; + this.tui.request('/mall/coupon/available', 'GET', { + userId: userId, + applyScene: 2, + regionId:JSON.parse(uni.getStorageSync('area')).id, + amount: amount, + merchantId: '0' + }, false, true).then((res) => { + if (res.code == 200 && res.result) { + this.availableCoupons = res.result; + if (this.selectedCoupon) { + let stillValid = this.availableCoupons.find(c => c.id === this.selectedCoupon.id); + if (!stillValid) this.selectedCoupon = null; + } + } + }); + }, + selectCoupon(item) { + this.selectedCoupon = item; + this.$refs.couponPopup.close(); + }, getShopArea(){ let that = this let areaStorage = uni.getStorageSync('area'); @@ -715,7 +805,8 @@ getCodes: codes, getPictures: pics, regionId: JSON.parse(uni.getStorageSync('area')).id, - deliveryFee: this.deliveryFeeCalc + deliveryFee: this.deliveryFeeCalc, + userCouponId: this.selectedCoupon ? this.selectedCoupon.id : null }; let mft = this.getMustFinishTime();