拼团问题修复,增加套餐功能

This commit is contained in:
2025-12-19 15:18:33 +08:00
parent 9ea8a2a7ab
commit cd199c980f
15 changed files with 2517 additions and 682 deletions

View File

@@ -0,0 +1,877 @@
<template>
<view class="color-333 u-font-28 min-page bg-f7" v-if="item.id">
<view class="relative">
<up-swiper height="428rpx" :list="item.images" @click="prveImg"></up-swiper>
<view class="share-box">
分享
<button class="share" open-type="share">分享</button>
</view>
</view>
<view class="sku">
<view class="u-flex u-col-center">
<text class="price">¥{{item.price}}</text>
<text class="old-price">¥{{item.originPrice}}</text>
</view>
<view>
<view class="u-m-t-16 text" v-if="item.limitBuyNum"> 限购{{item.limitBuyNum}} </view>
<view class="text u-m-t-10">已售{{item.saleNum||0}}</view>
</view>
</view>
<view class="goods">
<view class="goods-name">{{item.packageName}}</view>
<view class="u-m-t-20 color-666">
{{item.description}}
</view>
</view>
<view class="bg-f7" style="height: 32rpx"></view>
<view class="desc">
<view class="u-flex">
<view class="color-666 no-wrap" style="min-width: 180rpx;">可核销门店</view>
<view class="">{{item.shopName}}</view>
</view>
<view class="u-flex u-m-t-16 u-col-baseline">
<view class="color-666 no-wrap" style="min-width: 180rpx;">门店地址</view>
<view class="">{{item.shopAddress}}</view>
</view>
</view>
<template v-if="flase">
<view class="bg-f7" style="height: 32rpx"></view>
<view class="groups">
<view class="color-000 u-m-b-28 u-font-32 font-700">立即拼团</view>
<view class="item u-flex" v-for="(item,index) in item.gbOrderList" :key="index">
<up-avatar size="76rpx" :src="item.avatar"></up-avatar>
<view class="u-flex u-flex-1 u-p-l-22 u-col-center u-row-between">
<view>
<view class="color-000 u-line-1" style="max-width: 180rpx;">{{item.nickName}}</view>
<view class="main-color u-m-t-2">{{returnNeedPerpole(item)}}人拼成</view>
</view>
<view class="u-m-t-22">
<text class="color-666">剩余</text>
<text class="main-color">{{getRemainingHMS(item)}}</text>
</view>
<view class="btn" @click="fastBuy(item)">快速拼成</view>
</view>
</view>
</view>
</template>
<view class="bg-f7" style="height: 24rpx"></view>
<view class="goods-group">
<view class="u-flex u-row-between">
<view class="name">套餐商品</view>
<view class="u-flex color-666" @click="showGroup=!showGroup" style="align-items: baseline;">
<text class="u-m-r-18">{{showGroup?'收起':'展开'}}</text>
<view class="guodu" :class="{rotate:!showGroup}">
<up-icon name="arrow-down" bold></up-icon>
</view>
</view>
</view>
<view class="u-m-t-36" v-if="showGroup">
<view v-for="(item,index) in item.packageContent" :key="index">
<view class="">
<text>{{item.name}}</text>
<text class="u-m-l-30">{{item.packageProducts.length}}{{item.num}}</text>
</view>
<view class="u-m-t-48">
<view class="u-flex u-m-t-32 u-row-between" v-for="(goods,goodsIndex) in item.packageProducts"
:key="goodsIndex">
<text>{{goods.name}}</text>
<view class="u-flex text-right">
<text class="color-666 u-m-r-42">{{goods.num}}</text>
<view style="min-width: 110rpx;">¥{{goods.price}}</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="desc">
<view class="u-flex u-row-between">
<view class="name">分享说明</view>
<view class="u-flex color-666" @click="showDesc=!showDesc" style="align-items: baseline;">
<text class="u-m-r-18">{{showDesc?'收起':'展开'}}</text>
<view class="guodu" :class="{rotate:!showDesc}">
<up-icon name="arrow-down" bold></up-icon>
</view>
</view>
</view>
<template v-if="showDesc">
<view class="u-m-t-26 text-center table">
<view class="u-flex header color-666">
<view class="u-flex-1 u-p-t-32 u-p-b-32">分享人数</view>
<view class="u-flex-1 u-p-t-32 u-p-b-32">购买价格</view>
</view>
<view class="u-flex row" v-for="(step,index) in item.tieredDiscount" :key="index">
<view class="u-flex-1 u-p-t-32 u-p-b-32">{{step.peopleNum}}</view>
<view class="u-flex-1 u-p-t-32 u-p-b-32">¥{{step.price}}</view>
</view>
</view>
<view class="u-m-t-26" >
<view>
分享期限小时4
</view>
<view class="u-m-t-10">
规定期限内的助力才会被计入
</view>
<view class="u-m-t-40">
如何才是分享成功被分享人只需要点击助力提示助力成功后即可
</view>
</view>
</template>
</view>
<view class="desc">
<view class="u-flex u-row-between">
<view class="name">使用说明</view>
<view class="u-flex color-666" @click="useDescShow=!useDescShow" style="align-items: baseline;">
<text class="u-m-r-18">{{useDescShow?'收起':'展开'}}</text>
<view class="guodu" :class="{rotate:!useDescShow}">
<up-icon name="arrow-down" bold></up-icon>
</view>
</view>
</view>
<template v-if="useDescShow">
<view class="u-m-t-16 color-666">
<view>
1可用时间段04:00 - 16:07
</view>
<view>
2其他使用说明这里是其他使用说明
</view>
</view>
</template>
</view>
<view class="goods-detail" v-if="item.goodsCategory!='优惠券'">
<view class="u-flex u-row-center">
<view class="title">商品详情</view>
</view>
<view class="u-m-t-32">
<image class="w-full" v-for="(item,index) in item.imgs" :key="index" mode="widthFix" :src="item">
</image>
</view>
</view>
<view style="height: 140px"></view>
<view class="fixed-bottom ">
<view v-if="isCanExchange" class="btn" @click="exchangeClick">
{{returnBtmText}}
</view>
<view class="btn gray u-m-t-32" @click="createOrder">
立即助力
</view>
</view>
<!-- 需要支付的弹窗 -->
<up-popup :show="popupData.show" mode="bottom" closeOnClickOverlay @close="popupData.show = false">
<view class="popup-content">
<view class="popup-content-top u-flex u-row-right">
<up-icon name="close" bold="" @click="popupData.show = false"></up-icon>
</view>
<view class="goods-info">
<view class="u-flex">
<image class="cover" :src="coverImgs[0]"></image>
<view class="u-flex u-flex-1 u-row-between u-p-l-16 u-col-center">
<view>
<view class="u-font-32 font-bold">{{item.packageName}}</view>
<view class="u-m-t-12 color-666 u-line-2">{{item.otherDesc}}</view>
</view>
<view>
<view class="price">¥{{item.price}}</view>
<view class="old-price">¥{{item.originPrice}}</view>
<view class="limitBuyNum" v-if="item.limitBuyNum"> 限购{{item.limitBuyNum}} </view>
</view>
</view>
</view>
</view>
<view class="bottom u-flex u-row-between u-col-center">
<view class="u-flex u-col-baseline">
<text class="color-666">合计</text>
<text class=" price">{{totalPrice}}</text>
</view>
<view class="u-flex">
<up-icon name="minus-circle" size="20" color="#666" @click="changeNumber('-')"></up-icon>
<text class="u-m-l-20 u-m-r-20">{{number}}</text>
<up-icon name="plus-circle-fill" size="20" color="#ED5A2E" @click="changeNumber('+')"></up-icon>
</view>
</view>
<view class="u-m-t-42 u-flex u-row-center">
<view class="btn" @click="payExchange">去支付</view>
</view>
</view>
</up-popup>
<!-- 兑换确认弹窗end -->
</view>
</template>
<script setup>
import {
Storelogin
} from '@/stores/user.js';
const storelogin = Storelogin();
import {
computed,
reactive,
watch
} from "vue";
import dayjs from "dayjs";
import {
wxShare
} from '@/utils/share.js'
import {
getOpenId
} from '@/utils/uniapp.js'
import modal from "@/groupBuying/components/modal.vue";
import * as Api from '@/common/api/market/package.js'
import {
pay
} from '@/utils/pay.js'
const imgs = {
bg: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/2/9fd6a3ad2b384f6cb4e88ed6b77bd334.png",
};
const number = ref(1)
const showGroup = ref(true)
const showDesc = ref(true)
const useDescShow=ref(true)
import {
BigNumber
} from "bignumber.js";
const totalPrice = computed(() => {
if (!item.price) {
return 0;
}
return BigNumber(number.value).times(item.price).toNumber()
})
function changeNumber(step) {
if (step === '-') {
if (number.value == 1) {
return
}
number.value--
return
}
if (step === '+') {
if (item.limitBuyNum == -10086) {
number.value++
return
}
if (number.value >= item.limitBuyNum) {
return uni.showToast({
title: '最多可购买' + item.limitBuyNum + '份',
icon: 'none'
})
}
number.value++
return
}
}
const modalData = reactive({
show: false,
});
function prveImg(index) {
uni.previewImage({
urls: coverImgs.value,
current: index
})
}
const popupData = reactive({
show: false,
item: null
});
function exchangeClick() {
popupData.show = true
}
function fastBuy(item) {
popupData.item = item;
popupData.show = true
}
watch(() => popupData.show, (newval) => {
if (!newval) {
popupData.item = null
}
})
function dingyue() {
return new Promise((revlove, reject) => {
uni.requestSubscribeMessage({
tmplIds: ['JGPAGmqcPEgWB6mvAl0SC5cMqr5H5Qjcim8JCpHAZd0',
'F4OyUhe_ZQ9BR731jlkaN2QXAUaA3HBZuUeVPfraSz0'
],
success(res) {},
complete() {
revlove()
}
})
})
}
async function createOrder(){
Api.order({
packageId:item.id
}).then(res=>{
if(res){
uni.navigateTo({
url:'/userPackage/order/detail?orderId='+res
})
}else{
uni.showToast({
title:'发起助力失败',
icon:'none'
})
}
})
}
async function payExchange() {
uni.setStorageSync('group_buying_order', {
...item,
number: number.value,
groupOrderNo: popupData.item ? popupData.item.groupOrderNo : '',
})
uni.navigateTo({
url: '/groupBuying/confirm-order/confirm-order'
})
return
await dingyue();
uni.showLoading({
title: '支付中……'
})
const openId = await getOpenId()
uni.hideLoading()
if (openId) {
Api.exchange({
paramId: item.id,
shopId: item.shopId,
number: number.value,
groupOrderNo: popupData.item ? popupData.item.groupOrderNo : '',
openId
}).then(orderRes => {
popupData.show = false;
pay(orderRes.payInfo).then(res => {
console.log(res)
if (res) {
uni.redirectTo({
url: '/groupBuying/success/index?detailId=' + orderRes.record
.id
})
} else {
uni.showToast({
title: '开团失败',
icon: 'none'
})
}
})
})
} else {
uni.showToast({
title: '鉴权失败,兑换失败',
icon: 'none'
})
}
}
const item = reactive({
goodsDescription: []
})
const isCanExchange = computed(() => {
if (item.quantity <= 0) {
return false
}
if (item.limitQuota && item.boughtCount >= item.limitQuota) {
return false
}
return true
})
const returnBtmText = computed(() => {
if (isCanExchange.value) {
return '立即购买'
}
if (pointsUser.pointBalance < item.requiredPoints) {
const num = item.requiredPoints - pointsUser.pointBalance
return `积分不足,还差${num}积分`
}
if (item.quantity <= 0) {
return `库存不足`
}
if (item.limitQuota && item.boughtCount >= item.limitQuota) {
return `单人兑换已达上限`
}
})
const query = reactive({
shopId: '',
id: '',
groupOrderNo: ''
})
const coverImgs = ref([])
async function init(opt) {
// 获取小程序进入场景和参数
const launchOptions = uni.getLaunchOptionsSync();
console.log(launchOptions);
// 获取链接上的参数
const launchOptionsQuery = launchOptions.query;
console.log('launchOptionsQuery', launchOptionsQuery);
Object.assign(query, launchOptionsQuery)
console.log(opt)
Object.assign(query, opt)
console.log(query)
await storelogin.actionslogin()
getDetail()
}
function getDetail() {
Api.getPackageDetail(query.id).then(res => {
Object.assign(item, res)
console.log(item)
coverImgs.value = res.images
uni.cache.set('shopId', item.shopId)
})
}
/**
* 计算剩余时间差(毫秒)
* @param {Object} item - 包含groupEndTime的订单/拼团对象
* @returns {number} 剩余时间(毫秒)
*/
function returnRemainingTime(item) {
if (!item?.groupEndTime) return 0; // 容错无结束时间则返回0
return dayjs(item.groupEndTime).valueOf() - dayjs().valueOf();
}
/**
* 将毫秒差格式化为 HH:MM:SS最多72小时
* @param {number} ms - 时间差(毫秒)
* @returns {string} 格式化后的时分秒(如 09:09:09、72:00:00、00:00:00
*/
function formatTimeToHMS(ms) {
// 边界1已过期/无剩余时间 → 显示00:00:00
if (ms <= 0) return '00:00:00';
// 边界2超过72小时 → 按72小时算72*60*60*1000 = 259200000毫秒
const maxMs = 72 * 60 * 60 * 1000;
const validMs = Math.min(ms, maxMs);
// 转换为总秒数(取整,避免小数)
const totalSeconds = Math.floor(validMs / 1000);
// 拆解小时、分钟、秒
const hours = Math.floor(totalSeconds / 3600);
const remainingSeconds = totalSeconds % 3600;
const minutes = Math.floor(remainingSeconds / 60);
const seconds = remainingSeconds % 60;
// 补零(确保两位数,如 9 → 09
const pad = (num) => String(num).padStart(2, '0');
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
}
let timer = null
let nowTime = ref(Date.now())
timer = setInterval(() => {
nowTime.value = Date.now()
}, 1000)
// 组合使用:获取格式化后的剩余时间
function getRemainingHMS(item) {
nowTime.value
const ms = returnRemainingTime(item);
return formatTimeToHMS(ms);
}
function returnNeedPerpole(data) {
return data.groupPeopleNum - data.currentPeopleNum
}
onLoad(init)
// #ifdef MP-WEIXIN
uni.showShareMenu()
// #endif
onShareAppMessage(() => {
const query = `id=${item.id}&shopId=${item.shopId}`
return wxShare({
title: item.wareName,
imageUrl: coverImgs.value[0],
path: '/groupBuying/goodsDetail/goodsDetail' + '?' + query,
query,
})
})
</script>
<style lang="scss" scoped>
$topHeight: 350rpx;
.top-img {
width: 750rpx;
height: $topHeight;
}
.top {
margin: 14rpx 18rpx;
background-size: cover;
height: $topHeight;
box-sizing: border-box;
padding-left: 70rpx;
padding-top: 95rpx;
.name {
color: #000000;
font-size: 36rpx;
font-weight: 700;
}
.info {
color: #333333;
font-size: 48rpx;
font-weight: 700;
margin-top: 62rpx;
}
}
.sku {
display: flex;
justify-content: space-between;
padding: 20rpx 36rpx;
align-items: center;
background: linear-gradient(90deg, #ff4a63 0%, #fd1f48 100%);
.price {
color: #fff;
font-weight: 700;
font-size: 40rpx;
}
.old-price {
margin-left: 16rpx;
color: #E7E7E7;
opacity: .85;
font-weight: 700;
text-decoration: line-through;
}
.text {
color: #fff;
font-size: 28rpx;
}
}
.goods {
padding: 20rpx 28rpx;
background: #fff;
.goods-name {
font-size: 32rpx;
font-weight: 700;
color: #333;
}
}
.desc {
padding: 32rpx 28rpx;
background-color: #fff;
}
.goods-detail {
padding: 32rpx;
.title {
position: relative;
padding: 0 22rpx;
&::before {
content: "";
display: block;
position: absolute;
right: 100%;
width: 70rpx;
height: 2rpx;
top: 50%;
transform: translateY(-50%);
background: linear-gradient(90deg, #f7f8f9 0%, #c9cbcc 100%);
}
&::after {
left: 100%;
content: "";
position: absolute;
top: 50%;
transform: translateY(-50%);
display: block;
width: 70rpx;
height: 2rpx;
background: linear-gradient(90deg, #c9cbcc 0%, #f7f8f9 100%);
}
}
}
.fixed-bottom {
position: fixed;
left: 98rpx;
right: 98rpx;
padding-bottom: 30px;
padding-top: 32rpx;
bottom: 0;
z-index: 10;
.btn {
padding: 22rpx;
border-radius: 200rpx;
font-size: 32rpx;
color: #fff;
width: 556rpx;
text-align: center;
background-color: #E8AD7B;
border: 1px solid transparent;
&.gray {
background: #fff;
color: #E8AD7B;
border-color: #E8AD7B;
}
}
}
.waring {
background-color: rgba(255, 204, 0, 0.09);
padding: 32rpx 24rpx;
color: #ff8d28;
}
.popup-content {
font-size: 28rpx;
min-height: 300px;
.popup-content-top {
padding: 32rpx 28rpx;
border-bottom: 1px solid #ededed;
}
.goods-info {
padding: 32rpx 28rpx;
border-bottom: 1px solid #ededed;
.cover {
width: 184rpx;
height: 184rpx;
border-radius: 16rpx;
background: #d9d9d9;
&.bg-fff {
background-color: #fff;
}
}
.price {
font-size: 32rpx;
font-weight: 700;
color: #ed5a2e;
line-height: 46rpx;
}
.old-price {
font-size: 32rpx;
color: #999;
text-decoration-line: line-through;
line-height: 48rpx;
}
.limitBuyNum {
color: #666;
line-height: 42rpx;
}
}
.bottom {
padding: 20rpx;
border-bottom: 1px solid #ededed;
.price {
color: #ed5a2e;
font-size: 32rpx;
font-weight: 700;
}
}
.btn {
display: flex;
padding: 22rpx 214rpx;
align-items: flex-start;
gap: 20rpx;
border-radius: 66rpx;
background: #e8ad7b;
font-size: 32rpx;
color: #fff;
font-size: 700;
}
}
.w-full {
width: 100%;
}
.groups {
padding: 28rpx 22rpx;
background-color: #fff;
.item {
padding: 28rpx 0;
border-bottom: 2rpx solid #EDEDED;
&:last-child {
border-bottom: none;
}
.main-color {
color: #ed5a2e;
}
.btn {
padding: 8rpx 26rpx;
border-radius: 36rpx;
background: #E8AD7B;
font-weight: 700;
color: #fff;
}
}
}
.share-box {
top: 0;
position: absolute;
right: 0;
padding: 4rpx 30rpx;
border-radius: 0 0 0 24rpx;
color: #ed5a2e;
font-weight: 700;
background: #FFF;
overflow: hidden;
.share {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
opacity: 0;
}
}
.goods-group {
padding: 32rpx 46rpx;
background-color: #fff;
.name {
font-weight: 700;
font-size: 32rpx;
}
.rotate {
transform: rotate(-90deg);
}
}
.desc {
padding: 32rpx 46rpx;
background-color: #fff;
margin-top: 32rpx;
.name {
font-weight: 700;
font-size: 32rpx;
}
.table {
border: 2rpx solid #EDEDED;
border-radius: 8rpx;
margin: 0 52rpx;
.header {
background: #f8f8f88f;
}
.row {
border-top: 2rpx solid #EDEDED;
&:first-child {
border-top: none;
}
}
}
.rotate {
transform: rotate(-90deg);
}
}
.guodu {
transition: all .3s;
}
</style>