You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
314 lines
7.5 KiB
314 lines
7.5 KiB
// pages/evaluate/index.js
|
|
//估价页面 - 简化版三步骤流程
|
|
|
|
const api = require('../../utils/api');
|
|
|
|
Page({
|
|
data: {
|
|
currentStep: 1,
|
|
// 月日选择
|
|
selectedMonth: '',
|
|
selectedMonthIndex: 0,
|
|
selectedDay: '',
|
|
selectedDayIndex: 0,
|
|
months: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
|
|
days: [],
|
|
// 地区和品种选择
|
|
selectedRegion: '',
|
|
selectedRegionIndex: 0,
|
|
selectedBreed: '',
|
|
selectedBreedIndex: 0,
|
|
evaluateResult: {
|
|
estimatedPrice: '0.00',
|
|
priceRange: '0.00 - 0.00',
|
|
confidence: '85%'
|
|
},
|
|
|
|
// 地区选项
|
|
regionOptions: [
|
|
'成都市场报价'
|
|
],
|
|
// 品种选项
|
|
breedOptions: [
|
|
'黄蛋(红蛋)',
|
|
'粉蛋'
|
|
]
|
|
},
|
|
|
|
onLoad() {
|
|
console.log('估价页面初始化 - 简化版')
|
|
|
|
// 初始化为当前北京时间
|
|
this.initCurrentDate()
|
|
},
|
|
|
|
// 初始化当前日期
|
|
initCurrentDate() {
|
|
const now = new Date()
|
|
const currentMonth = (now.getMonth() + 1).toString()
|
|
const currentDate = now.getDate().toString()
|
|
|
|
// 设置默认月份
|
|
const monthIndex = this.data.months.indexOf(currentMonth)
|
|
this.setData({
|
|
selectedMonth: currentMonth,
|
|
selectedMonthIndex: monthIndex >= 0 ? monthIndex : 0
|
|
})
|
|
|
|
// 根据当前月份更新日期数组
|
|
this.updateDaysForMonth(currentMonth)
|
|
|
|
// 设置默认日期
|
|
const dayIndex = this.data.days.indexOf(currentDate)
|
|
this.setData({
|
|
selectedDay: dayIndex >= 0 ? currentDate : '',
|
|
selectedDayIndex: dayIndex >= 0 ? dayIndex : 0
|
|
})
|
|
},
|
|
|
|
// 第一步:点击我知道了
|
|
onIKnow() {
|
|
this.setData({
|
|
currentStep: 2
|
|
})
|
|
},
|
|
|
|
// 月份选择器变化
|
|
onMonthChange(e) {
|
|
const monthIndex = e.detail.value
|
|
const selectedMonth = this.data.months[monthIndex]
|
|
|
|
// 更新月份
|
|
this.setData({
|
|
selectedMonth: selectedMonth,
|
|
selectedMonthIndex: monthIndex,
|
|
selectedDay: '', // 清空日期选择
|
|
selectedDayIndex: 0
|
|
})
|
|
|
|
// 根据月份设置对应的日期数组
|
|
this.updateDaysForMonth(selectedMonth)
|
|
},
|
|
|
|
// 日期选择器变化
|
|
onDayChange(e) {
|
|
const dayIndex = e.detail.value
|
|
const selectedDay = this.data.days[dayIndex]
|
|
this.setData({
|
|
selectedDay: selectedDay,
|
|
selectedDayIndex: dayIndex
|
|
})
|
|
},
|
|
|
|
// 根据月份更新日期数组
|
|
updateDaysForMonth(month) {
|
|
let daysCount
|
|
|
|
// 根据月份设置日期数量
|
|
switch(month) {
|
|
case '2': // 2月
|
|
daysCount = 28 // 简化处理,不考虑闰年
|
|
break
|
|
case '4':
|
|
case '6':
|
|
case '9':
|
|
case '11': // 小月
|
|
daysCount = 30
|
|
break
|
|
default: // 大月
|
|
daysCount = 31
|
|
}
|
|
|
|
const days = []
|
|
for (let i = 1; i <= daysCount; i++) {
|
|
days.push(i.toString())
|
|
}
|
|
|
|
this.setData({
|
|
days: days,
|
|
selectedDay: '',
|
|
selectedDayIndex: 0
|
|
})
|
|
},
|
|
|
|
// 地区选择器变化
|
|
onRegionChange(e) {
|
|
const index = e.detail.value
|
|
const selectedRegion = this.data.regionOptions[index]
|
|
this.setData({
|
|
selectedRegion: selectedRegion,
|
|
selectedRegionIndex: index
|
|
})
|
|
},
|
|
|
|
// 品种选择器变化
|
|
onBreedChange(e) {
|
|
const index = e.detail.value
|
|
const selectedBreed = this.data.breedOptions[index]
|
|
this.setData({
|
|
selectedBreed: selectedBreed,
|
|
selectedBreedIndex: index
|
|
})
|
|
},
|
|
|
|
// 开始估价
|
|
startEvaluation() {
|
|
const { selectedMonth, selectedDay, selectedRegion, selectedBreed } = this.data
|
|
|
|
if (!selectedMonth || !selectedDay || !selectedRegion || !selectedBreed) {
|
|
wx.showToast({
|
|
title: '请完成所有选择',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return
|
|
}
|
|
|
|
// 显示加载中
|
|
wx.showLoading({
|
|
title: '估价中...',
|
|
mask: true
|
|
})
|
|
|
|
// 调用真实的价格评估API
|
|
api.evaluatePrice(selectedMonth, selectedDay, selectedRegion, selectedBreed)
|
|
.then(result => {
|
|
console.log('价格评估结果:', result);
|
|
|
|
// 更新评估结果
|
|
this.setData({
|
|
evaluateResult: {
|
|
estimatedPrice: result.estimatedPrice || '0.00',
|
|
priceRange: result.priceRange || '0.00 - 0.00',
|
|
confidence: result.confidence || '85%'
|
|
},
|
|
currentStep: 3
|
|
});
|
|
|
|
wx.hideLoading()
|
|
|
|
wx.showToast({
|
|
title: '估价完成',
|
|
icon: 'success',
|
|
duration: 1500
|
|
})
|
|
})
|
|
.catch(error => {
|
|
console.error('价格评估失败:', error);
|
|
|
|
wx.hideLoading()
|
|
|
|
wx.showToast({
|
|
title: '估价失败: ' + (error.message || '未知错误'),
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
|
|
// 可以选择保持当前步骤或者回到上一步
|
|
// this.goBack();
|
|
})
|
|
},
|
|
|
|
// 获取时间系数
|
|
getTimeMultiplier(timeValue) {
|
|
const multipliers = {
|
|
'today': 1.0,
|
|
'tomorrow': 0.98,
|
|
'week': 0.95,
|
|
'month': 0.90
|
|
}
|
|
return multipliers[timeValue] || 1.0
|
|
},
|
|
|
|
// 获取地区系数
|
|
getRegionMultiplier(region) {
|
|
const tier1Cities = ['北京', '上海', '广州', '深圳']
|
|
const tier2Cities = ['天津', '江苏', '浙江', '山东']
|
|
|
|
if (tier1Cities.includes(region)) return 1.15
|
|
if (tier2Cities.includes(region)) return 1.05
|
|
return 1.0
|
|
},
|
|
|
|
// 获取品种系数
|
|
getBreedMultiplier(breed) {
|
|
const premiumBreeds = ['绿壳', '双黄蛋', '黑鸡土蛋']
|
|
const popularBreeds = ['罗曼粉', '伊莎粉', '海蓝褐']
|
|
|
|
if (premiumBreeds.includes(breed)) return 1.20
|
|
if (popularBreeds.includes(breed)) return 1.10
|
|
return 1.0
|
|
},
|
|
|
|
// 计算价格区间
|
|
calculatePriceRange(basePrice) {
|
|
const min = (basePrice * 0.9).toFixed(2)
|
|
const max = (basePrice * 1.1).toFixed(2)
|
|
return `${min} - ${max}`
|
|
},
|
|
|
|
// 计算置信度
|
|
calculateConfidence(month, day, region, breed) {
|
|
let confidence = 80 // 基础置信度
|
|
|
|
// 根据选择增加置信度
|
|
// 如果选择了今日(当前月份和日期),增加置信度
|
|
const now = new Date()
|
|
const currentMonth = (now.getMonth() + 1).toString()
|
|
const currentDate = now.getDate().toString()
|
|
|
|
if (month === currentMonth && day === currentDate) {
|
|
confidence += 10
|
|
}
|
|
|
|
// 根据地区增加置信度
|
|
if (['北京', '上海', '广州', '深圳'].includes(region)) confidence += 5
|
|
if (['罗曼粉', '伊莎粉', '海蓝褐'].includes(breed)) confidence += 5
|
|
|
|
return Math.min(confidence, 95) + '%'
|
|
},
|
|
|
|
// 重新估价
|
|
restartEvaluation() {
|
|
this.setData({
|
|
currentStep: 1,
|
|
selectedMonth: '',
|
|
selectedMonthIndex: 0,
|
|
selectedDay: '',
|
|
selectedDayIndex: 0,
|
|
selectedRegion: '',
|
|
selectedRegionIndex: 0,
|
|
selectedBreed: '',
|
|
selectedBreedIndex: 0,
|
|
evaluateResult: {
|
|
estimatedPrice: '0.00',
|
|
priceRange: '0.00 - 0.00',
|
|
confidence: '85%'
|
|
}
|
|
})
|
|
},
|
|
|
|
// 重置估价(与restartEvaluation相同)
|
|
resetEvaluation() {
|
|
this.restartEvaluation()
|
|
},
|
|
|
|
// 查看市场
|
|
goToMarket() {
|
|
// 实际应用中,这里会跳转到市场页面
|
|
wx.showToast({
|
|
title: '功能开发中...',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
|
|
// 返回上一步
|
|
goBack() {
|
|
if (this.data.currentStep > 1) {
|
|
this.setData({
|
|
currentStep: this.data.currentStep - 1
|
|
})
|
|
}
|
|
}
|
|
})
|