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.
99 lines
3.1 KiB
99 lines
3.1 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: {
|
|
height: app.globalData.fragmentHeight - 100,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
top: 0,
|
|
orderList: [],
|
|
form: {
|
|
name: '',
|
|
pageNum: 1,
|
|
pageSize: 10
|
|
},
|
|
page: 0,
|
|
index: 0,
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
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()
|
|
},
|
|
//1:待定价,2:待过皮重,3:待过磅审核,4:待付款,5:已完成
|
|
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.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)
|
|
})
|
|
},
|
|
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(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)
|
|
}
|
|
})
|