const $$ = require('../../utils/util'); const app = getApp(); import Toast from '../../components/vant/toast/toast'; function pageZzQueryApi(param) { return $$.request({ url: 'ctUnit/pageZzQuery', type: 'get', submitData: param || {}, service: 'cust' }) } Page({ /** * 页面的初始数据 */ userInfo: {}, location: [], // 省市区等地理资源 data: { imgUrl: $$.url.img, search: { prov: '', provName: '', city: '', cityName: '', area: '', areaName: '', road: '', roadName: '', keyword: '', page: 1, size: 10, }, // 查询条件 data: [], // 数据 total: 0, // 总数 popup: { formtype: '', index: 0, }, // 下拉弹出框数据 }, // 下拉框选择确认 handleConfirmPicker({ detail }) { let type = this.data.popup.type, value = detail.detail.value, arr = []; this.data.popup.visible = false; if (type === 'caseCause') { arr = ['caseType', 'caseTypeName']; arr.forEach((x, t) => { this.data.search[x] = value[0][t === 0 ? 'value' : 'label']; }); } else if (type === 'location') { arr = [ ['city', 'cityName'], ['area', 'areaName'], ['road', 'roadName'], ]; arr.forEach((x, t) => { this.data.search[x[0]] = value[t]?.value || ''; this.data.search[x[1]] = value[t]?.label || ''; }); } this.setData({ popup: this.data.popup, search: this.data.search }); }, // 多行下拉选择时,省市区选择 handleChangeColumns(e) { if (this.data.popup.type === 'location') { let selectData = $$.changeLocation(e, this.location, this.data.popup.selectData); this.setData({ popup: { ...this.data.popup, selectData } }); } }, // 下拉框选择开启 handleShowPopup(e) { let type = e.currentTarget.dataset.type; let selectData = []; if (type === 'location') { if (this.location.length === 0) { return false; } let selectOption = JSON.parse(JSON.stringify(this.location)); let arr = $$.getLocationIndex(this.location, this.data.search); // 计算默认的市区县下标 selectData = [{ values: selectOption, defaultIndex: arr[0] }, { values: selectOption[arr[0]].children, defaultIndex: arr[1] }, { values: selectOption[arr[0]].children[arr[1]].children || [], defaultIndex: arr[2] }, ]; selectData.forEach((x) => { x.values.forEach((y) => { delete y.children; }); }); } else { let selectOption = this.select[type]; selectData = [{ values: selectOption, defaultIndex: 0 }]; } this.setData({ popup: { formtype: e.currentTarget.dataset.formtype, index: e.currentTarget.dataset.index, visible: true, title: e.currentTarget.dataset.title, type: type, selectData: selectData, }, }); }, // 关闭下拉框选择 handleClosePopup() { this.data.popup.visible = false; this.setData({ popup: this.data.popup }); }, searchButton() { this.pageZzQuery(this.data.search) }, async pageZzQuery(params, type) { $$.showLoading(); const res = await pageZzQueryApi(params); $$.hideLoading(); if (this.data.loading) { this.setData({ loading: false }); } if (res.type) { if (params.page === 1) { this.data.data = res.data.content || []; } else { this.data.data = this.data.data.concat(res.data.content || []); } this.setData({ search: params, data: this.data.data, total: res.data.totalElements || 0 }); if (type === 'onPullDownRefresh') { $$.showToast({ title: '已是最新记录', duration: 1000 }); wx.stopPullDownRefresh(); } } }, // 关闭底部弹窗 handleClosePopupMsg() { if (this.data.popupMsg.type === 1) { this.getUserInfo(this.data.popupMsg.intentionObj); } else { this.setData({ popupMsg: { show: false } }); } }, // 滚动到底部获取案件 handlescrolltolower() { if (this.data.data.length >= this.data.total) { return false; } if (!this.data.loading) { this.data.loading = true; this.setData({ loading: this.data.loading }); let submitData = { ...this.data.search }; submitData.page = submitData.page + 1; this.pageZzQuery(submitData); } }, // 返回首页 handleGoHomepage() { if (this.data.changeVisible) { wx.navigateBack({ delta: 1, }); return false; } wx.reLaunch({ url: '../../pages/homePage/index', }); }, // 获取省市区等地理资源 async getLocationData() { $$.showLoading(); const res = await $$.commonRequest({ url: `${$$.url.assets}locationSelect.json`, type: 'get' }); $$.hideLoading(); if (res) { let location = []; $$.province.forEach((x) => { location.push(res[x][0]); }); this.location = location; } }, // 跳转详情 _handleGoPage(e) { let url = e.currentTarget.dataset.url; let id = e.currentTarget.dataset.id; wx.navigateTo({ url: url + '?id=' + id, }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.pageZzQuery(this.data.search) this.getLocationData(); }, onShow: function () { // this.pageZzQuery(this.data.search); }, onHide: function () {}, onUnload: function () {}, });