You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.5 KiB
109 lines
3.5 KiB
// pages/storage/index/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getCardList, removeCardNop } from "../../../api/saas"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
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 })
|
|
event.on('EventMessage', this, this.onEvent)
|
|
this.fetchList()
|
|
},
|
|
onEvent: function(message){
|
|
if (message.what == 102 || message.what == 120) {
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
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}` })
|
|
},
|
|
onDelete: function (e) {
|
|
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.showLoading({ title: '正在处理', mask: true })
|
|
removeCardNop(item.cardNo).then(result => {
|
|
this.onRefreshList()
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
})
|