Commit 2856ab56 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 e45677ad eb2a5dea
......@@ -93,27 +93,45 @@ export default {
computed: {
// 根据fallResult或allResult字符串生成显示用的选项分布数据
displayOptionDistribution() {
// 优先使用fallResult(后端返回的实际数据)
if (this.fallResult && this.fallResult.trim() !== '' && this.fallResult.includes('|')) {
const percentages = this.fallResult.split('|');
const labels = ['能吃', '少吃', '慎吃', '禁吃'];
return percentages.map((percent, index) => ({
label: labels[index] || '',
percentage: `${percent}%`
}));
const labels = ['能吃', '少吃', '慎吃', '禁吃'];
// 确保所有数据都被正确记录
console.log('AllResult数据:', this.allResult, '类型:', typeof this.allResult);
console.log('FallResult数据:', this.fallResult, '类型:', typeof this.fallResult);
// 首先检查fallResult
if (this.fallResult && this.fallResult !== null && this.fallResult.trim() !== '' && this.fallResult.includes('|')) {
try {
const percentages = this.fallResult.split('|');
console.log('使用fallResult生成分布:', percentages);
return percentages.map((percent, index) => ({
label: labels[index] || '',
percentage: `${percent}%`
}));
} catch (error) {
console.error('处理fallResult时出错:', error);
}
}
// 如果没有fallResult,再使用allResult
else if (this.allResult && this.allResult.trim() !== '' && this.allResult.includes('|')) {
const percentages = this.allResult.split('|');
const labels = ['能吃', '少吃', '慎吃', '禁吃'];
// 然后检查allResult,使用更宽松的判断条件
if (this.allResult && this.allResult !== null && typeof this.allResult === 'string') {
// 即使不包含|符号,也尝试处理
let percentages;
if (this.allResult.includes('|')) {
percentages = this.allResult.split('|');
} else {
// 尝试作为单个百分比处理
percentages = [this.allResult, '0', '0', '0'];
}
console.log('使用allResult生成分布:', percentages);
return percentages.map((percent, index) => ({
label: labels[index] || '',
percentage: `${percent}%`
}));
}
// 否则使用传入的optionDistribution
// 最后使用默认的optionDistribution
console.log('使用默认optionDistribution');
return this.optionDistribution;
}
},
......
......@@ -72,87 +72,35 @@ export default {
// 处理地址点击
handleAddressTap(address) {
if (this.fromSettlement) {
// 如果从结算页面过来,设置为默认地址并返回
this.setAsDefaultAndBack(address);
// 如果从结算页面过来,直接返回选中的地址信息
this.returnToSettlement(address);
}
},
// 设置为默认地址并返回结算页面
async setAsDefaultAndBack(address) {
// 防连点检查
if (this.isSubmitting) return;
this.isSubmitting = true;
try {
// 如果已经是默认地址,直接返回
if (address.isDefault) {
this.returnToSettlement(address);
return;
}
// 显示加载提示
uni.showLoading({
title: '设置中...'
});
// 调用设置默认地址接口,确保使用API要求的正确字段名和完整信息
const response = await updateAddress({
id: address.id,
current: 1, // 1表示设置为默认地址
// 确保使用API要求的正确字段名
name: address.name || address.userName || '',
mobile: address.phone || address.mobile || '',
email: address.email || '',
detail: address.address || address.detail || '',
// 可选字段,保留原数据
province: address.province,
provinceCode: address.provinceCode,
city: address.city,
cityCode: address.cityCode,
area: address.area,
areaCode: address.areaCode,
town: address.town,
townCode: address.townCode,
postalCode: address.zipCode || address.postalCode,
floorNo: address.floorNo
});
console.log('设置默认地址结果:', response);
if (response.ok && response.success) {
// 更新本地数据
this.addressList.forEach(addr => {
addr.isDefault = addr.id === address.id;
});
// 返回结算页面
this.returnToSettlement({
...address,
isDefault: true
});
} else {
uni.showToast({
title: response.msg || '设置默认地址失败',
icon: 'none'
});
this.isSubmitting = false;
}
} catch (error) {
console.error('设置默认地址失败:', error);
uni.showToast({
title: '网络错误,请重试',
icon: 'none'
});
this.isSubmitting = false;
} finally {
uni.hideLoading();
}
},
// 返回结算页面
// 返回结算页面并传递选中的地址信息
returnToSettlement(selectedAddress) {
// 可以通过uni.navigateBack返回,并在结算页面通过onShow重新获取地址
// 创建要传递的地址数据对象
const addressData = {
id: selectedAddress.id,
name: selectedAddress.name,
mobile: selectedAddress.phone || selectedAddress.mobile,
province: selectedAddress.province,
city: selectedAddress.city,
area: selectedAddress.area,
town: selectedAddress.town,
detail: selectedAddress.detail || selectedAddress.address,
current: selectedAddress.isDefault || false
};
// 使用uni-app的全局状态来存储选中的地址
// 这是一种更可靠的数据传递方式
uni.setStorageSync('selectedAddressForSettlement', addressData);
console.log('存储选中的地址信息:', addressData);
// 返回上一页(结算页面)
uni.navigateBack({
delta: 1,
complete: () => {
this.isSubmitting = false;
}
......
......@@ -224,17 +224,17 @@ export default {
// 处理活动banner点击
handleVipActiveClick(index, item) {
console.log('活动banner点击:', item);
if (item?.linkType === 'h5') {
jump({
type: JumpType.H5,
url: item?.linkUrl || ''
});
} else if (item?.linkType === 'page') {
jump({
type: JumpType.PAGE,
url: item?.linkUrl || ''
});
}
// 只保留跳转功能,从item.link获取跳转参数
const url = item?.link?.url || item?.linkUrl || '';
const type = item?.link?.type || (item?.linkType === 'h5' ? JumpType.H5 : JumpType.PAGE);
const extra = item?.link?.extra;
jump({
type: type,
url: url,
extra: extra
})
}
}
}
......
......@@ -165,14 +165,45 @@ export default {
},
onShow() {
// 页面显示时重新检查地址(从地址编辑页面返回时)
this.checkAddress();
// 首先尝试从全局状态中获取选中的地址信息
const selectedAddress = uni.getStorageSync('selectedAddressForSettlement');
if (selectedAddress) {
console.log('从全局状态获取选中的地址:', selectedAddress);
this.selectedAddress = selectedAddress;
this.hasAddress = true;
this.orderParams.addressId = selectedAddress.id;
this.updateAddressDisplay();
// 清除全局状态中的选中标记,避免重复使用
uni.removeStorageSync('selectedAddressForSettlement');
return; // 已经有选中地址,不需要再调用checkAddress
}
// 如果已经有地址了,关闭地址弹窗
if (this.hasAddress && this.showAddressModal) {
this.closeAddressModal();
}
},
// 同时也检查页面栈方式(兼容原有逻辑)
const pages = getCurrentPages();
if (pages.length >= 2) {
const prevPage = pages[pages.length - 2];
// 如果有选中的地址信息,直接使用
if (prevPage && prevPage.data && prevPage.data.selectedAddressForSettlement) {
const pageSelectedAddress = prevPage.data.selectedAddressForSettlement;
console.log('从页面栈获取选中的地址:', pageSelectedAddress);
this.selectedAddress = pageSelectedAddress;
this.hasAddress = true;
this.orderParams.addressId = pageSelectedAddress.id;
this.updateAddressDisplay();
// 清除上一页的选中标记,避免重复使用
prevPage.data.selectedAddressForSettlement = null;
return; // 已经有选中地址,不需要再调用checkAddress
}
}
// 页面显示时重新检查地址(从地址编辑页面返回时或无选中地址时)
this.checkAddress();
// 如果已经有地址了,关闭地址弹窗
if (this.hasAddress && this.showAddressModal) {
this.closeAddressModal();
}
},
methods: {
// 解析页面参数
parsePageParams(options) {
......
......@@ -364,7 +364,7 @@
<!-- 答案解析弹窗 -->
<CanEatAnswerPopup :visible="showAnswerPopup" :isCorrect="isAnswerCorrect" :rewardInfo="rewardInfo"
:question="currentQuestion" :correctAnswer="correctAnswer" :analysis="answerAnalysis"
:optionDistribution="optionDistribution" :allResult="canEatData?.allResult"
:optionDistribution="optionDistribution" :allResult="canEatData?.analysis?.allResult"
@close="showAnswerPopup = false" />
<!-- 金币动画模块 -->
......@@ -467,12 +467,7 @@ export default {
currentQuestion: '',
correctAnswer: '',
answerAnalysis: '',
optionDistribution: [
{ label: '能吃', percentage: '25%', color: '#B27C1E' },
{ label: '少吃', percentage: '25%', color: '#B27C1E' },
{ label: '慎吃', percentage: '25%', color: '#B27C1E' },
{ label: '禁吃', percentage: '25%', color: '#B27C1E' }
],
// 悬浮图片相关配置
floatIcon: {
// imageUrl: 'homepage/btnclose.png',
......@@ -1225,7 +1220,7 @@ export default {
this.isAnswerCorrect = isCorrect;
this.currentQuestion = this.canEatData.title || '';
// 确保正确答案是文案而不是索引
this.correctAnswer = typeof correctAnswer === 'number' ?
this.correctAnswer = typeof correctAnswer === 'number' ?
['能吃', '少吃', '慎吃', '禁吃'][correctAnswer] : correctAnswer;
// 设置奖励信息
......@@ -1250,25 +1245,6 @@ export default {
this.rewardInfo = '';
}
// 设置选项分布数据
if (responseData.allResult && responseData.allResult.trim() !== '') {
const percentages = responseData.allResult.split('|');
const labels = ['能吃', '少吃', '慎吃', '禁吃'];
this.optionDistribution = percentages.map((percent, index) => ({
label: labels[index] || '',
percentage: `${percent}%`,
color: '#B27C1E'
}));
} else {
// 如果allResult为空,使用默认的25%分布
this.optionDistribution = [
{ label: '能吃', percentage: '25%', color: '#B27C1E' },
{ label: '少吃', percentage: '25%', color: '#B27C1E' },
{ label: '慎吃', percentage: '25%', color: '#B27C1E' },
{ label: '禁吃', percentage: '25%', color: '#B27C1E' }
];
}
// 设置解析内容
this.answerAnalysis = responseData.analysis || '暂无解析内容';
......@@ -1289,7 +1265,7 @@ export default {
// 显示解析弹窗
this.showAnswerResult({
analysis: this.canEatData.analysis?.content || '暂无解析内容',
allResult: this.canEatData.analysis?.allResult || '25|25|25|25',
allResult: this.canEatData.analysis?.allResult || '',
reward: this.canEatData.reward || null
}, isCorrect, this.canEatData.myAnswer, correctAnswerText);
} else {
......
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