diff --git a/src/gift/pages/recordList/index.ts b/src/gift/pages/recordList/index.ts index a69ade7..de9c421 100644 --- a/src/gift/pages/recordList/index.ts +++ b/src/gift/pages/recordList/index.ts @@ -28,9 +28,18 @@ Page({ list: [] as any[], pagination: { count: 0, page: 1, pages: 1 }, year: 0 as number, - yearOptions: [] as { label: string; value: number }[], - beginDate: '', - endDate: '', + yearOptions: [ + { + label: '按年', + value: 1, + }, + { + label: '按次', + value: 2, + }, + ] as { label: string; value: number }[], + beginDate: dayjs().subtract(1, 'year').add(1, 'month').format('YYYY-MM'), + endDate: dayjs().format('YYYY-MM'), // 用户头部 latestIgG4: '' as string | number, @@ -38,6 +47,9 @@ Page({ // 图表 chartUnit: '', chartList: [] as any[], + + selected: 1, + selectedLabel: '按年', }, ecDataTrendComponent: null as any, @@ -46,9 +58,6 @@ Page({ echarts = require.async('../../../resource/components/echart/echarts.js').then((mod: any) => { echarts = mod }) - // 默认按年,筛选前一年 - const lastYear = dayjs().subtract(1, 'year').year() - this.setData({ selectedYear: lastYear, selectedYearLabel: `${lastYear}年` }) _app.waitLogin().then(() => { this.getLatestRecord() this.getList() @@ -89,7 +98,6 @@ Page({ for (const item of res.list || []) { if (item.visitDate) yearSet.add(Number(item.visitDate.substring(0, 4))) } - const yearOptions = [...yearSet].sort((a, b) => b - a).map((y) => ({ label: `${y}年`, value: y })) this.setData({ list: reset ? list : [...this.data.list, ...list], @@ -98,7 +106,6 @@ Page({ page: res.page || 1, pages: res.pages || 1, }, - yearOptions: this.data.yearOptions.length ? this.data.yearOptions : yearOptions, }) }) }, @@ -118,10 +125,11 @@ Page({ getIndicatorHistory() { const data: Record = { indicatorField: 'igG4' } - if (this.data.filterMode === 'year') { - data.year = this.data.selectedYear - } else { - data.count = this.data.filterCount || 10 + const { beginDate, endDate, selected } = this.data + + if (beginDate && endDate && selected === 1) { + data.yearStart = Number(beginDate.substring(0, 4)) + data.yearEnd = Number(endDate.substring(0, 4)) } wx.ajax({ @@ -280,28 +288,36 @@ Page({ // ========== 筛选 ========== - handleFilterModeChange(e: any) { - const mode = e.currentTarget.dataset.mode - this.setData({ filterMode: mode }) - this.getIndicatorHistory() - }, - - handleYearChange(e: any) { + handleChange(e: any) { const idx = Number(e.detail.value) const selected = this.data.yearOptions[idx] if (!selected) return + // 按年模式重置为默认12个月范围,按次模式清空让用户选择 + const isByYear = selected.value === 1 this.setData({ - selectedYear: selected.value, - selectedYearLabel: selected.label, + selected: selected.value, + selectedLabel: selected.label, + beginDate: isByYear ? dayjs().subtract(1, 'year').add(1, 'month').format('YYYY-MM') : '', + endDate: isByYear ? dayjs().format('YYYY-MM') : '', }) this.getIndicatorHistory() }, - handleCountChange(e: any) { - const idx = Number(e.detail.value) - const count = this.data.countOptions[idx] - this.setData({ filterCount: count }) - this.getIndicatorHistory() + handleBeginDateChange(e: any) { + const beginDate = e.detail.value + this.setData({ beginDate }) + // 开始和结束日期都选择了才请求 + if (this.data.endDate) { + this.getIndicatorHistory() + } + }, + + handleEndDateChange(e: any) { + const endDate = e.detail.value + this.setData({ endDate }) + if (this.data.beginDate) { + this.getIndicatorHistory() + } }, // ========== 导航 ========== diff --git a/src/gift/pages/recordList/index.wxml b/src/gift/pages/recordList/index.wxml index 97e900d..c540a0f 100644 --- a/src/gift/pages/recordList/index.wxml +++ b/src/gift/pages/recordList/index.wxml @@ -11,13 +11,13 @@ - + - {{year || '按年'}} + {{selectedLabel}} - + {{beginDate ? beginDate : '开始时间'}}