|
|
|
|
@ -26,13 +26,22 @@ Page({
@@ -26,13 +26,22 @@ Page({
|
|
|
|
|
|
|
|
|
|
// 图表数据
|
|
|
|
|
chartData: [] as Array<{ date: string, count: number }>, |
|
|
|
|
pharmacistChartData: [] as Array<{ date: string, count: number }>, |
|
|
|
|
pharmacyChartData: [] as Array<{ date: string, count: number }>, |
|
|
|
|
|
|
|
|
|
// 日期范围
|
|
|
|
|
startDate: '', |
|
|
|
|
endDate: '', |
|
|
|
|
today: '', |
|
|
|
|
|
|
|
|
|
// 统计类型: day-日统计, month-月统计
|
|
|
|
|
statType: 'day', |
|
|
|
|
|
|
|
|
|
// 项目列表
|
|
|
|
|
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, |
|
|
|
|
currentProjectId: 0, |
|
|
|
|
currentProjectName: '特诺雅', |
|
|
|
|
projectIndex: 0, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
ecDataTrendComponent1_1: null as any, |
|
|
|
|
@ -44,16 +53,15 @@ Page({
@@ -44,16 +53,15 @@ Page({
|
|
|
|
|
// 地推端页面,仅允许地推人员(3)访问
|
|
|
|
|
app.waitLogin({ types: [3] }).then(() => { |
|
|
|
|
this.getUserInfo() |
|
|
|
|
this.getStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
this.getProjectList() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 初始化日期范围为最近30天
|
|
|
|
|
const endDate = this.formatDate(new Date()) |
|
|
|
|
const today = this.formatDate(new Date()) |
|
|
|
|
const endDate = today |
|
|
|
|
const startDate = this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) |
|
|
|
|
this.setData({ |
|
|
|
|
today, |
|
|
|
|
startDate, |
|
|
|
|
endDate, |
|
|
|
|
}) |
|
|
|
|
@ -67,11 +75,11 @@ Page({
@@ -67,11 +75,11 @@ Page({
|
|
|
|
|
return `${year}-${month}-${day}` |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
|
|
// 获取个人信息
|
|
|
|
|
getUserInfo() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '/app/promoter/promoter/info', |
|
|
|
|
url: '/app/promoter/promoter/profile', |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
promoterName: res.name, |
|
|
|
|
@ -80,11 +88,60 @@ Page({
@@ -80,11 +88,60 @@ Page({
|
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取项目列表
|
|
|
|
|
getProjectList() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '/app/promoter/promoter/project-list', |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
const projectList = res.list || [] |
|
|
|
|
const currentProjectId = res.currentProjectId || (projectList[0]?.projectId || 0) |
|
|
|
|
const currentProject = projectList.find((item: any) => item.projectId === currentProjectId) || projectList[0] |
|
|
|
|
const projectIndex = projectList.findIndex((item: any) => item.projectId === currentProjectId) |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
projectList, |
|
|
|
|
currentProjectId, |
|
|
|
|
currentProjectName: currentProject?.projectName || '特诺雅', |
|
|
|
|
projectIndex: projectIndex >= 0 ? projectIndex : 0, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 获取统计数据
|
|
|
|
|
this.getStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换项目
|
|
|
|
|
onProjectChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const index = e.detail.value |
|
|
|
|
const project = this.data.projectList[index] |
|
|
|
|
if (project && project.projectId !== this.data.currentProjectId) { |
|
|
|
|
this.setData({ |
|
|
|
|
currentProjectId: project.projectId, |
|
|
|
|
currentProjectName: project.projectName, |
|
|
|
|
projectIndex: index, |
|
|
|
|
}) |
|
|
|
|
// 重新加载数据
|
|
|
|
|
this.getStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取统计数据看板
|
|
|
|
|
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, |
|
|
|
|
@ -94,108 +151,74 @@ Page({
@@ -94,108 +151,74 @@ Page({
|
|
|
|
|
enrollPatientCount: res.enrollPatientCount || 0, |
|
|
|
|
indicationStats: res.indicationStats || [], |
|
|
|
|
}) |
|
|
|
|
}).catch(() => { |
|
|
|
|
// 接口失败时使用模拟数据
|
|
|
|
|
this.setData({ |
|
|
|
|
invitePharmacyCount: 45, |
|
|
|
|
invitePharmacistCount: 128, |
|
|
|
|
invitePatientCount: 356, |
|
|
|
|
jumpPatientCount: 289, |
|
|
|
|
enrollPatientCount: 156, |
|
|
|
|
indicationStats: [ |
|
|
|
|
{ indicationId: 1, indicationName: '斑块状银屑病', invitePatientCount: 150, jumpPatientCount: 120, enrollPatientCount: 65 }, |
|
|
|
|
{ indicationId: 2, indicationName: '溃疡性结肠炎', invitePatientCount: 120, jumpPatientCount: 98, enrollPatientCount: 52 }, |
|
|
|
|
{ indicationId: 3, indicationName: '克罗恩病', invitePatientCount: 86, jumpPatientCount: 71, enrollPatientCount: 39 }, |
|
|
|
|
], |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约患者统计图表
|
|
|
|
|
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: { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
}, |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
const list = res.list || [] |
|
|
|
|
this.setData({ |
|
|
|
|
chartData: list, |
|
|
|
|
}) |
|
|
|
|
this.initChartBar(list) |
|
|
|
|
}).catch(() => { |
|
|
|
|
// 接口失败时使用模拟数据
|
|
|
|
|
const mockData = this.generateMockChartData() |
|
|
|
|
data, |
|
|
|
|
}).then((list: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
chartData: mockData, |
|
|
|
|
chartData: list || [], |
|
|
|
|
}) |
|
|
|
|
this.initChartBar(mockData) |
|
|
|
|
this.initChartBar(list || []) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约药师统计图表
|
|
|
|
|
getPharmacistChart() { |
|
|
|
|
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/pharmacist-chart', |
|
|
|
|
data: { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
}, |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
this.initChartLine(res.list || [], '#chart2_1', 'ecDataTrendComponent2_1') |
|
|
|
|
}).catch(() => { |
|
|
|
|
// 接口失败时使用模拟数据
|
|
|
|
|
const mockData = this.generateMockChartData() |
|
|
|
|
this.initChartLine(mockData, '#chart2_1', 'ecDataTrendComponent2_1') |
|
|
|
|
data, |
|
|
|
|
}).then((list: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
pharmacistChartData: list || [], |
|
|
|
|
}) |
|
|
|
|
this.initChartLine(list || [], '#chart2_1', 'ecDataTrendComponent2_1') |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取邀约药店统计图表
|
|
|
|
|
getPharmacyChart() { |
|
|
|
|
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/pharmacy-chart', |
|
|
|
|
data: { |
|
|
|
|
type: this.data.statType, |
|
|
|
|
startDate: this.data.startDate, |
|
|
|
|
endDate: this.data.endDate, |
|
|
|
|
}, |
|
|
|
|
}).then((res: any) => { |
|
|
|
|
this.initChartLine(res.list || [], '#chart3_1', 'ecDataTrendComponent3_1') |
|
|
|
|
}).catch(() => { |
|
|
|
|
// 接口失败时使用模拟数据
|
|
|
|
|
const mockData = this.generateMockChartData() |
|
|
|
|
this.initChartLine(mockData, '#chart3_1', 'ecDataTrendComponent3_1') |
|
|
|
|
data, |
|
|
|
|
}).then((list: any) => { |
|
|
|
|
this.setData({ |
|
|
|
|
pharmacyChartData: list || [], |
|
|
|
|
}) |
|
|
|
|
this.initChartLine(list || [], '#chart3_1', 'ecDataTrendComponent3_1') |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
// 生成模拟图表数据
|
|
|
|
|
generateMockChartData() { |
|
|
|
|
const list: any[] = [] |
|
|
|
|
const days = this.data.statType === 'day' ? 30 : 12 |
|
|
|
|
for (let i = 0; i < days; i++) { |
|
|
|
|
const date = new Date() |
|
|
|
|
if (this.data.statType === 'day') { |
|
|
|
|
date.setDate(date.getDate() - (days - 1 - i)) |
|
|
|
|
list.push({ |
|
|
|
|
date: this.formatDate(date), |
|
|
|
|
count: Math.floor(Math.random() * 50) + 10, |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
date.setMonth(date.getMonth() - (days - 1 - i)) |
|
|
|
|
list.push({ |
|
|
|
|
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`, |
|
|
|
|
count: Math.floor(Math.random() * 500) + 100, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return list |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换统计类型
|
|
|
|
|
switchStatType(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
@ -238,6 +261,42 @@ Page({
@@ -238,6 +261,42 @@ Page({
|
|
|
|
|
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() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换到下一天
|
|
|
|
|
nextDate() { |
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
const newDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000) |
|
|
|
|
const today = new Date() |
|
|
|
|
|
|
|
|
|
// 最大日期不能大于当前日期
|
|
|
|
|
if (newDate > today) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '不能选择未来日期', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const startDate = this.formatDate(newDate) |
|
|
|
|
this.setData({ startDate }) |
|
|
|
|
// 重新加载图表数据
|
|
|
|
|
this.getPatientChart() |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
initChartBar(list: any[]) { |
|
|
|
|
return new Promise((reslove) => { |
|
|
|
|
this.ecDataTrendComponent1_1 = this.selectComponent('#chart1_1') |
|
|
|
|
|