riku
2024-11-12 befd1f21839939b54254bd316bbd158b136fcd15
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// pages/supervision/ec-code/index.js
import { useLoading } from '../../../behaviors/loading';
import { sceneTypeList } from '../../../common/dataSceneTypes';
import {
  fetchCreditCodeList,
  fetchCreditCodeCount,
} from '../../../services/enterprise/fetchCreditCode';
import dayjs from 'dayjs';
import { toPeriod, toTime } from '../../../utils/period';
 
Page({
  behaviors: [useLoading],
  /**
   * 页面的初始数据
   */
  data: {
    placeholder: '结果内搜索',
    searchValue: '',
    // 搜索结果
    searchResult: [],
    // 搜索条件
    searchOptions: {
      // 环信码类型,0:绿码;1:黄码;2:红码;null:全部
      ecCodeType: null,
      district: null,
      town: null,
      sceneType: null,
      period: undefined,
    },
  },
 
  _result: [],
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options) {
      const setData = (key, v) => {
        if (v) {
          this.setData({[key]: v})
        }
      }
      setData('searchOptions.provinceText', options.province)
      setData('searchOptions.cityText', options.city)
      setData('searchOptions.districtText', options.district)
      setData('searchOptions.townText', options.town)
      setData('searchOptions.area', options.area)
      setData('searchOptions.management', options.management)
      setData('searchOptions.locationValue', options.locationValue)
      this.setData({
        ['searchOptions.ecCodeType']: options.ecCodeType,
        ['searchOptions.sceneType']: options.sceneType ? options.sceneType : sceneTypeList()[0].value,
        ['searchOptions.period']: options.period ? options.period : dayjs().format('YYYY-MM-DD'),
      })
 
      // 设置行政区域选项初始值
      this.setData({
        location: {
          provinceText: options.province,
          cityText: options.city,
          districtText: options.district,
          townText: options.town,
          value: options.locationValue,
        }
      })
    }
    this.init();
  },
 
  onReachBottom() {
    this._loadMore();
  },
 
  /**
   * 初始加载
   * 当所有筛选条件都获取到初始值后,执行一次初始化加载
   */
  optionsCount: 0,
  init() {
    this.optionsCount++;
    // 时间、场景类型、风险等级三个条件是通过上层界面传递的,
    // 区域条件是选项组件返回的,
    // 需要两组条件同时满足
    if (this.optionsCount == 2) this._startLoad();
  },
 
  _fetchData(page) {
    const promise = [];
 
    let {
      provinceText, cityText,
      districtText, townText,
      area, management,
      ecCodeType: codeType,
      sceneType,
      period,
    } = this.data.searchOptions;
    const { searchValue } = this.data;
    const f1 = fetchCreditCodeList({
      page,
      data: {
        provinceName: provinceText,
        cityName: cityText,
        districtName: districtText,
        townName: townText,
        area: area,
        mcName: management,
        codeType,
        period,
        sceneTypes: [sceneType],
        searchText: searchValue,
      },
    }).then(res => {
      this.setData({
        searchResult:
          page == 1 ? res.data : this.data.searchResult.concat(res.data),
      });
      this._result = this.data.searchResult;
      return res.head;
    });
    promise.push(f1);
 
    if (page == 1) {
      // 环信码数量统计
      const f2 = fetchCreditCodeCount({
        data: {
          provinceName: provinceText,
          cityName: cityText,
          districtName: districtText,
          townName: townText,
          area: area,
          mcName: management,
          sceneTypes: [sceneType],
          period: period,
        },
      }).then(res => {
        this.setData({
          creditPeriod: res.data.period,
          creditRes: res.data.count,
        });
      });
 
      promise.push(f2);
    }
 
    return Promise.all(promise).then(res => {
      return res[0];
    });
  },
 
  // 环信码类型更改
  handleCodeChange(e) {
    const { codeValue } = e.detail;
    this.setData({
      ['searchOptions.ecCodeType']: codeValue[0],
    });
    this._startLoad();
  },
 
  // 场景类型更改
  handleSceneChange(e) {
    const { sceneValue } = e.detail;
    this.setData({
      ['searchOptions.sceneType']: sceneValue[0],
    });
    this._startLoad();
  },
 
  // 时间更改
  handleTimeChange(e) {
    const { timeValue } = e.detail;
    this.setData({
      ['searchOptions.period']: timeValue + '-01',
    });
    this._startLoad();
  },
 
  // 筛选条件弹出框
  showFilterPopup() {
    this.setData({
      show: true,
    });
  },
 
  showFilterPopupClose() {
    this.setData({
      show: false,
    });
  },
 
  setPopupValue(e) {
    const { searchOptions } = this.data;
    const { provinceText, cityText, districtText, townText, areaText, managementText } = e.detail;
    searchOptions.provinceText = provinceText;
    searchOptions.cityText = cityText;
    searchOptions.districtText = districtText;
    searchOptions.townText = townText;
    searchOptions.area = areaText;
    searchOptions.management = managementText;
    this.setData({
      show: false,
      searchOptions,
    });
  },
  initPopup(e) {
    this.setPopupValue(e);
    this.init();
  },
  onPopupSearch(e) {
    this.setPopupValue(e);
    this._startLoad();
  },
 
  // 弹出框关闭
  close(e) {
    this.setData({ show: e.detail.visible });
  },
 
  handCellClick(e) {
    let item = e.detail;
    let { period } = this.data.searchOptions;
    period = toPeriod(period);
    wx.navigateTo({
      url: '/pages/enterprise/detail/index',
      success: result => {
        result.eventChannel.emit('acceptEnterpriseData', {
          enterprise: {
            id: item.userId,
            name: item.name,
            sceneType: item.sceneType,
            sceneTypeId: item.sceneTypeId,
            district: item.district,
          },
          period,
        });
      },
    });
  },
 
  handleSubmit() {
    this._startLoad();
  },
 
  handleChange() {
    if (this.data.searchValue == '') {
      this.handleClear();
    }
  },
 
  handleClear() {
    this._startLoad();
  },
});