From 69a3df7d4073f55679ec2254908d994146ac7b46 Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Sun, 21 Jun 2026 18:12:54 +0800 Subject: [PATCH] 1 --- package2/group/groupBuySingle.vue | 384 +++++++++++++++++++++++------- 1 file changed, 303 insertions(+), 81 deletions(-) diff --git a/package2/group/groupBuySingle.vue b/package2/group/groupBuySingle.vue index cc29346..2a94acb 100644 --- a/package2/group/groupBuySingle.vue +++ b/package2/group/groupBuySingle.vue @@ -458,24 +458,6 @@ - - - - 优惠券 - - - -¥{{selectedCoupon.discountAmount.toFixed(2)}} - - - 有 {{availableCoupons.length}} 张可用 - - - 无可用券 - - - @@ -545,32 +527,40 @@ - - - - - + + + + + 支付剩余时间 - - ¥{{backendTotalAmount ? backendTotalAmount.toFixed(2) : '0.00'}} + + ¥{{formatMoney(getPayTotalAmount())}} - - - - 配送费(均摊){{tuanzhangOrder.deliveryFee}} 元 - - - 打包费 - {{currentItem.lunchBox}} 元 - - - 优惠券抵扣 -¥{{selectedCoupon.discountAmount.toFixed(2)}} + + + 商品金额 + ¥{{formatMoney(getPayGoodsAmount())}} + + + 餐盒费 + ¥{{formatMoney(getPayPackageFee())}} + + + 配送费(均摊) + ¥{{formatMoney(getPayDeliveryFee())}} + + + 优惠券 + + -¥{{formatMoney(getCouponDiscount(selectedCoupon))}} + 有 {{availableCoupons.length}} 张可用 + 无可用券 + + + - + 若拼团失败,将会为您自动退款 @@ -622,9 +612,7 @@ alt="" style="width: 36rpx;height: 36rpx;" /> - + 确认付款{{nowMake && groupdeliveryType == 2 && !isStoreGroupOrder ? '-即刻出餐' : ''}} @@ -676,27 +664,27 @@ - + 选择优惠券 - + - {{item.discountAmount}} + {{formatMoney(getCouponDiscount(item))}} - {{item.couponName}} + {{getCouponName(item)}} - - 满{{item.minAmount}}可用 + + 满{{formatMoney(getCouponMinAmount(item))}}可用 无门槛使用 @@ -806,6 +794,8 @@ backendTotalAmount: 0, currentOrderId: '', isCreatingOrder: false, + createdOrderInfo: null, + pendingPaySpecChoices: null, onlineWorkerInterval: 2500, onlineWorkerDuration: 500, menuList: [{ @@ -816,6 +806,7 @@ shopRecommend: [], availableCoupons: [], selectedCoupon: null, + navigatingFromPayPopup: false, freeOrderEffectVisible: false, freeOrderAmount: '0.00', popupPageStyle: '', @@ -987,9 +978,106 @@ } this.popupPageStyle = this.bottomPopupOpenCount > 0 ? 'overflow:hidden;' : ''; }, + onPayPopupChange(e) { + this.onBottomPopupChange(e); + if (!e.show && this.currentOrderId && !this.navigatingFromPayPopup) { + this.goPayOrderDetail(); + } + }, nowMakeMethod() { this.nowMake = !this.nowMake }, + toNumber(value) { + let amount = parseFloat(value); + return isNaN(amount) ? 0 : amount; + }, + getCouponDiscount(coupon) { + if (!coupon) return 0; + return this.toNumber(coupon.discountAmount || coupon.discountFee || coupon.amount || 0); + }, + getCouponMinAmount(coupon) { + if (!coupon) return 0; + return this.toNumber(coupon.minAmount || coupon.thresholdAmount || 0); + }, + getCouponName(coupon) { + if (!coupon) return '优惠券'; + if (coupon.couponName) return coupon.couponName; + if (coupon.name) return coupon.name; + if (coupon.title) return coupon.title; + return coupon.issuerType == 2 ? '商家优惠券' : '平台优惠券'; + }, + normalizeCoupons(list) { + return (list || []).map(item => { + return Object.assign({}, item, { + discountAmount: this.getCouponDiscount(item), + minAmount: this.getCouponMinAmount(item), + couponName: this.getCouponName(item) + }); + }); + }, + getMoreBuyAmount() { + let list = this.currentItem && this.currentItem.moreBuyData ? this.currentItem.moreBuyData : this.moreBuyData; + let amount = 0; + for (let i = 0; i < list.length; i++) { + if (list[i].quantity > 0) { + amount += Number((Number(list[i].quantity) * Number(this.sliceMsg2(list[i].attributeListPrice))).toFixed(2)); + } + } + return amount; + }, + getFaceToFaceGoodsAmount() { + return this.toNumber(this.selectedGroupRule && this.selectedGroupRule.groupPrice) + this.getMoreBuyAmount(); + }, + getPayGoodsAmount() { + if (this.createdOrderInfo && this.createdOrderInfo.goodsAmount != null) { + return this.toNumber(this.createdOrderInfo.goodsAmount); + } + return this.getFaceToFaceGoodsAmount(); + }, + getPayPackageFee() { + if (this.createdOrderInfo && this.createdOrderInfo.packageFee != null) { + return this.toNumber(this.createdOrderInfo.packageFee); + } + return this.groupdeliveryType == 1 ? this.toNumber(this.currentItem && this.currentItem.lunchBox) : 0; + }, + getPayDeliveryFee() { + if (this.createdOrderInfo && this.createdOrderInfo.deliveryFee != null) { + return this.toNumber(this.createdOrderInfo.deliveryFee); + } + return this.toNumber(this.tuanzhangOrder && this.tuanzhangOrder.deliveryFee); + }, + getPayTotalAmount() { + if (this.createdOrderInfo && this.backendTotalAmount) { + return this.toNumber(this.backendTotalAmount); + } + let total = this.getPayGoodsAmount() + this.getPayPackageFee() + this.getPayDeliveryFee(); + if (this.selectedCoupon) { + total -= this.getCouponDiscount(this.selectedCoupon); + } + return total > 0 ? total : 0.01; + }, + refreshSelectedGroupPayPrice() { + if (!this.selectedGroupRule) return; + let amount = this.getFaceToFaceGoodsAmount(); + if (this.selectedCoupon) { + amount -= this.getCouponDiscount(this.selectedCoupon); + } + this.selectedGroupRule.groupPriceAndMore = amount > 0 ? amount : 0.01; + }, + goPayOrderDetail() { + if (!this.currentOrderId) return; + this.navigatingFromPayPopup = true; + uni.redirectTo({ + url: '/package1/order/orderDetail?id=' + this.currentOrderId + }); + }, + goPayOrderConfirm() { + this.navigatingFromPayPopup = true; + uni.redirectTo({ + url: '/package1/order/orderConfirm?id=' + this.currentOrderId + '&groupId=' + this.groupId + + '&amount=' + this.backendTotalAmount + }); + }, scrollGoodsListToTop() { // 滚到 catalog-row 顶部并紧贴 nav-bar const query = uni.createSelectorQuery().in(this); @@ -1196,7 +1284,7 @@ obj : max)); this.selectedGroupRule.groupPriceAndMore = this.selectedGroupRule.groupPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1206,7 +1294,7 @@ prev : curr)); this.selectedGroupRule.groupPriceAndMore = this.selectedGroupRule.groupPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1220,7 +1308,7 @@ this.selectedGroupRule = item.productGroupBuyPrices[0]; this.selectedGroupRule.groupPriceAndMore = this.selectedGroupRule.groupPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1239,7 +1327,7 @@ } this.selectedGroupRule.groupPriceAndMore = Number(this.selectedGroupRule.groupPrice) + moreBuyPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1357,7 +1445,6 @@ if (this.isFaceToFaceGroup) { if (this.parsedSpecs.length === 0) { - // No specs needed, jump straight to direct pay this.submitFTFJoinPay({}); return; } @@ -1436,7 +1523,7 @@ this.selectedGroupRule = rule; this.selectedGroupRule.groupPriceAndMore = this.selectedGroupRule.groupPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1474,7 +1561,6 @@ } } if (this.groupId && this.isFaceToFaceGroup) { - // Direct face-to-face pay path this.submitFTFJoinPay(specChoices); return } @@ -1503,8 +1589,16 @@ if (this.$refs.pintuanPopup) this.$refs.pintuanPopup.close(); return; } - if (this.isCreatingOrder) return; - this.isCreatingOrder = true; + this.pendingPaySpecChoices = specChoices || {}; + this.groupdeliveryType = this.tuanzhangOrder.deliveryType; + this.backendTotalAmount = 0; + this.createdOrderInfo = null; + this.navigatingFromPayPopup = false; + this.fetchCoupons(); + this.$refs.payPopup.open('bottom'); + if (this.$refs.pintuanPopup) this.$refs.pintuanPopup.close(); + }, + buildFTFJoinPayload(specChoices) { let items = [{ productId: this.currentItem.id, specs: JSON.stringify(specChoices || {}), @@ -1526,7 +1620,7 @@ let packageFee = parseFloat(this.currentItem.lunchBox || 0); - let payload = { + return { userId: uni.getStorageSync('id') || 'test-user123', shopId: this.shopItem.id, deliveryType: this.tuanzhangOrder.deliveryType, @@ -1540,9 +1634,18 @@ shopPhone: this.shopItem.shopPhone || '', shopAddress: this.shopItem.shopAddress || '', groupId: this.groupId, - userCouponId: this.selectedCoupon ? this.selectedCoupon.id : null + userCouponId: this.selectedCoupon ? this.selectedCoupon.id : null, + regionId: JSON.parse(uni.getStorageSync('area')).id }; - payload.regionId = JSON.parse(uni.getStorageSync('area')).id + }, + createFTFJoinOrder(specChoices, autoPay) { + if (this.isCreatingOrder) return; + this.isCreatingOrder = true; + let payload = this.buildFTFJoinPayload(specChoices); + if (!payload) { + this.isCreatingOrder = false; + return; + } uni.showLoading({ title: '创建订单中....' }); @@ -1553,10 +1656,18 @@ this.currentOrderId = res.result.id; this.groupdeliveryType = res.result.deliveryType; this.backendTotalAmount = res.result.totalAmount; + this.createdOrderInfo = res.result; if (res.result.isFreeOrder == 1) { this.showFreeOrderEffect(res.result); } - this.$refs.payPopup.open('bottom'); + this.pendingPaySpecChoices = null; + if (autoPay) { + this.$nextTick(() => { + this.wxPayment(); + }); + } else { + this.$refs.payPopup.open('bottom'); + } if (this.$refs.pintuanPopup) this.$refs.pintuanPopup.close(); } else { uni.showToast({ @@ -1801,7 +1912,7 @@ } this.selectedGroupRule.groupPriceAndMore = Number(this.selectedGroupRule.groupPrice) + moreBuyPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1835,7 +1946,7 @@ } this.selectedGroupRule.groupPriceAndMore = Number(this.selectedGroupRule.groupPrice) + moreBuyPrice if (this.selectedCoupon) { - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); + this.selectedGroupRule.groupPriceAndMore -= this.getCouponDiscount(this.selectedCoupon); if (this.selectedGroupRule.groupPriceAndMore <= 0) { this.selectedGroupRule.groupPriceAndMore = 0.01 } @@ -1849,7 +1960,12 @@ }, wxPayment() { let that = this; - if (!this.currentOrderId || !this.backendTotalAmount) return; + if (!this.currentOrderId || !this.backendTotalAmount) { + if (this.pendingPaySpecChoices) { + this.createFTFJoinOrder(this.pendingPaySpecChoices, true); + } + return; + } let amountInCents = Math.round(this.backendTotalAmount * 100); let userRequireMake = 0 @@ -1886,14 +2002,10 @@ that.tui.toast("订单创建失败,请联系客服处理"); } }) */ - uni.redirectTo({ - url: '/package1/order/orderConfirm?id=' + that - .currentOrderId + '&groupId=' + that.groupId + - '&amount=' + that.backendTotalAmount - }); + that.goPayOrderConfirm(); }, fail: function(err) { - that.tui.toast("支付失败或取消"); + that.goPayOrderDetail(); } }); } else { @@ -1902,13 +2014,14 @@ that.tui.request( `/hiver/order/payMallOrderSuccess?orderId=${that.currentOrderId}&workerId=`, "POST", {}, false, false).then(res2 => { + that.navigatingFromPayPopup = true; that.$refs.payPopup.close(); uni.showToast({ title: '支付成功(模拟)', icon: 'none' }); setTimeout(() => { - that.$refs.joinSuccessPopup.open('bottom'); + that.goPayOrderConfirm(); }, 1500); }); } else { @@ -1927,10 +2040,9 @@ }, 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', { + if (!userId) return Promise.resolve([]); + let amount = this.getFaceToFaceGoodsAmount(); + return this.tui.request('/mall/coupon/available', 'GET', { userId: userId, applyScene: 1, regionId: JSON.parse(uni.getStorageSync('area')).id, @@ -1938,12 +2050,13 @@ merchantId: this.shopItem.id || '0' }, false, true).then((res) => { if (res.code == 200 && res.result) { - this.availableCoupons = res.result; + this.availableCoupons = this.normalizeCoupons(res.result); if (this.selectedCoupon) { let stillValid = this.availableCoupons.find(c => c.id === this.selectedCoupon.id); if (!stillValid) this.selectedCoupon = null; } } + return this.availableCoupons; }); }, openMianRemark() { @@ -1952,10 +2065,7 @@ }, selectCoupon(item) { this.selectedCoupon = item; - this.selectedGroupRule.groupPriceAndMore -= parseFloat(this.selectedCoupon.discountAmount); - if (this.selectedGroupRule.groupPriceAndMore <= 0) { - this.selectedGroupRule.groupPriceAndMore = 0.01 - } + this.refreshSelectedGroupPayPrice(); this.$refs.couponPopup.close(); }, openCouponPopup() { @@ -3565,6 +3675,118 @@ background: rgba(255, 248, 224, 0.64); } + .pay-popup { + height: auto; + background: #fff; + border-radius: 40rpx 40rpx 0 0; + padding-top: 34rpx; + padding-bottom: calc(30rpx + env(safe-area-inset-bottom)); + } + + .pay-popup-content { + height: 100%; + margin-top: 0; + } + + .pay-summary-card { + padding: 28rpx 30rpx 24rpx; + } + + .pay-countdown { + display: flex; + align-items: center; + justify-content: center; + min-height: 54rpx; + color: #586963; + font-size: 26rpx; + } + + .pay-amount { + margin-top: 8rpx; + text-align: center; + font-size: 30rpx; + font-weight: 800; + line-height: 84rpx; + color: #00231C; + } + + .pay-amount text { + font-size: 62rpx; + } + + .pay-fee-list { + margin-top: 14rpx; + padding: 18rpx 22rpx; + border-radius: 22rpx; + background: #f8fbf9; + border: 1rpx solid #edf3f0; + } + + .pay-fee-row { + display: flex; + align-items: center; + justify-content: space-between; + min-height: 44rpx; + color: #65756f; + font-size: 24rpx; + line-height: 34rpx; + } + + .pay-fee-row + .pay-fee-row { + margin-top: 8rpx; + } + + .pay-fee-row text:last-child { + margin-left: 20rpx; + color: #243a34; + font-weight: 800; + } + + .pay-fee-discount text { + color: #ff5722 !important; + } + + .pay-coupon-entry { + transition: transform 0.18s ease; + } + + .pay-coupon-entry:active { + transform: scale(0.98); + } + + .pay-coupon-value { + display: flex; + align-items: center; + justify-content: flex-end; + color: #0b9b73; + font-weight: 800; + } + + .pay-coupon-value text:first-child { + margin-right: 8rpx; + color: inherit; + } + + .pay-refund-tip { + margin-top: 16rpx; + text-align: center; + color: #f0441f; + font-size: 24rpx; + line-height: 36rpx; + } + + .pay-confirm-btn { + background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1)); + width: 90%; + height: 100rpx; + border-radius: 100rpx; + text-align: center; + font-size: 28rpx; + font-weight: 700; + line-height: 100rpx; + margin: 40rpx auto; + } + .popup-bottom-bar { background: rgba(255, 255, 255, 0.98); box-shadow: 0 -12rpx 28rpx rgba(0, 35, 28, 0.1);