// pages/storage/index/index.js import Scene from '../../index/scene' import { getCardList } from "../../../api/saas" const util = require('../../../utils/util') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, loading: true, requesting: false, finished: false, top: 0, orderList: [], form: { pageNum: 1, pageSize: 15 }, show: false, actions: [ { id: 1, name: '绑定客户' } ], nowItem: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0){ this.data.actions = [{ id: 2, name: '绑定员工' }, { id: 1, name: '绑定客户' }] } this.setData({ height: app.globalData.fragmentHeight, actions: this.data.actions }) this.fetchList() }, onRefreshList: function () { if (this.data.requesting) { return } this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false }) this.fetchList() }, fetchList: function () { if (this.data.requesting || this.data.finished) { return } this.data.requesting = true getCardList(this.data.form).then(result => { if (result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = this.data.form.pageNum var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total if(this.data.form.pageNum == 1){ this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false }) } else { 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) }).then(() => { this.refresh = this.refresh || this.selectComponent('#refresh') this.refresh.setRefresh(false) }) }, onClose: function() { this.setData({ show: false }) }, onSelect: function({detail}) { if(detail.id == 1){ wx.navigateTo({ url: `/pages/home/customer-info/index?cardNo=${this.data.nowItem.cardNo}` }) } else if(detail.id == 2){ wx.navigateTo({ url: `/pages/home/employee-info/index?cardNo=${this.data.nowItem.cardNo}` }) } }, lookItem: function (e) { this.data.nowItem = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index] if(app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0){ this.setData({ show: true }) return } wx.navigateTo({ url: `/pages/home/customer-info/index?cardNo=${this.data.nowItem.cardNo}` }) } })