Riku
2024-08-13 cf693a5227f17bbf2201512128d267281a8c5695
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
// pages/supervision/index.js
import { useLoading } from '../../behaviors/loading';
import { fetchGradeList } from '../../services/enterprise/fetchAssessment';
import { sceneTypeList } from '../../common/dataSceneTypes';
import dayjs from 'dayjs';
 
Page({
  behaviors: [useLoading],
  /**
   * 页面的初始数据
   */
  data: {
    placeholder: '搜索企业',
    // 搜索结果
    searchResult: [],
    // 搜索条件
    searchOptions: {
      sorts: 'desc', //默认搜索降序排列
      province: null,
      city: null,
      district: null,
      town: null,
      sceneTypeText: null,
      sceneType: null,
      period: undefined,
    },
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.init();
  },
 
  onShow() {
    this.getTabBar().init();
  },
 
  onReachBottom() {
    this._loadMore();
  },
 
  /**
   * 初始加载
   * 当所有筛选条件都获取到初始值后,执行一次初始化加载
   */
  optionsCount: 0,
  init() {
    this.optionsCount++;
    // 包括时间、场景类型、区域三个选项,全部获取初始值后,执行加载
    if (this.optionsCount == 3) this._startLoad();
  },
 
  _fetchData(page) {
    let {
      province,
      city,
      district,
      town,
      area,
      management,
      sorts,
      sceneType,
      period,
    } = this.data.searchOptions;
    return fetchGradeList({
      page,
      data: {
        provinceName: province,
        cityName: city,
        districtName: district,
        townName: town,
        area: area,
        mcName: management,
        sorts,
        period,
        sceneTypes: [sceneType],
      },
    }).then(res => {
      this.setData({
        searchResult:
          page == 1 ? res.data : this.data.searchResult.concat(res.data),
      });
      return res.head;
    });
  },
 
  // 排序更改
  handleSortsChange(e) {
    const { sorts } = e.detail;
    this.setData({
      ['searchOptions.sorts']: sorts,
    });
    this._startLoad();
  },
 
  // 时间更改
  setTimeValue(e) {
    const { timeValue } = e.detail;
    const p = dayjs(timeValue);
    const period = `${p.year()}/${p.month() + 1}-${p.month() + 1}`;
    this.setData({
      ['searchOptions.period']: period,
    });
  },
  initTime(e) {
    this.setTimeValue(e);
    this.init();
  },
  handleTimePickerChange(e) {
    this.setTimeValue(e);
    this._startLoad();
  },
 
  // 场景类型更改
  setSceneValue(e) {
    const { sceneValue } = e.detail;
    this.setData({
      ['searchOptions.sceneType']: sceneValue.join(''),
    });
  },
  initScene(e) {
    this.setSceneValue(e);
    this.init();
  },
  handleScenePickerChange(e) {
    this.setSceneValue(e);
    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.province = provinceText;
    searchOptions.city = cityText;
    searchOptions.district = districtText;
    searchOptions.town = townText;
    searchOptions.area = areaText;
    searchOptions.management = managementText;
    console.log(searchOptions);
    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;
    const { period } = this.data.searchOptions;
    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,
        });
      },
    });
  },
 
  navToSearchPage() {
    wx.navigateTo({
      url: '/pages/enterprise/search/index',
      success: result => {},
      fail: res => {},
      complete: res => {},
    });
  },
});