import { useLoading } from '../../../behaviors/loading'; import { fetchScene } from '../../../services/inspection/fetchScene'; import dayjs from 'dayjs'; import { useSummaryChart } from './chart-proxy.js'; import { useSubtask } from './subtask-proxy.js'; import { useRecurrence } from './recurrence-proxy.js'; Page({ behaviors: [useLoading, useSummaryChart, useSubtask, useRecurrence], data: { year: dayjs().format('YYYY'), sceneId: 'VvQo5wiz3ibWcrcD', scene: {}, subtaskId: 'eMkZXvhKpoP5dWrV', subtaskSummary: [], }, onLoad(options) { this.getOpenerEventChannel().on('acceptInspectionDetailData', data => { if (data) { const year = dayjs(data.time).format('YYYY'); this.setData({ scene: data.scene, year: year, time: data.time, }); } this.initRecentTime(); this.init(); }); }, /** * 初始加载 * 当所有筛选条件都获取到初始值后,执行一次初始化加载 * 包括图表初始化、页面初始化两个选项,全部获取初始值后,执行加载 */ optionsCount: 0, init() { this.optionsCount++; if (this.optionsCount == 2) this._startLoad(); }, onTimePickerConfirm(e) { const { timeValue } = e.detail; this.setData({ year: timeValue, }); this._startLoad(); }, // 根据传入的时间,转换为近期时间下拉框的选项 initRecentTime() { // fixme: 初始化应该通过组件获取 const now = dayjs(); const time = dayjs(this.data.time); let diffMonth = now.diff(time, 'month'); let recentTimeValue = 0; let recentTimeText = '近三月'; if (diffMonth < 3) { diffMonth = 2; recentTimeValue = 0; recentTimeText = '近三月'; } else if (diffMonth < 6) { diffMonth = 5; recentTimeValue = 1; recentTimeText = '近半年'; } else { diffMonth = 11; recentTimeValue = 2; recentTimeText = '近一年'; } let endTime = now.endOf('month'); let startTime = endTime.subtract(diffMonth, 'month').startOf('month'); startTime = startTime.format('YYYY-MM-DD HH:mm:ss'); endTime = endTime.format('YYYY-MM-DD HH:mm:ss'); this.setData({ recentTimeText, recentTimeValue, diffMonth, startTime, endTime }); }, onRecentTimePickerConfirm(e) { const { recentTimeText, recentTimeValue } = e.detail; let diffMonth = 2; if (recentTimeValue == 0) { diffMonth = 2; } else if (recentTimeValue == 1) { diffMonth = 5; } else if (recentTimeValue == 2) { diffMonth = 11; } let endTime = dayjs().endOf('month'); let startTime = endTime.subtract(diffMonth, 'month').startOf('month'); startTime = startTime.format('YYYY-MM-DD HH:mm:ss'); endTime = endTime.format('YYYY-MM-DD HH:mm:ss'); this.setData({ recentTimeText, recentTimeValue, diffMonth, startTime, endTime }); this._startLoad(); }, _fetchData(page) { const pList = []; const p1 = this.fetchProblemsStatistic(); pList.push(p1); const p2 = this.fetchSubtaskSummary(); pList.push(p2); return Promise.all(pList).then(res => { return res[0]; }); }, });