Commit dabb76e6 authored by 王炽's avatar 王炽

Merge branch 'feihesanqi_20251014' of...

Merge branch 'feihesanqi_20251014' of http://gitlab2.dui88.com/fh/20250528_FHQ1 into feihesanqi_20251014
parents 4812b0cc 64904fb4
......@@ -12,6 +12,24 @@ const {
export const fetchGoodsDetail = (data) => api.get('/c/goods/detail', data);
/**
* 获取秒杀商品详情
* @param {Object} data - 请求参数
* @param {string} data.id - 商品ID (必须)
* @param {string} [data.phone] - 充值号码 (可选)
* @param {string} [data.buyNum=1] - 下单数量 (可选,默认1)
* @param {string} [data.storeId] - 门店ID (可选)
* @param {string} [data.amount] - 充值面额 (可选)
* @param {string} [data.channel] - 渠道 (可选)
* @param {string} [data.addressId] - 地址ID (可选)
* @param {string} data.appGoodsId - 应用商品ID (必须)
* @param {string} data.sessionKey - 会话密钥 (必须)
* @returns {Promise} API响应
* @description 获取秒杀商品详情信息
*/
export const fetchSeckillDetail = (data) => api.get('/c/seckill/detail', data);
/**
......@@ -51,6 +69,23 @@ export const fetchGoodsPrice = (data) => api.post('/c/goods/price', data);
export const fetchTradeCredits = (data) => api.post('/c/trade/credits', data);
/**
* 秒杀下单
* @param {Object} data - 请求参数
* @param {string} data.id - 商品ID (必须)
* @param {string} [data.phone] - 充值号码 (可选)
* @param {string} [data.buyNum=1] - 下单数量 (可选,默认1)
* @param {string} [data.storeId] - 门店ID (可选)
* @param {string} [data.amount] - 充值面额 (可选)
* @param {string} [data.channel] - 渠道 (可选)
* @param {string} [data.addressId] - 地址ID (可选)
* @param {string} data.appGoodsId - 应用商品ID (必须)
* @param {string} data.sessionKey - 会话密钥 (必须)
* @returns {Promise} API响应
* @description 秒杀下单,不需要调用价格计算接口
*/
export const fetchSeckillTakeOrder = (data) => api.post('/c/seckill/takeOrder', data);
......@@ -243,6 +243,58 @@ const getGoodsListClass = () => {
return '';
};
// 智能定位场次索引
const getTargetSessionIndex = (sessions) => {
if (!sessions || sessions.length === 0) return 0;
// 1. 有正在秒杀的就定位到正在秒杀的场次
const ongoingSessions = sessions.filter(session => session.status === 'ongoing');
if (ongoingSessions.length > 0) {
// 如果有多个正在秒杀的场次,选择开始时间最早的
const earliestOngoingSession = ongoingSessions.reduce((earliest, current) => {
const getStartTimeFromTags = (session) => {
const timeTag = session.timeTags.find(tag => tag.includes('开始') && /^\d{2}:\d{2}开始$/.test(tag));
if (timeTag) {
const timeStr = timeTag.replace('开始', '');
const [hours, minutes] = timeStr.split(':').map(Number);
return hours * 60 + minutes;
}
return 0;
};
return getStartTimeFromTags(current) < getStartTimeFromTags(earliest) ? current : earliest;
});
return sessions.findIndex(session => session.id === earliestOngoingSession.id);
}
// 2. 只有已结束和未开始时定位到即将开始的场次
const upcomingSessions = sessions.filter(session => session.status === 'upcoming');
if (upcomingSessions.length > 0) {
// 选择开始时间最早的即将开始的场次
const earliestUpcomingSession = upcomingSessions.reduce((earliest, current) => {
const getStartTimeFromTags = (session) => {
const timeTag = session.timeTags.find(tag => tag.includes('开始') && /^\d{2}:\d{2}开始$/.test(tag));
if (timeTag) {
const timeStr = timeTag.replace('开始', '');
const [hours, minutes] = timeStr.split(':').map(Number);
return hours * 60 + minutes;
}
return 0;
};
return getStartTimeFromTags(current) < getStartTimeFromTags(earliest) ? current : earliest;
});
return sessions.findIndex(session => session.id === earliestUpcomingSession.id);
}
// 3. 全部结束定位到最后一个场次
const allEnded = sessions.every(session => session.status === 'ended');
if (allEnded) {
return sessions.length - 1;
}
// 4. 所有场次未开始时定位到第一个场次
return 0;
};
// 开始倒计时
const startCountdown = (sessionId, initialSeconds) => {
if (countdownTimers.value[sessionId]) {
......@@ -254,7 +306,8 @@ const startCountdown = (sessionId, initialSeconds) => {
seconds--;
if (seconds <= 0) {
clearInterval(countdownTimers.value[sessionId]);
// 倒计时结束,可以触发相应逻辑
// 倒计时结束,自动切换到下一场
handleCountdownEnd(sessionId);
}
// 更新对应场次的倒计时数据
const session = creditsSaleData.value.sessions.find(s => s.id === sessionId);
......@@ -264,11 +317,66 @@ const startCountdown = (sessionId, initialSeconds) => {
}, 1000);
};
// 处理倒计时结束
const handleCountdownEnd = (endedSessionId) => {
const sessions = creditsSaleData.value.sessions;
const currentIndex = sessions.findIndex(s => s.id === endedSessionId);
const endedSession = sessions[currentIndex];
// 如果当前场次是"即将开始"状态,转换为"正在秒杀"
if (endedSession && endedSession.status === 'upcoming') {
// 更新场次状态为正在秒杀
endedSession.status = 'ongoing';
// 重新计算结束时间倒计时
const now = new Date();
const endTime = new Date(endedSession.endTime);
const remainingMs = endTime.getTime() - now.getTime();
if (remainingMs > 0) {
const hours = Math.floor(remainingMs / (1000 * 60 * 60));
const minutes = Math.floor((remainingMs % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((remainingMs % (1000 * 60)) / 1000);
const totalSeconds = hours * 3600 + minutes * 60 + seconds;
// 更新倒计时显示
endedSession.countdown = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// 重新启动倒计时
if (totalSeconds > 0) {
startCountdown(endedSessionId, totalSeconds);
}
console.log('场次开始,状态转换为正在秒杀:', endedSession);
}
} else if (endedSession && endedSession.status === 'ongoing') {
// 正在秒杀场次结束,标记为已结束
endedSession.status = 'ended';
// 如果当前场次不是最后一场,切换到下一场
if (currentIndex < sessions.length - 1) {
const nextSession = sessions[currentIndex + 1];
// 检查下一场是否已经开始或即将开始
if (nextSession.status === 'ongoing' || nextSession.status === 'upcoming') {
currentSessionIndex.value = currentIndex + 1;
console.log('自动切换到下一场:', nextSession);
}
}
}
};
// 初始化倒计时
const initCountdowns = () => {
if (creditsSaleData.value.sessions && Array.isArray(creditsSaleData.value.sessions)) {
// 检查是否全部结束
const allEnded = creditsSaleData.value.sessions.every(session => session.status === 'ended');
if (allEnded) {
return; // 全部结束,不需要倒计时
}
// 其他情况都需要倒计时
creditsSaleData.value.sessions.forEach(session => {
if (session.status === 'ongoing') {
if (session.status === 'ongoing' || session.status === 'upcoming') {
// 将倒计时字符串转换为秒数
const timeParts = session.countdown.split(':');
const hours = parseInt(timeParts[0]) || 0;
......@@ -293,6 +401,9 @@ const mapSeckillDataToCreditsSale = (seckillData) => {
return;
}
// 保存活动ID
creditsSaleData.value.activityId = seckillData.data.id;
console.log('开始处理接口数据,configs长度:', seckillData.data.configs.length);
const sessions = seckillData.data.configs.map((config, index) => {
......@@ -364,7 +475,10 @@ const mapSeckillDataToCreditsSale = (seckillData) => {
status,
countdown,
timeTags,
goods
goods,
sessionKey: config.sessionKey,
startTime: config.start,
endTime: config.end
};
});
......@@ -386,33 +500,9 @@ const mapSeckillDataToCreditsSale = (seckillData) => {
creditsSaleData.value.sessions = sessions;
// 自动定位到正在秒杀的场次
const ongoingSessions = sessions.filter(session => session.status === 'ongoing');
if (ongoingSessions.length > 0) {
// 如果有多个正在秒杀的场次,选择开始时间最早的
const earliestOngoingSession = ongoingSessions.reduce((earliest, current) => {
const getStartTimeFromTags = (session) => {
const timeTag = session.timeTags.find(tag => tag.includes('开始') && /^\d{2}:\d{2}开始$/.test(tag));
if (timeTag) {
const timeStr = timeTag.replace('开始', '');
const [hours, minutes] = timeStr.split(':').map(Number);
return hours * 60 + minutes;
}
return 0;
};
return getStartTimeFromTags(current) < getStartTimeFromTags(earliest) ? current : earliest;
});
// 找到最早场次的索引
const targetIndex = sessions.findIndex(session => session.id === earliestOngoingSession.id);
if (targetIndex !== -1) {
currentSessionIndex.value = targetIndex;
}
} else {
// 没有正在秒杀的场次,定位到第一个
currentSessionIndex.value = 0;
}
// 智能定位场次逻辑
const targetIndex = getTargetSessionIndex(sessions);
currentSessionIndex.value = targetIndex;
console.log('映射后的秒杀数据:', creditsSaleData.value);
console.log('当前选中场次索引:', currentSessionIndex.value);
......@@ -421,7 +511,10 @@ const mapSeckillDataToCreditsSale = (seckillData) => {
// 处理积分抢购点击事件
const handleCreditsSaleClick = (good) => {
console.log('点击抢购商品:', good);
emit('credits-sale-click', good);
// 获取当前活动ID和场次Key
const activityId = creditsSaleData.value.activityId;
const sessionKey = creditsSaleData.value.sessions[currentSessionIndex.value]?.sessionKey;
emit('credits-sale-click', { good, activityId, sessionKey });
};
// 创建防连点的点击处理函数
......
......@@ -22,13 +22,17 @@
<text class="points-value">{{ goodsData.points }}</text>
<text class="points-unit">{{ goodsData.creditsTypeName || '积分' }}</text>
</view>
<text class="exchange-count">已兑换{{ formatCount(goodsData.exchangeCount) }}</text>
<text class="exchange-count">已兑换{{ formatCount(goodsData.saleCount) }}</text>
</view>
<!-- 会员标签 -->
<view class="member-tags" v-if="goodsData.memberLevel || goodsData.limit">
<text class="member-level" v-if="goodsData.memberLevel">{{ goodsData.memberLevel }}</text>
<text class="purchase-limit" v-if="goodsData.limit">每人限{{ goodsData.limit }}</text>
<view class="member-tags" v-if="goodsData.vipLimit && goodsData.vipLimit.length > 0">
<text class="member-level" v-for="(level, index) in goodsData.vipLimit" :key="index">{{ level }}</text>
</view>
<!-- 购买限制 -->
<view class="purchase-limit-section" v-if="goodsData.goodsLimit">
<text class="purchase-limit">每人限{{ goodsData.goodsLimit }}</text>
</view>
<!-- 优惠券名称 -->
......@@ -69,7 +73,7 @@
<view class="product-details">
<text class="product-points">{{ goodsData.points }}{{ goodsData.creditsTypeName || '积分'
}}</text>
<text class="product-stock">库存 {{ formatCount(goodsData.exchangeCount) }}</text>
<text class="product-stock">库存 {{ formatCount(goodsData.saleCount) }}</text>
</view>
</view>
......@@ -85,13 +89,20 @@
</view>
<!-- 数量选择 -->
<view class="quantity-section">
<text class="quantity-label">选择数量 <text class="limit-text">(限购{{ goodsData.limit }}件)</text></text>
<view class="quantity-section" v-if="!isSeckill">
<text class="quantity-label">选择数量 <text class="limit-text" v-if="goodsData.goodsLimit">(限购{{ goodsData.goodsLimit }}件)</text></text>
<view class="quantity-selector">
<view class="quantity-btn " @click="decreaseQuantity" :disabled="quantity <= 1">-</view>
<text class="quantity-value">{{ quantity }}</text>
<view class="quantity-btn " @click="increaseQuantity"
:disabled="quantity >= parseInt(goodsData.limit)">+</view>
:disabled="goodsData.goodsLimit && quantity >= parseInt(goodsData.goodsLimit)">+</view>
</view>
</view>
<!-- 秒杀商品数量显示(固定为1) -->
<view class="quantity-section" v-else>
<text class="quantity-label">购买数量</text>
<view class="quantity-display">
<text class="quantity-value">1</text>
</view>
</view>
......@@ -120,7 +131,7 @@
</template>
<script>
import { fetchGoodsDetail, fetchGoodsPrice, fetchTradeCredits } from '@/api/goods.js';
import { fetchGoodsDetail, fetchSeckillDetail, fetchGoodsPrice, fetchTradeCredits, fetchSeckillTakeOrder } from '@/api/goods.js';
import { useUserStore } from '@/stores/user';
import { jump, JumpType } from '../../utils';
......@@ -131,8 +142,11 @@ export default {
id: '',
points: 0,
exchangeCount: 0,
saleCount: 0, // 已兑换数量
memberLevel: '',
vipLimit: [], // 会员限制数组
limit: '',
goodsLimit: false, // 商品购买限制
name: '',
couponName: '',
expireDate: '',
......@@ -183,6 +197,13 @@ export default {
cfgStatus: {
isRegister: true, // 登录状态
showDetail: false // 是否显示详情
},
// 兑换类型
isSeckill: false, // 是否为秒杀兑换
seckillParams: {
activityId: '', // 活动ID
sessionKey: '', // 会话密钥
appGoodsId: '' // 应用商品ID
}
}
},
......@@ -208,17 +229,18 @@ export default {
}
}
// 3. 用户等级不足
if (this.goodsData.memberLevel && this.userStore && this.userStore.userInfo) {
// 3. 用户等级不足(检查vipLimit数组)
if (this.goodsData.vipLimit && this.goodsData.vipLimit.length > 0 && this.userStore && this.userStore.userInfo) {
const userLevel = this.userStore.userInfo.grade || 1;
const requiredLevel = this.getRequiredLevel(this.goodsData.memberLevel);
if (userLevel < requiredLevel) {
const userLevelName = this.getUserLevelName(userLevel);
// 检查用户等级是否在vipLimit中
if (!this.goodsData.vipLimit.includes(userLevelName)) {
return false;
}
}
// 4. 用户达到兑换上限
if (this.goodsData.limit && this.userBuyLimit) {
// 4. 用户达到兑换上限(使用goodsLimit)
if (this.goodsData.goodsLimit && this.userBuyLimit) {
return false;
}
......@@ -250,17 +272,18 @@ export default {
}
}
// 3. 用户等级不足
if (this.goodsData.memberLevel && this.userStore && this.userStore.userInfo) {
// 3. 用户等级不足(检查vipLimit数组)
if (this.goodsData.vipLimit && this.goodsData.vipLimit.length > 0 && this.userStore && this.userStore.userInfo) {
const userLevel = this.userStore.userInfo.grade || 1;
const requiredLevel = this.getRequiredLevel(this.goodsData.memberLevel);
if (userLevel < requiredLevel) {
const userLevelName = this.getUserLevelName(userLevel);
// 检查用户等级是否在vipLimit中
if (!this.goodsData.vipLimit.includes(userLevelName)) {
return 'insufficientLevel';
}
}
// 4. 用户达到兑换上限
if (this.goodsData.limit && this.userBuyLimit) {
// 4. 用户达到兑换上限(使用goodsLimit)
if (this.goodsData.goodsLimit && this.userBuyLimit) {
return 'exchangeLimit';
}
......@@ -278,33 +301,71 @@ export default {
// 初始化用户状态
this.initUserStatus();
// 构建API请求参数
const apiParams = {
gid: options.gid || options.id || options.goodsId || '', // 商品ID (必须)
skuld: options.skuld || '', // 商品规格ID (可选)
buy_num: parseInt(options.buy_num) || 1, // 下单数量 (可选,默认1)
phone: options.phone || '', // 充值号码 (可选)
amount: options.amount || '', // 充值面额 (可选)
couponId: options.couponId || '', // 优惠券ID (可选)
remark: options.remark || '', // 下单备注 (可选)
addressId: options.addressId || '', // 地址ID (可选)
storeId: options.storeId || '', // 门店ID (可选)
projectId: options.projectId || '' // 活动ID (可选)
};
console.log('API请求参数:', apiParams);
if (apiParams.gid) {
this.fetchGoodsDetail(apiParams);
// 判断是否为秒杀兑换
this.isSeckill = !!(options.activityId || options.sessionKey);
if (this.isSeckill) {
// 秒杀兑换参数
this.seckillParams = {
activityId: options.activityId || '',
sessionKey: options.sessionKey || '',
appGoodsId: options.appGoodsId || options.gid || options.id || options.goodsId || ''
};
// 构建秒杀API请求参数
const seckillParams = {
id: this.seckillParams.appGoodsId,
phone: options.phone || '',
buyNum: options.buyNum || '1',
storeId: options.storeId || '',
amount: options.amount || '',
channel: options.channel || '',
addressId: options.addressId || '',
appGoodsId: this.seckillParams.appGoodsId,
sessionKey: this.seckillParams.sessionKey
};
console.log('秒杀API请求参数:', seckillParams);
if (seckillParams.id && seckillParams.appGoodsId && seckillParams.sessionKey) {
this.fetchSeckillDetail(seckillParams);
} else {
uni.showToast({
title: '秒杀参数不完整',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
}
} else {
uni.showToast({
title: '商品ID不能为空',
icon: 'none'
});
// 延迟返回上一页
setTimeout(() => {
uni.navigateBack();
}, 1500);
// 普通兑换参数
const apiParams = {
gid: options.gid || options.id || options.goodsId || '', // 商品ID (必须)
skuld: options.skuld || '', // 商品规格ID (可选)
buy_num: parseInt(options.buy_num) || 1, // 下单数量 (可选,默认1)
phone: options.phone || '', // 充值号码 (可选)
amount: options.amount || '', // 充值面额 (可选)
couponId: options.couponId || '', // 优惠券ID (可选)
remark: options.remark || '', // 下单备注 (可选)
addressId: options.addressId || '', // 地址ID (可选)
storeId: options.storeId || '', // 门店ID (可选)
projectId: options.projectId || '' // 活动ID (可选)
};
console.log('普通兑换API请求参数:', apiParams);
if (apiParams.gid) {
this.fetchGoodsDetail(apiParams);
} else {
uni.showToast({
title: '商品ID不能为空',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
}
}
},
onShow() {
......@@ -374,8 +435,11 @@ export default {
id: data.id || '',
points: parseInt(data.credits) || 0,
exchangeCount: data.stock || 0,
saleCount: data.saleCount || 0, // 已兑换数量
memberLevel: this.getMemberLevel(data.state),
vipLimit: data.vipLimit || [], // 会员限制数组
limit: data.groupCount ? data.groupCount.toString() : '1',
goodsLimit: data.goodsLimit || false, // 商品购买限制
name: data.goodsName || data.name || '',
couponName: data.goodsName || data.name || '',
expireDate: data.expireTime && data.expireTime.length > 0 ? data.expireTime[0] : '',
......@@ -430,6 +494,84 @@ export default {
}
},
// 获取秒杀商品详情
async fetchSeckillDetail(params) {
this.isLoading = true;
console.log('开始获取秒杀商品详情,请求参数:', params);
try {
const response = await fetchSeckillDetail(params);
console.log('秒杀商品详情接口返回:', response);
if (response.ok && response.data) {
const data = response.data;
// 映射API数据到组件数据(秒杀商品数据结构可能与普通商品不同)
this.goodsData = {
id: data.id || '',
points: parseInt(data.credits) || 0,
exchangeCount: data.stock || 0,
saleCount: data.saleCount || 0, // 已兑换数量
memberLevel: this.getMemberLevel(data.state),
vipLimit: data.vipLimit || [], // 会员限制数组
limit: data.groupCount ? data.groupCount.toString() : '1',
goodsLimit: data.goodsLimit || false, // 商品购买限制
name: data.goodsName || data.name || '',
couponName: data.goodsName || data.name || '',
expireDate: data.expireTime && data.expireTime.length > 0 ? data.expireTime[0] : '',
remainDays: this.calculateRemainDays(data.expireTime),
isSoldOut: data.stock <= 0,
isInsufficientCredits: data.buttonText && data.buttonText.includes('积分不足'),
goodsType: data.goodsType || data.type || '',
goodsContent: data.goodsContent || data.content || '',
goodsDeclare: data.goodsDeclare || '',
goodsIcon: data.goodsIcon || data.icon || '',
goodsImage: data.goodsImage || data.image || [],
creditsType: data.creditsType || '',
creditsTypeName: data.creditsTypeName || '',
priceMarket: data.priceMarket || data.price_market || '',
priceSale: data.priceSale || data.price_sale || '',
buttonText: data.buttonText || data.button_text || '立即兑换',
address: data.address || null,
phone: data.phone || '',
stores: data.stores || [],
skus: data.skus || [],
amount: data.amount || [],
checkRule: data.checkRule || {},
failRule: data.failRule || {},
exchangeTime: data.exchangeTime || {},
virtualConfig: data.virtualConfig || {},
matnr: data.matnr || '',
groupEnable: data.groupEnable || false,
goodsState: data.state || 0
};
// 更新用户购买限制状态
this.userBuyLimit = data.userBuyLimit || false;
this.goodsLimit = data.goodsLimit || false;
// 根据商品类型设置规格选项
this.setSpecOptions(data.skus);
// 秒杀商品固定数量为1
this.quantity = 1;
} else {
uni.showToast({
title: response.msg || '获取秒杀商品详情失败',
icon: 'none'
});
}
} catch (error) {
console.error('获取秒杀商品详情失败:', error);
uni.showToast({
title: '网络错误,请重试',
icon: 'none'
});
} finally {
this.isLoading = false;
}
},
// 根据商品状态获取会员等级
getMemberLevel(goodsState) {
// 根据goodsState映射到会员等级
......@@ -453,6 +595,17 @@ export default {
return levelMap[memberLevelName] || 1;
},
// 根据等级数字获取等级名称
getUserLevelName(level) {
const levelMap = {
1: '普通会员',
2: '黄金会员',
3: '铂金会员',
4: '钻石会员'
};
return levelMap[level] || '普通会员';
},
// 计算剩余天数
calculateRemainDays(expireTime) {
if (!expireTime || expireTime.length === 0) return 0;
......@@ -669,9 +822,10 @@ export default {
// 增加数量
increaseQuantity() {
if (this.quantity < parseInt(this.goodsData.limit)) {
this.quantity++;
if (this.goodsData.goodsLimit && this.quantity >= parseInt(this.goodsData.goodsLimit)) {
return;
}
this.quantity++;
},
// 减少数量
......@@ -716,11 +870,14 @@ export default {
title: '兑换中...'
});
// 1. 先计算价格
await this.calculatePrice();
// 2. 非实物商品直接下单
await this.createOrder();
if (this.isSeckill) {
// 秒杀兑换:直接下单,不需要计算价格
await this.createSeckillOrder();
} else {
// 普通兑换:先计算价格,再下单
await this.calculatePrice();
await this.createOrder();
}
} catch (error) {
console.error('兑换失败:', error);
......@@ -779,10 +936,14 @@ export default {
title: '计算中...'
});
// 先计算价格
await this.calculatePrice();
uni.hideLoading();
if (this.isSeckill) {
// 秒杀商品:不需要计算价格,直接跳转
uni.hideLoading();
} else {
// 普通商品:先计算价格
await this.calculatePrice();
uni.hideLoading();
}
// 构建结算页面参数
const settlementParams = {
......@@ -798,8 +959,8 @@ export default {
points: this.goodsData.points,
creditsTypeName: this.goodsData.creditsTypeName || '积分',
// 价格数据
priceData: JSON.stringify(this.priceData),
// 价格数据(秒杀商品可能没有价格数据)
priceData: this.priceData ? JSON.stringify(this.priceData) : '',
// 其他参数
phone: this.orderParams.phone || '',
......@@ -808,7 +969,13 @@ export default {
remark: this.orderParams.remark || '',
addressId: this.orderParams.addressId || '',
storeId: this.orderParams.storeId || '',
projectId: this.orderParams.projectId || ''
projectId: this.orderParams.projectId || '',
// 秒杀相关参数
isSeckill: this.isSeckill,
activityId: this.seckillParams.activityId,
sessionKey: this.seckillParams.sessionKey,
appGoodsId: this.seckillParams.appGoodsId
};
console.log('结算页面参数:', settlementParams);
......@@ -856,6 +1023,40 @@ export default {
}
},
// 创建秒杀订单
async createSeckillOrder() {
try {
const seckillOrderParams = {
id: this.goodsData.id,
phone: this.orderParams.phone || '',
buyNum: this.quantity.toString(), // 秒杀固定为1
storeId: this.orderParams.storeId || '',
amount: this.orderParams.amount || '',
channel: this.orderParams.channel || '',
addressId: this.orderParams.addressId || '',
appGoodsId: this.seckillParams.appGoodsId,
sessionKey: this.seckillParams.sessionKey
};
console.log('秒杀下单参数:', seckillOrderParams);
const response = await fetchSeckillTakeOrder(seckillOrderParams);
console.log('秒杀下单结果:', response);
if (response.ok && response.success) {
this.orderResult = response.data;
uni.hideLoading();
// 跳转到支付结果页面
this.navigateToPayResult(true, response.data);
} else {
throw new Error(response.msg || '秒杀下单失败');
}
} catch (error) {
console.error('秒杀下单失败:', error);
throw error;
}
},
// 跳转到支付结果页面
navigateToPayResult(isSuccess, orderData = null) {
const resultParams = {
......@@ -873,13 +1074,19 @@ export default {
goodsSpec: this.selectedSpec || '',
quantity: this.quantity,
// 价格数据
priceData: JSON.stringify(this.priceData),
// 价格数据(秒杀商品可能没有价格数据)
priceData: this.priceData ? JSON.stringify(this.priceData) : '',
// 订单参数
gid: this.goodsData.id,
skuld: this.getSelectedSkuId(),
buy_num: this.quantity
buy_num: this.quantity,
// 秒杀相关参数
isSeckill: this.isSeckill,
activityId: this.seckillParams.activityId,
sessionKey: this.seckillParams.sessionKey,
appGoodsId: this.seckillParams.appGoodsId
};
if (!isSuccess) {
......@@ -1096,7 +1303,19 @@ export default {
margin-bottom: 20rpx;
}
.member-level,
.member-level {
font-size: 24rpx;
color: #D3A458;
background-color: #FCF2E2;
padding: 8rpx 16rpx;
border-radius: 20rpx;
}
/* 购买限制区域 */
.purchase-limit-section {
margin-bottom: 20rpx;
}
.purchase-limit {
font-size: 24rpx;
color: #D3A458;
......@@ -1382,6 +1601,26 @@ export default {
padding: 0 20rpx;
}
/* 秒杀商品数量显示 */
.quantity-display {
display: flex;
align-items: center;
gap: 0;
border: 2rpx solid #A8A8A8;
border-radius: 8rpx;
padding: 0;
width: fit-content;
}
.quantity-display .quantity-value {
font-size: 32rpx;
color: #333;
font-weight: 500;
min-width: 80rpx;
text-align: center;
padding: 0 20rpx;
}
/* 确认按钮 */
.confirm-spec-btn {
width: 680rpx;
......
......@@ -540,8 +540,9 @@ const isdebug = ref(false);
// 处理积分抢购点击事件
const handleCreditsSaleClick = (good) => {
console.log('点击抢购商品:', good);
const handleCreditsSaleClick = (params) => {
const { good, activityId, sessionKey } = params;
console.log('点击抢购商品:', good, '活动ID:', activityId, '场次Key:', sessionKey);
// 检查库存
if (good.stock <= 0) {
......@@ -567,10 +568,11 @@ const handleCreditsSaleClick = (good) => {
icon: 'none'
});
// TODO: 添加跳转到商品详情页或购买页面的逻辑
// 构建跳转URL,添加activityId和sessionKey参数
const url = `/v3/goodDetail/goodDetail?gid=${good.id}&activityId=${activityId}&sessionKey=${sessionKey}`;
jump({
type: JumpType.INNER,
url: `/v3/goodDetail/goodDetail?gid=${good.id}`
url: url
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment