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.
 
 
 

154 lines
3.7 KiB

const app = getApp<IAppOption>()
Page({
data: {
// 药师ID
pharmacistId: '',
// 时间筛选
startDate: '',
endDate: '',
type: 'day', // day-按日,month-按月
// 统计数据
invitePatientCount: 0,
jumpPatientCount: 0,
enrollPatientCount: 0,
indicationStats: [] as any[],
// 图表数据
chartList: [] as any[],
// 加载状态
loading: false,
},
onLoad(option: { id?: string }) {
// 地推端统计页面,仅允许地推人员访问
app.waitLogin({ types: [3] }).then(() => {
// 获取药师ID
const pharmacistId = option.id || ''
if (!pharmacistId) {
wx.showToast({
title: '缺少药师ID',
icon: 'none',
})
return
}
this.setData({ pharmacistId })
// 设置默认时间范围(最近30天)
this.setDefaultDateRange()
// 获取统计数据
this.getStatistics()
this.getChartData()
})
},
// 设置默认时间范围(2026年3月至今)
setDefaultDateRange() {
const endDate = new Date()
const startDate = new Date('2026-03-01')
this.setData({
startDate: this.formatDate(startDate),
endDate: this.formatDate(endDate),
})
},
// 格式化日期
formatDate(date: Date): string {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
// 获取统计数据
getStatistics() {
const { pharmacistId } = this.data
if (!pharmacistId) return
wx.ajax({
method: 'GET',
url: '/app/promoter/promoter/pharmacist-statistics',
data: {
pharmacistId,
},
}).then((res: any) => {
this.setData({
invitePatientCount: res.invitePatientCount || 0,
jumpPatientCount: res.jumpPatientCount || 0,
enrollPatientCount: res.enrollPatientCount || 0,
indicationStats: res.indicationStats || [],
})
})
},
// 获取图表数据
getChartData() {
const { pharmacistId, startDate, endDate, type } = this.data
if (!pharmacistId || !startDate || !endDate) return
this.setData({ loading: true })
wx.ajax({
method: 'GET',
url: '/app/promoter/promoter/pharmacist-chart',
data: {
pharmacistId,
startDate,
endDate,
type,
},
}).then((res: any) => {
this.setData({
chartList: res.list || res || [],
loading: false,
})
}).catch(() => {
this.setData({ loading: false })
})
},
// 开始时间选择
handleStartDateChange(e: WechatMiniprogram.CustomEvent) {
const startDate = e.detail.value
const { endDate } = this.data
// 如果已选择结束时间,验证开始时间不能大于结束时间
if (endDate && startDate > endDate) {
wx.showToast({
title: '开始时间不能大于结束时间',
icon: 'none',
})
return
}
this.setData({ startDate })
this.getChartData()
},
// 结束时间选择
handleEndDateChange(e: WechatMiniprogram.CustomEvent) {
const endDate = e.detail.value
const { startDate } = this.data
// 如果已选择开始时间,验证结束时间不能小于开始时间
if (startDate && endDate < startDate) {
wx.showToast({
title: '结束时间不能小于开始时间',
icon: 'none',
})
return
}
this.setData({ endDate })
this.getChartData()
},
// 切换统计类型
handleTypeChange(e: WechatMiniprogram.CustomEvent) {
const type = e.currentTarget.dataset.type
this.setData({ type })
this.getChartData()
},
handleBack() {
wx.navigateBack()
},
})
export {}