Riku
2024-08-13 093afd3be27ea5e9692839845b69bd56e2405518
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import dayjs from 'dayjs';
import { useLoading } from '../../../behaviors/loading';
import { fetchSceneProSummary } from '../../../services/inspection/fetchScene';
import { fetchProblemsStatistic } from '../../../services/inspection/fetchInspection';
import { _getParamsArea } from '../param-util.js';
 
Page({
  behaviors: [useLoading],
  data: {
    summaryList: [],
    sort: '',
    sortBy: 'pro',
    statistic: {
      proNum: 0,
      changeNum: 0,
    },
  },
 
  onLoad(options) {
    this.getOpenerEventChannel().on('acceptInspectionData', data => {
      this.setData({
        location: {
          provinceText: data.inspection.provinceName,
          cityText: data.inspection.cityName,
          districtText: data.inspection.districtName,
          townText: data.inspection.townName,
        },
        inspection: data.inspection,
        time: data.time,
        sceneTypeText: data.sceneTypeText,
        sceneTypeValue: data.sceneTypeValue,
      });
      this._startLoad();
    });
  },
 
  onReachBottom() {
    this._loadMore();
  },
 
  _fetchData(page) {
    const f1 = this.fetchSceneProSummary(page);
    const f2 = this.fetchProblems(page);
    return Promise.all([f1, f2]).then(res => {
      // 返回请求f1的分页信息
      return res[0];
    });
  },
 
  fetchSceneProSummary(page) {
    const params = _getParamsArea(this.data);
    const { sortBy } = this.data;
    return fetchSceneProSummary({ area: params, sortBy, page }).then(res => {
      if (res.success) {
        this.setData({
          summaryList: page == 1 ? res.data : this.data.summaryList.concat(res.data),
        });
      } else {
        this.setData({
          summaryList: [],
        });
      }
      return res.head;
    });
  },
 
  fetchProblems(page) {
    const params = _getParamsArea(this.data);
    return fetchProblemsStatistic(params).then(res => {
      let proNum = 0,
        changeNum = 0,
        changePer = 0;
      res.data.forEach(r => {
        proNum += r.count;
        changeNum += r.changeCount;
      });
      if (proNum > 0) {
        changePer = Math.round((changeNum / proNum) * 1000) / 10;
        changePer += '%';
      }
      this.setData({
        statistic: { proNum, changeNum, changePer },
      });
      return res.head;
    });
  },
 
  onTimePickerConfirm(e) {
    const { timeValue } = e.detail;
    this.setData({
      time: timeValue,
    });
    this._startLoad();
  },
  onLocationChange(e) {
    const { inspection } = this.data;
    inspection.provinceName = e.detail.provinceText;
    inspection.cityName = e.detail.cityText;
    inspection.districtName = e.detail.districtText;
    inspection.townName = e.detail.townText;
    inspection.provinceCode = e.detail.provinceValue;
    inspection.cityCode = e.detail.cityValue;
    inspection.districtCode = e.detail.districtValue;
    inspection.townCode = e.detail.townValue;
    inspection.locationValue = e.detail.locationValue;
    this.setData({ inspection });
    this._startLoad();
  },
  onScenePickerConfirm(e) {
    const { sceneText: sceneTypeText, sceneValue: sceneTypeValue } = e.detail;
    this.setData({ sceneTypeText, sceneTypeValue });
    this._startLoad();
  },
 
  onSortChange(e) {
    const { sorts } = e.detail;
    const { type } = e.currentTarget.dataset;
    this.setData({
      sort: sorts,
      sortBy: type,
      proSort: type == 'pro' ? sorts : 'default',
      changeSort: type == 'changePer' ? sorts : 'default',
    });
    this._startLoad();
  },
 
  // 问题数排序更改
  onProNumSortChange(e) {
    const { sorts } = e.detail;
    this.setData({
      sort: sorts,
    });
    this._startLoad();
  },
 
  // 整改率排序更改
  onChangePerSortChange(e) {},
 
  navToDetail(e) {
    const { index } = e.currentTarget.dataset;
    const summary = this.data.summaryList[index];
    wx.navigateTo({
      url: '/pages/inspection/detail/index',
      success: result => {
        result.eventChannel.emit('acceptInspectionDetailData', {
          scene: summary.scene,
          time: this.data.time,
        });
      },
    });
  },
});