import { getChainList } from "../../../api/chain" const math = require('../../../utils/math') const util = require('../../../utils/util') const event = require('../../../utils/event') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, /** 页面的初始数据 */ data: { firstShow: false, userInfo: null, menuList: [ {url: '/pages/home/factory-list/index', text: '供应商管理', icon: '/assets/image/supplier-icon.png'}, {url: '/pages/home/factory-list/index', text: '订单审核', icon: '/assets/image/order-check-icon.png'}, {url: '/pages/home/factory-list/index', text: '在线对账', icon: '/assets/image/reconciliation-icon.png'} ], loading: true, requesting: false, finished: false, dataList: [], form: { pageNum: 1, pageSize: 10 } }, lifetimes: { attached: function () { event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { onRestart: function () { if(!this.data.firstShow) { this.setData({height: app.globalData.windowHeight - app.globalData.safeBottom - 100, userInfo: app.userInfo }) this.data.form.storeId = app.userInfo.storeBaseInfo.id this.fetchChainList() } // this.fetchStatisticsInfo() this.data.firstShow = true }, onEvent: function (message) { if (message.what == 888) { } }, fetchStatisticsInfo: function(loading){ getBalanceInfo().then(result => { if(result.data){ result.data.accountMoney = math.minus(result.data.accountMoney, result.data.frozenMoney) this.setData({ banlanceInfo: result.data }) } }).catch(err => { if(loading){ wx.hideLoading() } }) }, fetchChainList: function(){ if (this.data.requesting || this.data.finished) { return } this.data.requesting = true getChainList(this.data.form).then(result => { if (result.data && result.data.records && result.data.records.length) { var respList = result.data.records let nowList = `dataList[${this.data.dataList.length}]` var num = this.data.form.pageNum var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total 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) }) } } })