// 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 => {}, }); }, });