纸通宝SAAS仓库
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.
 

110 lines
3.5 KiB

// pages/home/customer/index.js
import Scene from '../../index/scene'
import { getCustomerList } from "../../../api/saas"
const util = require('../../../utils/util')
const event = require('../../../utils/event')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
type: 0,
height: app.globalData.fragmentHeight - 100,
loading: true,
requesting: false,
finished: false,
orderList: [],
form: {
name: '',
pageNum: 1,
pageSize: 15
},
page: 0,
index: 0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.type){
this.data.type = Number(options.type)
}
this.setData({ height: app.globalData.fragmentHeight - 100 })
event.on('EventMessage', this, this.onEvent)
this.fetchCustomerList()
},
onEvent: function(message){
if (message.what == 102) {
this.setData({ [`orderList[${this.data.page}][${this.data.index}]`]: message.detail })
}
},
onRefreshList: function () {
if (this.data.requesting) {
return
}
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
this.fetchCustomerList()
},
fetchCustomerList: function () {
if (this.data.requesting || this.data.finished) {
return
}
if (this.data.loading) {
this.data.requesting = true
} else {
this.setData({ requesting: true })
}
getCustomerList(this.data.form).then(result => {
if (result.data && result.data.records && 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), 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)
})
},
onChange: function({detail}) {
this.data.form.name = detail
},
onSearch: function(){
this.onRefreshList()
},
customerInfo: function(e){
this.data.page = e.currentTarget.dataset.page
this.data.index = e.currentTarget.dataset.index
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
if(this.data.type){
const channel = this.getOpenerEventChannel()
channel.emit('onCallback', { what: 130, detail: item })
wx.navigateBack()
} else {
if(util.isEmpty(item.userId)){
wx.navigateTo({ url: `/pages/home/customer-info/index?id=${item.id}` })
} else {
wx.navigateTo({ url: `/pages/home/customer-info/index?id=${item.id}&userId=${item.userId}` })
}
}
},
bindCustomer: function(e){
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
wx.navigateTo({ url: `/pages/client/registe/index?id=${item.id}` })
},
onUnload: function(){
event.remove('EventMessage', this)
}
})