// pages/message/index.js import { getPreferType, getPreferList } from "../../../api/moment" const util = require('../../../utils/util') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { height: { type: Number, value: 0 } }, data: { tabList: [], tabIndex: 0, typeList: [], scrolled: false, form: { pageNum: 1, pageSize: 10 }, loading: true, requesting: false, finished: false, orderList: [] }, methods: { onRestart: function () { this.fetchTypeList() if(!this.firstShow){ this.fetchList() } this.firstShow = true }, fetchTypeList: function(){ if(this.data.tabList.length > 0){ return } getPreferType().then(result => { this.data.typeList = [{ id: '', name: '全部' }].concat(result.data) for (let index = 0; index < this.data.typeList.length; index++) { this.data.tabList.push(this.data.typeList[index].name) } this.setData({ tabList: this.data.tabList, scrolled: this.data.typeList.length >= 5 }) }) }, onTabChange: function ({ detail }) { if (this.data.tabIndex == Number(detail.index)) { return } this.data.tabIndex = Number(detail.index) this.data.form.categoryId = this.data.typeList[this.data.tabIndex].id this.onRefreshList() }, // 下拉刷新... onRefreshList: function () { if (this.data.requesting) { return } this.setData({ orderList: [], tabIndex: this.data.tabIndex, ['form.pageNum']: 1, loading: true, finished: false }) this.fetchList() }, fetchList: function(){ if (this.data.requesting || this.data.finished) { return } // this.data.requesting = true this.setData({ requesting: true }) getPreferList(this.data.form).then(result => { if (result.data && result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = this.data.form.pageNum var finished = this.data.form.pageNum >= result.data.pages this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false }) } else { this.setData({ finished: true, requesting: false, loading: false }) } }).catch(err => { this.setData({ requesting: false, loading: false }) util.showToast(err) }) } } })