// pages/home/customer/index.js import Scene from '../../index/scene' import { getChanelList, saveChanel, getAllFactoryList } from "../../../api/saas" const util = require('../../../utils/util') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { type: 0, height: app.globalData.fragmentHeight - 90, tabIndex: 0, tabList: [ {id: 0, name: '自有渠道', badge: 0, status: '' }, {id: 1, name: '千鸟渠道', badge: 0, status: 1 } // {id: 8, name: '已取消', badge: 0, status: 6 } ], loading: true, requesting: false, finished: false, top: 0, orderList: [], form: { name: '', pageNum: 1, pageSize: 10 }, nowItem: { name: '', }, show: false, requesting2: false, loading2: true, factoryList: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.type){ this.setData({ height: app.globalData.fragmentHeight - 90, type: Number(options.type )}) } else { this.setData({ height: app.globalData.fragmentHeight - 90 }) } this.fetchCustomerList() 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.fetchCustomerList() }, onRefreshList2: function () { if (this.data.requesting2) { return } this.setData({ factoryList: [], loading2: true }) this.fetchFactoryList() }, //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 }) } getChanelList(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) }) }, 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) }) } })