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.
165 lines
4.8 KiB
165 lines
4.8 KiB
// pages/home/customer/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getChanelList, saveChanel } from "../../../api/saas"
|
|
import { getAllFactoryList } from "../../../api/ztb"
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
type: 0,
|
|
height: app.globalData.fragmentHeight,
|
|
tabIndex: 0,
|
|
tabList: [
|
|
{id: 0, name: '自有渠道', badge: 0, status: '' },
|
|
{id: 1, name: '千鸟渠道', badge: 0, status: 1 }
|
|
],
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
top: 0,
|
|
orderList: [],
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize: 20
|
|
},
|
|
nowItem: {
|
|
name: '',
|
|
},
|
|
show: false,
|
|
requesting2: false,
|
|
loading2: true,
|
|
factoryList: [],
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(options.type){
|
|
this.setData({ height: app.globalData.fragmentHeight, type: Number(options.type )})
|
|
} else {
|
|
this.setData({ height: app.globalData.fragmentHeight })
|
|
}
|
|
this.fetchList()
|
|
// this.fetchFactoryList()
|
|
},
|
|
onTabChange: function ({detail}) {
|
|
if (this.data.tabIndex == Number(detail.index)) {
|
|
return
|
|
}
|
|
this.setData({ tabIndex: detail.index })
|
|
if(this.data.tabIndex == 2 && this.data.factoryList.length <= 0){
|
|
this.fetchFactoryList()
|
|
}
|
|
},
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchList()
|
|
},
|
|
onRefreshList2: function () {
|
|
if (this.data.requesting2) {
|
|
return
|
|
}
|
|
this.setData({ factoryList: [], loading2: true })
|
|
this.fetchFactoryList()
|
|
},
|
|
fetchList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
getChanelList(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), 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)
|
|
})
|
|
},
|
|
fetchFactoryList: function(){
|
|
if (this.data.requesting2) {
|
|
return
|
|
}
|
|
if (this.data.loading2) {
|
|
this.data.requesting2 = true
|
|
} else {
|
|
this.setData({ requesting2: true })
|
|
}
|
|
getAllFactoryList().then(result => {
|
|
this.setData({ factoryList: result.data, requesting2: false, loading2: false })
|
|
}).catch(err => {
|
|
this.setData({ requesting2: false, loading2: false })
|
|
})
|
|
},
|
|
onChange: function({detail}) {
|
|
this.data.form.name = detail
|
|
},
|
|
onSearch: function(){
|
|
this.onRefreshList()
|
|
},
|
|
showDialog: function(){
|
|
this.setData({ show: true, nowItem: { name: ''} })
|
|
},
|
|
bindInput: function({detail}){
|
|
this.data.nowItem.name = detail.value
|
|
},
|
|
onClose: function(){
|
|
this.setData({ show: false })
|
|
},
|
|
lookItem: function(e){
|
|
if(this.data.tabIndex == 0){
|
|
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
if(this.data.type == 1){
|
|
const channel = this.getOpenerEventChannel()
|
|
channel.emit('onCallback', { what: 140, detail: item })
|
|
wx.navigateBack()
|
|
return
|
|
}
|
|
this.setData({ show: true ,nowItem: item })
|
|
} else {
|
|
var item = this.data.factoryList[e.currentTarget.dataset.index]
|
|
const channel = this.getOpenerEventChannel()
|
|
channel.emit('onCallback', { what: 140, detail: item })
|
|
wx.navigateBack()
|
|
}
|
|
},
|
|
onConfirm: function(){
|
|
if (util.isEmpty(this.data.nowItem.name)) {
|
|
util.showToast('请输入纸厂名称')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
saveChanel(this.data.nowItem).then(result => {
|
|
wx.hideLoading()
|
|
if(this.data.nowItem.id){
|
|
util.showToast('修改成功!')
|
|
} else {
|
|
util.showToast('添加成功!')
|
|
}
|
|
this.onRefreshList()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
})
|