riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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];
    });
  },
});