Browse Source

2.0接口联调

dev2.0
kola-web 2 weeks ago
parent
commit
39ec4b8383
  1. 68
      src/gift/pages/recordList/index.ts
  2. 6
      src/gift/pages/recordList/index.wxml

68
src/gift/pages/recordList/index.ts

@ -28,9 +28,18 @@ Page({ @@ -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({ @@ -38,6 +47,9 @@ Page({
// 图表
chartUnit: '',
chartList: [] as any[],
selected: 1,
selectedLabel: '按年',
},
ecDataTrendComponent: null as any,
@ -46,9 +58,6 @@ Page({ @@ -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({ @@ -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({ @@ -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({ @@ -118,10 +125,11 @@ Page({
getIndicatorHistory() {
const data: Record<string, any> = { 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({ @@ -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()
}
},
// ========== 导航 ==========

6
src/gift/pages/recordList/index.wxml

@ -11,13 +11,13 @@ @@ -11,13 +11,13 @@
</view>
<view class="chart" wx:if="{{chartList.length}}">
<view class="chart-header">
<picker range="{{yearOptions}}" range-key="label" bindchange="handleYearChange">
<picker range="{{yearOptions}}" range-key="label" bindchange="handleChange">
<view class="type">
{{year || '按年'}}
{{selectedLabel}}
<van-icon class="icon" name="play" />
</view>
</picker>
<view class="date">
<view class="date" wx:if="{{selected === 1}}">
<picker mode="date" fields="month" bindchange="handleBeginDateChange" value="{{beginDate}}" end="{{endDate}}">
<view class="start {{beginDate && 'active'}}">{{beginDate ? beginDate : '开始时间'}}</view>
</picker>

Loading…
Cancel
Save