|
|
|
|
@ -44,18 +44,29 @@ Page({
@@ -44,18 +44,29 @@ Page({
|
|
|
|
|
// 日期范围 - 邀约患者统计卡片(单日)
|
|
|
|
|
startDate: '', |
|
|
|
|
today: '', |
|
|
|
|
// 统计卡片显示用的月份(YYYY-MM)
|
|
|
|
|
startMonth: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表1(邀约患者统计)
|
|
|
|
|
chart1StartDate: '', |
|
|
|
|
chart1EndDate: '', |
|
|
|
|
// 图表1显示用的月份(YYYY-MM)
|
|
|
|
|
chart1StartMonth: '', |
|
|
|
|
chart1EndMonth: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表2(邀约药师统计)
|
|
|
|
|
chart2StartDate: '', |
|
|
|
|
chart2EndDate: '', |
|
|
|
|
// 图表2显示用的月份(YYYY-MM)
|
|
|
|
|
chart2StartMonth: '', |
|
|
|
|
chart2EndMonth: '', |
|
|
|
|
|
|
|
|
|
// 日期范围 - 图表3(邀约药店统计)
|
|
|
|
|
chart3StartDate: '', |
|
|
|
|
chart3EndDate: '', |
|
|
|
|
// 图表3显示用的月份(YYYY-MM)
|
|
|
|
|
chart3StartMonth: '', |
|
|
|
|
chart3EndMonth: '', |
|
|
|
|
|
|
|
|
|
// 统计类型: day-日统计, month-月统计
|
|
|
|
|
statType: 'day', |
|
|
|
|
@ -81,18 +92,27 @@ Page({
@@ -81,18 +92,27 @@ Page({
|
|
|
|
|
|
|
|
|
|
// 初始化日期
|
|
|
|
|
const today = this.formatDate(new Date()) |
|
|
|
|
const currentMonth = this.formatMonth(new Date()) |
|
|
|
|
const defaultStartDate = this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) |
|
|
|
|
const defaultStartMonth = this.formatMonth(new Date(Date.now() - 365 * 24 * 60 * 60 * 1000)) |
|
|
|
|
this.setData({ |
|
|
|
|
today, |
|
|
|
|
// 邀约患者统计卡片(单日)- 默认为今天
|
|
|
|
|
startDate: today, |
|
|
|
|
startMonth: currentMonth, |
|
|
|
|
// 图表1-3(日期范围)- 默认为最近30天
|
|
|
|
|
chart1StartDate: defaultStartDate, |
|
|
|
|
chart1EndDate: today, |
|
|
|
|
chart1StartMonth: defaultStartMonth, |
|
|
|
|
chart1EndMonth: currentMonth, |
|
|
|
|
chart2StartDate: defaultStartDate, |
|
|
|
|
chart2EndDate: today, |
|
|
|
|
chart2StartMonth: defaultStartMonth, |
|
|
|
|
chart2EndMonth: currentMonth, |
|
|
|
|
chart3StartDate: defaultStartDate, |
|
|
|
|
chart3EndDate: today, |
|
|
|
|
chart3StartMonth: defaultStartMonth, |
|
|
|
|
chart3EndMonth: currentMonth, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -104,6 +124,13 @@ Page({
@@ -104,6 +124,13 @@ Page({
|
|
|
|
|
return `${year}-${month}-${day}` |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 格式化月份(YYYY-MM)
|
|
|
|
|
formatMonth(date: Date): string { |
|
|
|
|
const year = date.getFullYear() |
|
|
|
|
const month = String(date.getMonth() + 1).padStart(2, '0') |
|
|
|
|
return `${year}-${month}` |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取个人信息
|
|
|
|
|
getUserInfo() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
@ -292,8 +319,80 @@ Page({
@@ -292,8 +319,80 @@ Page({
|
|
|
|
|
// 切换统计类型
|
|
|
|
|
switchStatType(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const type = e.currentTarget.dataset.type |
|
|
|
|
const isMonth = type === 'month' |
|
|
|
|
|
|
|
|
|
// 根据统计类型重置日期范围
|
|
|
|
|
let startDate = this.data.startDate |
|
|
|
|
let startMonth = this.data.startMonth |
|
|
|
|
let chart1StartDate = this.data.chart1StartDate |
|
|
|
|
let chart1EndDate = this.data.chart1EndDate |
|
|
|
|
let chart1StartMonth = this.data.chart1StartMonth |
|
|
|
|
let chart1EndMonth = this.data.chart1EndMonth |
|
|
|
|
let chart2StartDate = this.data.chart2StartDate |
|
|
|
|
let chart2EndDate = this.data.chart2EndDate |
|
|
|
|
let chart2StartMonth = this.data.chart2StartMonth |
|
|
|
|
let chart2EndMonth = this.data.chart2EndMonth |
|
|
|
|
let chart3StartDate = this.data.chart3StartDate |
|
|
|
|
let chart3EndDate = this.data.chart3EndDate |
|
|
|
|
let chart3StartMonth = this.data.chart3StartMonth |
|
|
|
|
let chart3EndMonth = this.data.chart3EndMonth |
|
|
|
|
|
|
|
|
|
if (isMonth) { |
|
|
|
|
// 切换到月统计,设置默认月份
|
|
|
|
|
startMonth = this.formatMonth(new Date()) |
|
|
|
|
startDate = `${startMonth}-01` |
|
|
|
|
// 图表月份范围为最近12个月
|
|
|
|
|
const currentMonth = this.formatMonth(new Date()) |
|
|
|
|
const defaultStartMonth = this.formatMonth(new Date(Date.now() - 365 * 24 * 60 * 60 * 1000)) |
|
|
|
|
chart1StartMonth = defaultStartMonth |
|
|
|
|
chart1EndMonth = currentMonth |
|
|
|
|
chart1StartDate = `${chart1StartMonth}-01` |
|
|
|
|
chart1EndDate = `${chart1EndMonth}-01` |
|
|
|
|
chart2StartMonth = defaultStartMonth |
|
|
|
|
chart2EndMonth = currentMonth |
|
|
|
|
chart2StartDate = `${chart2StartMonth}-01` |
|
|
|
|
chart2EndDate = `${chart2EndMonth}-01` |
|
|
|
|
chart3StartMonth = defaultStartMonth |
|
|
|
|
chart3EndMonth = currentMonth |
|
|
|
|
chart3StartDate = `${chart3StartMonth}-01` |
|
|
|
|
chart3EndDate = `${chart3EndMonth}-01` |
|
|
|
|
} else { |
|
|
|
|
// 切换到日统计,设置默认日期为今天
|
|
|
|
|
startDate = this.formatDate(new Date()) |
|
|
|
|
startMonth = startDate.substring(0, 7) |
|
|
|
|
// 图表日期范围为最近30天
|
|
|
|
|
const today = this.formatDate(new Date()) |
|
|
|
|
const defaultStartDate = this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) |
|
|
|
|
chart1StartDate = defaultStartDate |
|
|
|
|
chart1EndDate = today |
|
|
|
|
chart1StartMonth = chart1StartDate.substring(0, 7) |
|
|
|
|
chart1EndMonth = chart1EndDate.substring(0, 7) |
|
|
|
|
chart2StartDate = defaultStartDate |
|
|
|
|
chart2EndDate = today |
|
|
|
|
chart2StartMonth = chart2StartDate.substring(0, 7) |
|
|
|
|
chart2EndMonth = chart2EndDate.substring(0, 7) |
|
|
|
|
chart3StartDate = defaultStartDate |
|
|
|
|
chart3EndDate = today |
|
|
|
|
chart3StartMonth = chart3StartDate.substring(0, 7) |
|
|
|
|
chart3EndMonth = chart3EndDate.substring(0, 7) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
statType: type, |
|
|
|
|
startDate, |
|
|
|
|
startMonth, |
|
|
|
|
chart1StartDate, |
|
|
|
|
chart1EndDate, |
|
|
|
|
chart1StartMonth, |
|
|
|
|
chart1EndMonth, |
|
|
|
|
chart2StartDate, |
|
|
|
|
chart2EndDate, |
|
|
|
|
chart2StartMonth, |
|
|
|
|
chart2EndMonth, |
|
|
|
|
chart3StartDate, |
|
|
|
|
chart3EndDate, |
|
|
|
|
chart3StartMonth, |
|
|
|
|
chart3EndMonth, |
|
|
|
|
}) |
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
this.getPatientChart() |
|
|
|
|
@ -303,10 +402,16 @@ Page({
@@ -303,10 +402,16 @@ Page({
|
|
|
|
|
|
|
|
|
|
// 日期选择变化(邀约患者统计卡片 - 单日选择)
|
|
|
|
|
onDateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const value = e.detail.value // YYYY-MM-DD 或 YYYY-MM
|
|
|
|
|
|
|
|
|
|
// 月统计时,value 是 YYYY-MM 格式,需要补全为 YYYY-MM-DD
|
|
|
|
|
const isMonth = value.length === 7 |
|
|
|
|
const fullDate = isMonth ? `${value}-01` : value |
|
|
|
|
const monthValue = isMonth ? value : value.substring(0, 7) |
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
startDate: value, |
|
|
|
|
startDate: fullDate, |
|
|
|
|
startMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
// 重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
@ -315,19 +420,25 @@ Page({
@@ -315,19 +420,25 @@ Page({
|
|
|
|
|
// 图表1日期选择变化
|
|
|
|
|
onChart1DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const value = e.detail.value // YYYY-MM-DD 或 YYYY-MM
|
|
|
|
|
|
|
|
|
|
// 月统计时,value 是 YYYY-MM 格式,需要补全为 YYYY-MM-DD
|
|
|
|
|
const isMonth = value.length === 7 |
|
|
|
|
const fullDate = isMonth ? `${value}-01` : value |
|
|
|
|
const monthValue = isMonth ? value : value.substring(0, 7) |
|
|
|
|
|
|
|
|
|
const startDate = this.data.chart1StartDate |
|
|
|
|
const endDate = this.data.chart1EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
if (field === 'startDate' && endDate && fullDate > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
if (field === 'endDate' && startDate && fullDate < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
@ -335,28 +446,42 @@ Page({
@@ -335,28 +446,42 @@ Page({
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (field === 'startDate') { |
|
|
|
|
this.setData({ |
|
|
|
|
chart1StartDate: fullDate, |
|
|
|
|
chart1StartMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.setData({ |
|
|
|
|
[field === 'startDate' ? 'chart1StartDate' : 'chart1EndDate']: value, |
|
|
|
|
chart1EndDate: fullDate, |
|
|
|
|
chart1EndMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
this.getPatientChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 图表2日期选择变化
|
|
|
|
|
onChart2DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const value = e.detail.value // YYYY-MM-DD 或 YYYY-MM
|
|
|
|
|
|
|
|
|
|
// 月统计时,value 是 YYYY-MM 格式,需要补全为 YYYY-MM-DD
|
|
|
|
|
const isMonth = value.length === 7 |
|
|
|
|
const fullDate = isMonth ? `${value}-01` : value |
|
|
|
|
const monthValue = isMonth ? value : value.substring(0, 7) |
|
|
|
|
|
|
|
|
|
const startDate = this.data.chart2StartDate |
|
|
|
|
const endDate = this.data.chart2EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
if (field === 'startDate' && endDate && fullDate > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
if (field === 'endDate' && startDate && fullDate < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
@ -364,28 +489,42 @@ Page({
@@ -364,28 +489,42 @@ Page({
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (field === 'startDate') { |
|
|
|
|
this.setData({ |
|
|
|
|
chart2StartDate: fullDate, |
|
|
|
|
chart2StartMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.setData({ |
|
|
|
|
[field === 'startDate' ? 'chart2StartDate' : 'chart2EndDate']: value, |
|
|
|
|
chart2EndDate: fullDate, |
|
|
|
|
chart2EndMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
this.getPharmacistChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 图表3日期选择变化
|
|
|
|
|
onChart3DateChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const { field } = e.currentTarget.dataset |
|
|
|
|
const value = e.detail.value |
|
|
|
|
const value = e.detail.value // YYYY-MM-DD 或 YYYY-MM
|
|
|
|
|
|
|
|
|
|
// 月统计时,value 是 YYYY-MM 格式,需要补全为 YYYY-MM-DD
|
|
|
|
|
const isMonth = value.length === 7 |
|
|
|
|
const fullDate = isMonth ? `${value}-01` : value |
|
|
|
|
const monthValue = isMonth ? value : value.substring(0, 7) |
|
|
|
|
|
|
|
|
|
const startDate = this.data.chart3StartDate |
|
|
|
|
const endDate = this.data.chart3EndDate |
|
|
|
|
|
|
|
|
|
// 验证日期范围
|
|
|
|
|
if (field === 'startDate' && endDate && value > endDate) { |
|
|
|
|
if (field === 'startDate' && endDate && fullDate > endDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '开始时间不能大于结束时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (field === 'endDate' && startDate && value < startDate) { |
|
|
|
|
if (field === 'endDate' && startDate && fullDate < startDate) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '结束时间不能小于开始时间', |
|
|
|
|
icon: 'none', |
|
|
|
|
@ -393,28 +532,75 @@ Page({
@@ -393,28 +532,75 @@ Page({
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (field === 'startDate') { |
|
|
|
|
this.setData({ |
|
|
|
|
chart3StartDate: fullDate, |
|
|
|
|
chart3StartMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.setData({ |
|
|
|
|
[field === 'startDate' ? 'chart3StartDate' : 'chart3EndDate']: value, |
|
|
|
|
chart3EndDate: fullDate, |
|
|
|
|
chart3EndMonth: monthValue, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
this.getPharmacyChart() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换到上一天(只更新邀约患者统计卡片)
|
|
|
|
|
// 切换到上一天/上月(只更新邀约患者统计卡片)
|
|
|
|
|
prevDate() { |
|
|
|
|
const isMonth = this.data.statType === 'month' |
|
|
|
|
let newDate: Date |
|
|
|
|
let startDate: string |
|
|
|
|
let startMonth: string |
|
|
|
|
|
|
|
|
|
if (isMonth) { |
|
|
|
|
// 月统计:切换到上个月
|
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
const newDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000) |
|
|
|
|
const startDate = this.formatDate(newDate) |
|
|
|
|
newDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1) |
|
|
|
|
startDate = this.formatDate(newDate) |
|
|
|
|
startMonth = this.formatMonth(newDate) |
|
|
|
|
} else { |
|
|
|
|
// 日统计:切换到上一天
|
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
newDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000) |
|
|
|
|
startDate = this.formatDate(newDate) |
|
|
|
|
startMonth = startDate.substring(0, 7) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ startDate }) |
|
|
|
|
this.setData({ startDate, startMonth }) |
|
|
|
|
// 只重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换到下一天(只更新邀约患者统计卡片)
|
|
|
|
|
// 切换到下一天/下月(只更新邀约患者统计卡片)
|
|
|
|
|
nextDate() { |
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
const newDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000) |
|
|
|
|
const isMonth = this.data.statType === 'month' |
|
|
|
|
const today = new Date() |
|
|
|
|
let newDate: Date |
|
|
|
|
let startDate: string |
|
|
|
|
let startMonth: string |
|
|
|
|
|
|
|
|
|
if (isMonth) { |
|
|
|
|
// 月统计:切换到下个月
|
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
newDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1) |
|
|
|
|
|
|
|
|
|
// 最大月份不能大于当前月份
|
|
|
|
|
const currentMonth = new Date(today.getFullYear(), today.getMonth(), 1) |
|
|
|
|
if (newDate > currentMonth) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '不能选择未来月份', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
startDate = this.formatDate(newDate) |
|
|
|
|
startMonth = this.formatMonth(newDate) |
|
|
|
|
} else { |
|
|
|
|
// 日统计:切换到下一天
|
|
|
|
|
const currentDate = new Date(this.data.startDate) |
|
|
|
|
newDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000) |
|
|
|
|
|
|
|
|
|
// 最大日期不能大于当前日期
|
|
|
|
|
if (newDate > today) { |
|
|
|
|
@ -425,8 +611,11 @@ Page({
@@ -425,8 +611,11 @@ Page({
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const startDate = this.formatDate(newDate) |
|
|
|
|
this.setData({ startDate }) |
|
|
|
|
startDate = this.formatDate(newDate) |
|
|
|
|
startMonth = startDate.substring(0, 7) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setData({ startDate, startMonth }) |
|
|
|
|
// 只重新加载统计数据
|
|
|
|
|
this.getPatientStatistics() |
|
|
|
|
}, |
|
|
|
|
|