Commit 2ec95e00 authored by spc's avatar spc

fixed

parent c2c297e8
......@@ -30,7 +30,7 @@ export const fetchGoodsDetail = (data) => api.get('/c/goods/detail', data);
* @returns {Promise} API响应
* @description 计算商品价格和优惠信息,在下单前调用
*/
export const fetchGoodsPrice = (data) => api.get('/c/goods/price', data);
export const fetchGoodsPrice = (data) => api.post('/c/goods/price', data);
/**
* 下单
......@@ -48,7 +48,7 @@ export const fetchGoodsPrice = (data) => api.get('/c/goods/price', data);
* @returns {Promise} API响应
* @description 创建订单,在价格计算后调用
*/
export const fetchTradeCredits = (data) => api.get('/c/trade/credits', data);
export const fetchTradeCredits = (data) => api.post('/c/trade/credits', data);
......
......@@ -121,6 +121,8 @@
<script>
import { fetchGoodsDetail, fetchGoodsPrice, fetchTradeCredits } from '@/api/goods.js';
import { useUserStore } from '@/stores/user';
import { jump, JumpType } from '../../utils';
export default {
data() {
......@@ -175,18 +177,34 @@ export default {
// 订单相关
orderParams: {}, // 订单参数
priceData: null, // 价格计算结果
orderResult: null // 下单结果
orderResult: null, // 下单结果
// 用户状态
userStore: null, // 用户store实例
cfgStatus: {
isRegister: true, // 登录状态
showDetail: false // 是否显示详情
}
}
},
computed: {
// 是否可以兑换
canExchange() {
// 首先检查登录状态
if (!this.cfgStatus.isRegister) {
return false;
}
// 只有goodsState为1时才可兑换
return this.goodsData.goodsState === 1;
},
// 兑换状态
exchangeStatus() {
// 未登录状态
if (!this.cfgStatus.isRegister) {
return 'notLoggedIn';
}
// 只有goodsState为1时才可兑换
if (this.goodsData.goodsState === 1) {
return 'canExchange';
......@@ -199,6 +217,9 @@ export default {
onLoad(options) {
console.log('页面参数:', options);
// 初始化用户状态
this.initUserStatus();
// 构建API请求参数
const apiParams = {
gid: options.gid || options.id || options.goodsId || '', // 商品ID (必须)
......@@ -228,12 +249,57 @@ export default {
}, 1500);
}
},
onShow() {
// 每次页面显示时重新检查用户状态
this.checkUserStatus();
},
methods: {
// 返回上一页
navigateBack() {
uni.navigateBack();
},
// 初始化用户状态
async initUserStatus() {
// 获取用户store实例
this.userStore = useUserStore();
// 加载会员信息
await this.userStore.loadMemberInfo();
// 检查用户状态
this.checkUserStatus();
},
// 检查用户状态
checkUserStatus() {
if (!this.userStore) {
this.cfgStatus.isRegister = false;
return;
}
// 检查用户信息是否存在且有效
const userInfo = this.userStore.userInfo;
const memberId = userInfo?.memberId;
// 如果memberId为"not_login"或不存在,则未登录
if (!memberId || memberId === "not_login") {
this.cfgStatus.isRegister = false;
this.cfgStatus.showDetail = false;
} else {
this.cfgStatus.isRegister = true;
// 根据宝宝阶段决定是否显示详情
const babyInfo = this.userStore.babyInfo;
this.cfgStatus.showDetail = babyInfo?.babyStage ? [1, 2].includes(babyInfo.babyStage) : false;
}
console.log('用户状态检查:', {
userInfo,
memberId,
cfgStatus: this.cfgStatus
});
},
// 获取商品详情
async fetchGoodsDetail(params) {
this.isLoading = true;
......@@ -399,12 +465,25 @@ export default {
// 获取按钮文本
getButtonText() {
// 未登录状态
if (!this.cfgStatus.isRegister) {
return '请先登录';
}
// 优先使用API返回的按钮文本
return this.goodsData.buttonText || '立即兑换';
},
// 处理兑换
handleExchange() {
if (!this.cfgStatus.isRegister) {
// 未登录,跳转到登录注册页面
jump({
type: JumpType.INNER,
url: "/pages/activity/register",
});
return;
}
if (!this.canExchange) {
this.showStatusMessage();
return;
......@@ -418,7 +497,10 @@ export default {
showStatusMessage() {
let message = '';
if (this.goodsData.goodsState === 1) {
// 未登录状态
if (!this.cfgStatus.isRegister) {
message = '请先登录后再进行兑换';
} else if (this.goodsData.goodsState === 1) {
message = '可以兑换';
} else {
message = this.goodsData.buttonText || '无法兑换该商品';
......
......@@ -390,7 +390,7 @@ const navigateToWithLogin = (url) => {
console.warn('navigateToWithLogin', url);
console.warn('cfgStatus.value.isRegister', cfgStatus.value.isRegister);
// 检查登录状态
if (cfgStatus.value.isRegister) {
if (!cfgStatus.value.isRegister) {
// 未登录,跳转到登录注册页面
jump({
type: JumpType.INNER,
......
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