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

126 lines
3.7 KiB

// pages/process/supply/index.js
// import { getCategoryList, getProductList } from "../../api/mall"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const app = getApp()
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 页面的初始数据
*/
data: {
height: app.globalData.safeFragmentHeight - 190,
CustomBar: app.globalData.CustomBar,
userInfo: null,
firstShow: false,
tabIndex: 0,
tabList: [],
loading: true,
requesting: false,
finished: false,
top: 0,
orderList: [],
form: { categoryId: '', pageNum: 1, pageSize: 10 }
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
event.on('EventMessage', this, this.onEvent)
},
detached: function () {
event.remove('EventMessage', this)
}
},
methods: {
onRestart: function () {
if (this.data.firstShow) {
return
}
this.setData({ height: app.globalData.safeFragmentHeight - 190, CustomBar: app.globalData.CustomBar, userInfo: app.accountInfo })
this.fetchCategoryList()
this.fetchOrderList()
this.data.firstShow = true
},
onEvent: function (message) {
if (message.what == 888) {
this.setData({ userInfo: app.accountInfo })
}
},
fetchCategoryList: function(){
getCategoryList().then(result => {
this.setData({ tabList: [{id: '', name: '全部'}].concat(result.data) })
})
},
onTabChange: function ({detail}) {
if (this.data.tabIndex == Number(detail.index)) {
return
}
this.setData({ tabIndex: detail.index})
this.data.form.categoryId = this.data.tabList[this.data.tabIndex].id
this.onRefreshList()
},
onRefreshList: function () {
this.setData({
orderList: [],
['form.pageNum']: 1,
loading: true,
finished: false
})
this.fetchOrderList()
},
fetchOrderList: function () {
if (this.data.requesting || this.data.finished) {
return
}
if (this.data.loading) {
this.data.requesting = true
} else {
this.setData({ requesting: true })
}
getProductList(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)
})
},
lookItem: function (e) {
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
wx.navigateTo({ url: '/pages/process/purchase-detail/index?id=' + item.id })
},
searchList: function(){
wx.navigateTo({ url: '/pages/mall/search-list/index' })
}
}
})