123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- // 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"],
- });
- this.getResourceList()
- this.getListAll()
- },
- onUnload() {
- this.storeBindings.destroyStoreBindings();
- },
- onShow() {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 1
- })
- }
- },
- 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: '../../userResource/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() {
- this.setData({
- show: true
- })
- // console.log('aaa');
- },
- popupLeft() {
- this.setData({
- show: false,
- });
- },
- onConfirm() {
- this.selectComponent('#item').toggle();
- },
- 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("", "");
- }
- }
- })
|