// pages/balance/fragment/index.js import { getFinanceList } from "../../api/saas" const util = require('../../../utils/util') Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { direction: { type: Number, value: 0 }, height: { type: Number, value: 0 } }, /** * 页面的初始数据 */ data: { firstShow: false, finished: false, requesting: false, taskList: [], form: { pageSize: 10, pageNum: 1, direction: null } }, methods: { onRestart: function () { if (!this.data.firstShow) { this.fetchList() this.data.firstShow = true } }, fetchList: function () { if (this.data.requesting || this.data.finished) { return } this.data.form.direction = this.data.direction this.data.requesting = true wx.showLoading({ title: '加载中', mask: true }) getFinanceList(this.data.form).then(result => { this.setData({ requesting: false, loading: false }) if (result.data.records.length) { var respList = result.data.records let nowList = `taskList[${this.data.taskList.length}]` var num = this.data.form.pageNum var finished = this.data.form.pageNum >= result.data.pages this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished }) } else { this.setData({ finished: true }) } wx.hideLoading() }).catch(err => { this.setData({ requesting: false, loading: false }) wx.hideLoading() util.showToast(err) }) }, lookItem: function(e){ wx.navigateTo({ url: '/pages/balance/detail/index?id=' + e.currentTarget.id + '&type=' + this.data.direction }) } } })