// index.js // 获取应用实例 import { config, formData } from './columns.js' const dataHttps = require("../../utils/serverData"); const https = require("../../utils/serverResource"); import { createStoreBindings } from 'mobx-miniprogram-bindings' import { store } from "../../store/index"; Page({ data: { hasData: true, popupOptions: [], popupType: "city", popupKey: "city", popupTitle: "活动城市", popupApi: "", show: false, length: 0, hasRefund: false, resourceList: [], formData: { ...formData }, type_id_option: [], area_id_option: [], attendance_id_option: [], store_spec_id_option: [], }, onLoad() { this.storeBindings = createStoreBindings(this, { store, fields: ["token"], actions: ["setStore"], }); }, onUnload() { this.storeBindings.destroyStoreBindings(); }, onShow() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 1 }) } this.getResourceList() this.getListAll() }, async getListAll() { const list1 = await this.getDateList('type_id'); const list2 = await this.getDateList('area_id'); const list3 = await this.getDateList('attendance_id'); const list4 = await this.getDateList('store_spec_id'); this.setData({ type_id_option: list1, area_id_option: list2, attendance_id_option: list3, store_spec_id_option: list4, }) // console.log(this.data.type_id_option); }, async getDateList(key) { const { api, isok, unit } = config[key] let resList = [{ value: '0', text: '不限' }] const { code, data } = await dataHttps[api]({ page: 1, limit: 99999, status: 1 }) if (code === 1) { const { list } = data list.forEach(si => { resList.push({ value: si.id + "", min: si.min, max: si.max, text: isok ? si.name : String(si.max) === '0' ? `${si.min}+${unit}` : `${si.min}~${si.max}${unit}` }) }) } else { resList = [] await this.setStore("", ""); } return resList }, typeChange(e) { const type = e.currentTarget.dataset.type; const value = e.detail let list = this.data[type + '_option'], titleVlue = "" const index = list.findIndex( (item) => item.value == value ) titleVlue = list[index].text const { formData, } = this.data let model = { ...formData } model[type] = value model[type + '_title'] = titleVlue model.page = 1 this.setData({ formData: model, }) // console.log(formData); // console.log(this.data.formData); this.getResourceList() }, onReachBottom() { // console.log(' onReachBottom'); const { formData, } = this.data let model = { ...formData } model.page = model.page + 1 this.setData({ formData: model, }) // console.log(this.data.formData) this.getResourceList() }, // 事件处理函数 bindViewTap(e) { const type = e.currentTarget.dataset.type; // console.log(type); wx.navigateTo({ url: '../../userOrder/pages/resource-details/index?id=' + type }) }, onSearch(e) { const value = e.detail && e.detail.value !== undefined ? e.detail.value : e.detail // console.log(value); const { formData, } = this.data let model = { ...formData } model.page = 1 model.store_name = value this.setData({ formData: model, }) this.getResourceList() }, aaa() { const { formData } = this.data this.setData({ show: true, popupValue: formData.store_city }) // console.log('aaa'); }, popupLeft() { this.setData({ show: false, }); }, tapItemClick(e) { const { label, value, } = e.detail console.log(e); let form = { ...this.data.formData, store_city: value, store_city_name: label, } this.setData({ show: false, formData: form }); }, async getResourceList() { const { formData, resourceList, hasData } = this.data const { page, size } = formData if (page !== 1 && hasData === false) { this.setData({ formData: { ...formData, page: page - 1 } }) return } if (page === 1) { wx.pageScrollTo({ scrollTop: 0, duration: 500 }) } let arr = []; let model = { ...formData } for (let key in model) { if (model[key] === "0") { model[key] = "" } } const { code, data } = await https.list(model) if (code == 1) { const { list, count } = data arr = page == 1 ? list : resourceList.concat(list) const total = page * size this.setData({ resourceList: arr, length: arr.length, hasData: count > total }) } else { await this.setStore("", ""); } } })