|
|
|
|
@ -10,9 +10,21 @@ Page({
@@ -10,9 +10,21 @@ Page({
|
|
|
|
|
promoterAvatar: '', |
|
|
|
|
label: '邀约专员', |
|
|
|
|
|
|
|
|
|
// 统计数据
|
|
|
|
|
invitePharmacyCount: 0, |
|
|
|
|
invitePharmacistCount: 0, |
|
|
|
|
// 累计统计数据(来自 getStatistics)
|
|
|
|
|
totalInvitePharmacyCount: 0, |
|
|
|
|
totalInvitePharmacistCount: 0, |
|
|
|
|
totalInvitePatientCount: 0, |
|
|
|
|
totalJumpPatientCount: 0, |
|
|
|
|
totalEnrollPatientCount: 0, |
|
|
|
|
totalIndicationStats: [] as Array<{ |
|
|
|
|
indicationId: number |
|
|
|
|
indicationName: string |
|
|
|
|
invitePatientCount: number |
|
|
|
|
jumpPatientCount: number |
|
|
|
|
enrollPatientCount: number |
|
|
|
|
}>, |
|
|
|
|
|
|
|
|
|
// 日期筛选统计数据(来自 getPatientStatistics)
|
|
|
|
|
invitePatientCount: 0, |
|
|
|
|
jumpPatientCount: 0, |
|
|
|
|
enrollPatientCount: 0, |
|
|
|
|
@ -29,11 +41,22 @@ Page({
@@ -29,11 +41,22 @@ Page({
|
|
|
|
|
pharmacistChartData: [] as Array<{ date: string, count: number }>, |
|
|
|
|
pharmacyChartData: [] as Array<{ date: string, count: number }>, |
|
|
|
|
|
|
|
|
|
// 日期范围
|
|
|
|
|
// 日期范围 - 邀约患者统计卡片(单日)
|
|
|
|
|
startDate: '', |
|
|
|
|
endDate: '', |
|
|
|
|
today: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表1(邀约患者统计)
|
|
|
|
|
chart1StartDate: '', |
|
|
|
|
chart1EndDate: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表2(邀约药师统计)
|
|
|
|
|
chart2StartDate: '', |
|
|
|
|
chart2EndDate: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表3(邀约药店统计)
|
|
|
|
|
chart3StartDate: '', |
|
|
|
|
chart3EndDate: '', |
|
|
|
|
|
|
|
|
|
// 统计类型: day-日统计, month-月统计
|
|
|
|
|
statType: 'day', |
|
|
|
|
|
|
|
|
|
@ -56,14 +79,20 @@ Page({
@@ -56,14 +79,20 @@ Page({
|
|
|
|
|
this.getProjectList() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 初始化日期范围为最近30天
|
|
|
|
|
// 初始化日期
|
|
|
|
|
const today = this.formatDate(new Date()) |
|
|
|
|
const endDate = today |
|
|
|
|
const startDate = this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) |
|
|
|
|
const defaultStartDate = this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) |
|
|
|
|
this.setData({ |
|
|
|
|
today, |
|
|
|
|
startDate, |
|
|
|
|
endDate, |
|
|
|
|
// 邀约患者统计卡片(单日)- 默认为今天
|
|
|
|
|
startDate: today, |
|
|
|
|
// 图表1-3(日期范围)- 默认为最近30天
|
|
|
|
|
chart1StartDate: defaultStartDate, |
|
|
|
|
chart1EndDate: today, |
|
|
|
|
chart2StartDate: defaultStartDate, |
|
|
|
|
chart2EndDate: today, |
|
|
|
|
chart3StartDate: defaultStartDate, |
|
|
|
|
chart3EndDate: today, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -108,6 +137,7 @@ Page({
@@ -108,6 +137,7 @@ Page({
|
|
|
|
|
|
|
|
|
|
// 获取统计数据
|
|
|
|
|
this.getStatistics() |
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
@ -119,6 +149,15 @@ Page({
@@ -119,6 +149,15 @@ Page({
|
|
|
|
|
const index = e.detail.value |
|
|
|
|
const project = this.data.projectList[index] |
|
|
|
|
if (project && project.projectId !== this.data.currentProjectId) { |
|
|
|
|
// 先调用切换项目接口
|
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '/app/promoter/promoter/switch-project', |
|
|
|
|
data: { |
|
|
|
|
projectId: project.projectId, |
|
|
|
|
}, |
|
|
|
|
}).then(() => { |
|
|
|
|
// 切换成功后更新页面数据
|
|
|
|
|
this.setData({ |
|
|
|
|
currentProjectId: project.projectId, |
|
|
|
|
currentProjectName: project.projectName, |
|
|
|
|
@ -126,26 +165,52 @@ Page({
@@ -126,26 +165,52 @@ Page({
|
|
|
|
|
}) |
|
|
|
|
// 重新加载数据
|
|
|
|
|
this.getStatistics() |
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '切换成功', |
|
|
|
|
icon: 'success', |
|
|
|
|
}) |
|
|
|
|
}).catch(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '切换失败', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取统计数据看板
|
|
|
|
|
// 获取统计数据看板(累计数据)
|
|
|
|
|
getStatistics() { |
|
|
|
|
const data: any = {} |
|
|
|
|
if (this.data.currentProjectId) { |
|
|
|
|
data.projectId = this.data.currentProjectId |
|
|
|
|
} |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '/app/promoter/promoter/statistics', |
|
|
|
|
data, |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
invitePharmacyCount: res.invitePharmacyCount || 0, |
|
|
|
|
invitePharmacistCount: res.invitePharmacistCount || 0, |
|
|
|
|
// 累计数据
|
|
|
|
|
totalInvitePharmacyCount: res.invitePharmacyCount || 0, |
|
|
|
|
totalInvitePharmacistCount: res.invitePharmacistCount || 0, |
|
|
|
|
totalInvitePatientCount: res.invitePatientCount || 0, |
|
|
|
|
totalJumpPatientCount: res.jumpPatientCount || 0, |
|
|
|
|
totalEnrollPatientCount: res.enrollPatientCount || 0, |
|
|
|
|
totalIndicationStats: res.indicationStats || [], |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取日/月度邀约患者统计数据(按日期筛选)
|
|
|
|
|
getPatientStatistics() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '/app/promoter/promoter/patient-statistics', |
|
|
|
|
data: { |
|
|
|
|
statDate: this.data.startDate, |
|
|
|
|
type: this.data.statType, |
|
|
|
|
}, |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
invitePatientCount: res.invitePatientCount || 0, |
|
|
|
|
jumpPatientCount: res.jumpPatientCount || 0, |
|
|
|
|
enrollPatientCount: res.enrollPatientCount || 0, |
|
|
|
|
@ -154,34 +219,38 @@ Page({
@@ -154,34 +219,38 @@ Page({
|
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约患者统计图表
|
|
|
|
|
// 获取邀约患者统计图表(使用 chart1 的日期)
|
|
|
|
|
getPatientChart() { |
|
|
|
|
const data: any = { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
} |
|
|
|
|
if (this.data.currentProjectId) { |
|
|
|
|
data.projectId = this.data.currentProjectId |
|
|
|
|
} |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '/app/promoter/promoter/patient-chart', |
|
|
|
|
data, |
|
|
|
|
data: { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.chart1StartDate, |
|
|
|
|
endDate: this.data.chart1EndDate, |
|
|
|
|
}, |
|
|
|
|
}).then((list: any) => { |
|
|
|
|
// 新接口返回的数据格式包含 invitePatientCount, jumpPatientCount, enrollPatientCount, indicationStats
|
|
|
|
|
// 转换为图表需要的格式
|
|
|
|
|
const chartData = (list || []).map((item: any) => ({ |
|
|
|
|
date: item.statDate, |
|
|
|
|
inviteCount: item.invitePatientCount || 0, |
|
|
|
|
jumpCount: item.jumpPatientCount || 0, |
|
|
|
|
enrollCount: item.enrollPatientCount || 0, |
|
|
|
|
})) |
|
|
|
|
this.setData({ |
|
|
|
|
chartData: list || [], |
|
|
|
|
chartData, |
|
|
|
|
}) |
|
|
|
|
this.initChartBar(list || []) |
|
|
|
|
this.initChartBar(chartData) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约药师统计图表
|
|
|
|
|
// 获取邀约药师统计图表(使用 chart2 的日期)
|
|
|
|
|
getPharmacistChart() { |
|
|
|
|
const data: any = { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
startDate: this.data.chart2StartDate, |
|
|
|
|
endDate: this.data.chart2EndDate, |
|
|
|
|
} |
|
|
|
|
if (this.data.currentProjectId) { |
|
|
|
|
data.projectId = this.data.currentProjectId |
|
|
|
|
@ -198,12 +267,12 @@ Page({
@@ -198,12 +267,12 @@ Page({
|
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约药店统计图表
|
|
|
|
|
// 获取邀约药店统计图表(使用 chart3 的日期)
|
|
|
|
|
getPharmacyChart() { |
|
|
|
|
const data: any = { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
startDate: this.data.chart3StartDate, |
|
|
|
|
endDate: this.data.chart3EndDate, |
|
|
|
|
} |
|
|
|
|
if (this.data.currentProjectId) { |
|
|
|
|
data.projectId = this.data.currentProjectId |
|
|
|
|
@ -226,25 +295,39 @@ Page({
@@ -226,25 +295,39 @@ Page({
|
|
|
|
|
this.setData({ |
|
|
|
|
statType: type, |
|
|
|
|
}) |
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 日期选择变化
|
|
|
|
|
// 日期选择变化(邀约患者统计卡片 - 单日选择)
|
|
|
|
|
onDateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const value = e.detail.value |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
startDate: value, |
|
|
|
|
}) |
|
|
|
|
// 重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 图表1日期选择变化
|
|
|
|
|
onChart1DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const startDate = this.data.chart1StartDate |
|
|
|
|
const endDate = this.data.chart1EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && this.data.endDate && value > this.data.endDate) { |
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && this.data.startDate && value < this.data.startDate) { |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
@ -253,28 +336,81 @@ Page({
@@ -253,28 +336,81 @@ Page({
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
[field]: value, |
|
|
|
|
[field === 'startDate' ? 'chart1StartDate' : 'chart1EndDate']: value, |
|
|
|
|
}) |
|
|
|
|
// 重新加载图表数据
|
|
|
|
|
this.getPatientChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 图表2日期选择变化
|
|
|
|
|
onChart2DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const startDate = this.data.chart2StartDate |
|
|
|
|
const endDate = this.data.chart2EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
[field === 'startDate' ? 'chart2StartDate' : 'chart2EndDate']: value, |
|
|
|
|
}) |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 图表3日期选择变化
|
|
|
|
|
onChart3DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const startDate = this.data.chart3StartDate |
|
|
|
|
const endDate = this.data.chart3EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
[field === 'startDate' ? 'chart3StartDate' : 'chart3EndDate']: value, |
|
|
|
|
}) |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换到上一天
|
|
|
|
|
// 切换到上一天(只更新邀约患者统计卡片)
|
|
|
|
|
prevDate() { |
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
const newDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000) |
|
|
|
|
const startDate = this.formatDate(newDate) |
|
|
|
|
|
|
|
|
|
this.setData({ startDate }) |
|
|
|
|
// 重新加载图表数据
|
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
// 只重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换到下一天
|
|
|
|
|
// 切换到下一天(只更新邀约患者统计卡片)
|
|
|
|
|
nextDate() { |
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
const newDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000) |
|
|
|
|
@ -291,10 +427,8 @@ Page({
@@ -291,10 +427,8 @@ Page({
|
|
|
|
|
|
|
|
|
|
const startDate = this.formatDate(newDate) |
|
|
|
|
this.setData({ startDate }) |
|
|
|
|
// 重新加载图表数据
|
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
// 只重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
initChartBar(list: any[]) { |
|
|
|
|
|