wangfukang 3 weeks ago
parent
commit
8625e4fa24
  1. 68
      package1/buyFood/buyFood.vue
  2. 237
      package1/group/groupBuySingle.vue

68
package1/buyFood/buyFood.vue

@ -282,10 +282,10 @@
</view>
</uni-popup>
<!-- 拼团分享弹出层 -->
<uni-popup ref="pintuanPopup" background-color="#fff">
<uni-popup ref="pintuanPopup" background-color="#fff" @change="onPintuanPopupChange">
<view class="pintuan-popup">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/ecd00dab1c9c44198d765bc08bc1bd71.png" alt=""
style="position: absolute;top: 0;right: 0;width: 240rpx;height: 180rpx;">
style="position: absolute;top: 0;right: 0;width: 240rpx;height: 180rpx;" @tap="$refs.pintuanPopup.close()">
<view style="position: absolute;bottom: 0;width: 100%;height: 760rpx;">
<view class="kaituan1">
<view class="kaituan1-title">
@ -318,7 +318,9 @@
剩余<text style="font-size: 32rpx;font-weight: 700;padding: 0 20rpx;color: red;">23:59:23</text>结束
</view>
<view class="kaituan4">
分享至微信 <uni-icons type="weixin" size="15"></uni-icons>
<button open-type="share" style="background:transparent;border:none;color:inherit;font-size:inherit;display:inline-flex;align-items:center;">
分享至微信 <uni-icons type="weixin" size="15"></uni-icons>
</button>
</view>
<view class="kaituan5">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/c1f1b45c98fa4db1a1e5f98b3a0573c2.png"
@ -360,7 +362,9 @@
immediateTimeStr: '',
totalPackageFee: 0,
backendTotalAmount: 0,
currentOrderId: ''
currentOrderId: '',
createdOrderInfo: null,
isPaymentSuccessGroupInitiate: false
}
},
components: {
@ -451,12 +455,29 @@
`${endTime.getHours().toString().padStart(2, '0')}:${endTime.getMinutes().toString().padStart(2, '0')}`;
this.immediateTimeStr = `${startStr}-${endStr}`;
// Listen for selected delivery person event
uni.$on('updateDeliveryWorker', (worker) => {
this.assignedWorker = worker;
this.selected = 'zhiding';
});
},
onShareAppMessage(res) {
if (this.isPaymentSuccessGroupInitiate) {
let groupId = this.createdOrderInfo?.groupId || this.createdOrderInfo?.groupDeliveryOrderId || this.createdOrderInfo?.id || this.currentOrderId;
let targetMembers = this.groupItem?.groupRule?.groupCount || 2;
let shopItemStr = encodeURIComponent(JSON.stringify(this.shopItem));
let isFTF = this.isFaceToFace ? 1 : 0;
let path = `/package1/group/groupBuySingle?type=shop&item=${shopItemStr}&groupId=${groupId}&targetMembers=${targetMembers}&isFaceToFace=${isFTF}`;
return {
title: '我发起了一个拼团,快来一起拼单吧!',
path: path,
}
}
return {
title: '买饭',
path: '/pages/index/index'
}
},
onUnload() {
uni.$off('updateDeliveryWorker');
},
@ -587,9 +608,7 @@
icon: 'success'
});
setTimeout(() => {
uni.navigateBack({
delta: 2
});
that.handlePaymentSuccess();
}, 1500);
},
fail: function(err) {
@ -608,9 +627,7 @@
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({
delta: 2
});
that.handlePaymentSuccess();
}, 1500);
}).catch(e => {
that.tui.toast("请求失败");
@ -621,6 +638,34 @@
}
})
},
handlePaymentSuccess() {
if (!this.isGroupBuy) {
uni.redirectTo({
url: '/package1/order/orderDetail?id=' + this.currentOrderId
});
} else {
let isInitiating = !this.groupItem.groupId;
let isJoining = !!this.groupItem.groupId;
if (isInitiating) {
this.isPaymentSuccessGroupInitiate = true;
this.$refs.pintuanPopup.open('center');
} else if (isJoining) {
uni.redirectTo({
url: '/package1/order/pendGroup?groupId=' + this.groupItem.groupId
});
}
}
},
onPintuanPopupChange(e) {
if (!e.show && this.isPaymentSuccessGroupInitiate) {
// pendGroup
let groupId = this.createdOrderInfo?.groupId || this.createdOrderInfo?.groupDeliveryOrderId || this.createdOrderInfo?.id || this.currentOrderId;
uni.redirectTo({
url: `/package1/order/pendGroup?groupId=${groupId}`
});
}
},
getMustFinishTime() {
if (!this.formData.deliveryTime || this.formData.deliveryTime === '自动送达' || this.formData.deliveryTime ===
'尽快送达') return null;
@ -723,6 +768,7 @@
let totalAmount = res.result.totalAmount;
this.backendTotalAmount = totalAmount;
this.currentOrderId = orderId;
this.createdOrderInfo = res.result;
this.$refs.payPopup.open('bottom');
} else {
uni.showToast({

237
package1/group/groupBuySingle.vue

@ -130,12 +130,12 @@
</view>
</view>
<view class="goods-bottom">
<view class="goods-btn" @tap="openPopup('xiadan','dandu',item)"
<view class="goods-btn" v-if="!groupId" @tap="openPopup('xiadan','dandu',item)"
style="background: rgba(166, 255, 234, 0.3);margin-right: 6%;border: 1px solid rgba(166, 255, 234, 0.5);">
直接购买¥{{item.attributeListPrice | sliceMsg}}
</view>
<view class="goods-btn" @tap="openPopup('xiadan','pintuan',item)">
拼团购买¥{{item.productGroupBuyPrices | slicePrice}}
<view class="goods-btn" :style="groupId ? 'width:100%;' : ''" @tap="openPopup('xiadan','pintuan',item)">
拼团购买¥{{ getGroupPrice(item) }}
</view>
</view>
</view>
@ -468,6 +468,71 @@
</scroll-view>
</view>
</uni-popup>
<!-- 支付弹出层 -->
<uni-popup ref="payPopup" background-color="#fff">
<view class="pay-popup" style="height: 480px;background: #fff;border-radius: 20px 20px 0 0;padding-top: 20px;">
<view class="content">
<view class="box1">
<view style="height: 70rpx;line-height: 70rpx;text-align: center;">
支付剩余时间 59:09
</view>
<view
style="height: 90rpx;line-height: 90rpx;text-align: center;font-weight: 700;font-size: 30rpx;">
<text
style="font-size: 60rpx;">{{backendTotalAmount ? backendTotalAmount.toFixed(2) : '0.00'}}</text>
</view>
<view style="height: 40rpx;text-align: center;color: red;">
若拼团失败将会为您自动退款
</view>
</view>
<view class="box1" style="display: flex;padding: 40rpx;">
<view style="flex: 1;">
<view style="height: 42rpx;line-height: 42rpx;display: flex;">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/4c8e0cc311db4d38ab43e019673c4b8c.png"
alt="" style="width: 42rpx;height: 42rpx;margin-right: 20rpx;" />
<text style="font-size: 30rpx;font-weight: 700;">微信支付</text>
</view>
<view style="text-align: right;margin-left: 60rpx;color: #777;width: 146rpx;">
使用微信支付
</view>
</view>
<view style="width: 36rpx;padding-top: 20rpx;">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/02bff7edc4e04caaa1868955ff684f1f.png"
alt="" style="width: 36rpx;height: 36rpx;" />
</view>
</view>
<view class="btn" style="background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1));width: 90%;height: 50px;border-radius: 50px;text-align: center;font-size: 14px;font-weight: 700;line-height: 50px;margin: 20px auto;" @tap="wxPayment">
确认付款
</view>
</view>
</view>
</uni-popup>
<!-- 参团成功提示弹出层 -->
<uni-popup ref="joinSuccessPopup" background-color="#fff" @change="onJoinSuccessPopupChange">
<view class="pintuan-popup" style="position: relative;height: 600px;width: 100%;border-top-left-radius: 10px;border-top-right-radius: 10px;padding: 10px;">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/ecd00dab1c9c44198d765bc08bc1bd71.png" alt=""
style="position: absolute;top: 0;right: 0;width: 240rpx;height: 180rpx;" @tap="$refs.joinSuccessPopup.close()">
<view style="position: absolute;bottom: 0;width: 100%;height: 760rpx;">
<view class="kaituan1">
<view class="kaituan1-title" style="margin-top: 100rpx;text-align: center;font-size: 40rpx;font-weight: bold;">
参团成功
</view>
<view class="kaituan1-title1" style="text-align: center;margin-top: 20rpx;color: #777;">
您已成功参与拼团
</view>
</view>
<view class="kaituan2" style="display: flex;justify-content: center;margin-top: 60rpx;">
<view class="kaituan22">
<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/801c569079da4540990c1cc634186fdd.png"
alt=""
style="width: 90rpx;height: 90rpx;border-radius: 90rpx;margin: 0 auto;display: block;" />
</view>
</view>
</view>
</view>
</uni-popup>
</view>
</template>
@ -505,6 +570,9 @@
isPintuan: true,
groupId: '',
isFaceToFaceGroup: false,
targetMembers: 2,
backendTotalAmount: 0,
currentOrderId: '',
menuList: [{
categoryName: '猜你喜欢',
id: '',
@ -587,10 +655,23 @@
if (option.isFaceToFace) {
this.isFaceToFaceGroup = option.isFaceToFace === '1' || option.isFaceToFace === 'true';
}
if (option.targetMembers) {
this.targetMembers = parseInt(option.targetMembers);
} else {
this.targetMembers = 2; // Default fallback
}
if (this.type == 'shop') {
this.shopItem = JSON.parse(option.item);
try {
this.shopItem = JSON.parse(decodeURIComponent(option.item));
} catch(e) {
this.shopItem = JSON.parse(option.item);
}
} else {
this.productItem = JSON.parse(option.item);
try {
this.productItem = JSON.parse(decodeURIComponent(option.item));
} catch(e) {
this.productItem = JSON.parse(option.item);
}
}
this.getCategory(this.shopItem.id);
this.getProduct('');
@ -721,12 +802,35 @@
if (index == 'pintuan') {
this.isPintuan = true;
// Set default group rule
if (item.productGroupBuyPrices && item.productGroupBuyPrices.length > 0) {
this.selectedGroupRule = item.productGroupBuyPrices[0];
if (this.groupId) {
// Determine best price match given targetMembers
let prices = item.productGroupBuyPrices || [];
let validPrices = prices.filter(p => p.groupCount <= this.targetMembers);
if (validPrices.length > 0) {
this.selectedGroupRule = validPrices.reduce((max, obj) => (obj.groupCount > max.groupCount ? obj : max));
} else if (prices.length > 0) {
this.selectedGroupRule = prices.reduce((prev, curr) => (prev.groupCount < curr.groupCount ? prev : curr));
} else {
this.selectedGroupRule = {};
}
if (this.isFaceToFaceGroup) {
if (this.parsedSpecs.length === 0) {
// No specs needed, jump straight to direct pay
this.submitFTFJoinPay({});
return;
}
}
} else {
this.selectedGroupRule = {};
// Normal init
if (item.productGroupBuyPrices && item.productGroupBuyPrices.length > 0) {
this.selectedGroupRule = item.productGroupBuyPrices[0];
} else {
this.selectedGroupRule = {};
}
}
this.$refs.pintuanPopup.open('bottom');
} else {
this.isPintuan = false;
@ -769,6 +873,13 @@
specChoices[spec.name] = spec.selected;
}
let packageFee = parseFloat(this.currentItem.lunchBox || 0);
if (this.groupId && this.isFaceToFaceGroup) {
// Direct face-to-face pay path
this.submitFTFJoinPay(specChoices);
return;
}
// Pack data for checkout
let goData = {
item: this.currentItem,
@ -786,6 +897,47 @@
});
this.$refs.pintuanPopup.close();
},
submitFTFJoinPay(specChoices) {
let items = [{
productId: this.currentItem.id,
specs: JSON.stringify(specChoices || {}),
price: parseFloat(this.selectedGroupRule && this.selectedGroupRule.groupPrice ? this.selectedGroupRule.groupPrice : 0),
quantity: 1
}];
let packageFee = parseFloat(this.currentItem.lunchBox || 0);
let payload = {
userId: uni.getStorageSync('id') || 'test-user123',
shopId: this.shopItem.id,
deliveryType: 1,
packageFee: packageFee,
remark: '',
items: items,
receiverName: '',
receiverPhone: '',
receiverAddress: '',
shopName: this.shopItem.shopName,
shopPhone: this.shopItem.shopPhone || '',
shopAddress: this.shopItem.shopAddress || '',
groupId: this.groupId
};
uni.showLoading({ title: '创建订单中...' });
this.tui.request("/mall/order/create", "POST", payload, false, false).then(res => {
uni.hideLoading();
if (res.success && res.result) {
this.currentOrderId = res.result.id;
this.backendTotalAmount = res.result.totalAmount;
this.$refs.payPopup.open('bottom');
if (this.$refs.pintuanPopup) this.$refs.pintuanPopup.close();
} else {
uni.showToast({ title: res.message || '下单失败', icon: 'none' });
}
}).catch(err => {
uni.hideLoading();
});
},
addToCart(item, specs) {
let specStr = specs ? JSON.stringify(specs) : '';
let cartId = item.id + '_' + specStr;
@ -869,6 +1021,73 @@
})
}
},
getGroupPrice(item) {
if (!this.groupId) {
return this.$options.filters.slicePrice(item.productGroupBuyPrices);
}
let target = this.targetMembers;
let prices = item.productGroupBuyPrices || [];
if (prices.length === 0) return '0.00';
let validPrices = prices.filter(p => p.groupCount <= target);
if (validPrices.length === 0) {
let minRule = prices.reduce((prev, curr) => (prev.groupCount < curr.groupCount ? prev : curr));
return parseFloat(minRule.groupPrice).toFixed(2);
}
let bestRule = validPrices.reduce((max, obj) => (obj.groupCount > max.groupCount ? obj : max));
return parseFloat(bestRule.groupPrice).toFixed(2);
},
wxPayment() {
let that = this;
if (!this.currentOrderId || !this.backendTotalAmount) return;
let amountInCents = Math.round(this.backendTotalAmount * 100);
this.tui.request("/api/wechat/pay/unified-order", "POST", {
openid: uni.getStorageSync('miniProgramOpenid') || 'test-openid',
amount: amountInCents,
description: '拼团参与订单',
outTradeNo: this.currentOrderId
}, false, false).then((res) => {
if (res.code == 200) {
uni.requestPayment({
provider: 'wxpay',
timeStamp: res.timeStamp,
nonceStr: res.nonceStr,
package: res.package,
signType: res.signType,
paySign: res.paySign,
success: function(res2) {
that.$refs.payPopup.close();
uni.showToast({ title: '支付成功', icon: 'success' });
setTimeout(() => { that.$refs.joinSuccessPopup.open('bottom'); }, 1500);
},
fail: function(err) {
that.tui.toast("支付失败或取消");
}
});
} else {
//
if (res.code == 404 || res.code == 500 || res.code == 400 || !res.code) {
that.tui.request(
`/hiver/order/payMallOrderSuccess?orderId=${that.currentOrderId}&workerId=`,
"POST", {}, false, false).then(res2 => {
that.$refs.payPopup.close();
uni.showToast({ title: '支付成功(模拟)', icon: 'none' });
setTimeout(() => { that.$refs.joinSuccessPopup.open('bottom'); }, 1500);
});
} else {
that.tui.toast(res.message);
}
}
})
},
onJoinSuccessPopupChange(e) {
if (!e.show) {
uni.redirectTo({
url: '/package1/order/pendGroup?groupId=' + this.groupId
});
}
},
back() {
uni.navigateBack()
}

Loading…
Cancel
Save