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.
116 lines
3.1 KiB
116 lines
3.1 KiB
// pages/agent/index/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight - 100,
|
|
kg: app.globalData.kg,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
cateList: [],
|
|
cateScroll: false,
|
|
top: 0,
|
|
orderList: [],
|
|
form: {
|
|
firstCategoryId: '',
|
|
pageNum: 1
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({ height: app.globalData.fragmentHeight, kg: app.globalData.kg, CustomBar: app.globalData.CustomBar })
|
|
this.fetchCateList()
|
|
this.fetchGoodsList()
|
|
},
|
|
fetchCateList: function(){
|
|
request.post('/recycle-service/paperCategoryList', { type: 1 }).then(result => {
|
|
//成功回调
|
|
var cateList = [{id: '', name: '全部'}].concat(result.data)
|
|
this.setData({ cateList: cateList, cateScroll: cateList.length >= 5 })
|
|
})
|
|
},
|
|
onCategoryChange: function (e) {
|
|
if (this.data.form.firstCategoryId == e.detail.key) {
|
|
return
|
|
}
|
|
this.setData({ ['form.firstCategoryId']: e.detail.key })
|
|
this.onRefreshList()
|
|
},
|
|
// 下拉刷新...
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
orderList: [],
|
|
['form.pageNum']: 1,
|
|
loading: true,
|
|
finished: false
|
|
})
|
|
this.fetchGoodsList()
|
|
},
|
|
// 获取特价列表
|
|
fetchGoodsList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.loading) {
|
|
this.data.requesting = true
|
|
} else {
|
|
this.setData({ requesting: true })
|
|
}
|
|
// /purchase/get/product-list 获取店铺采购商品列表接口
|
|
request.get('/recycle-service/purchase/get/product-list', this.data.form).then(result => {
|
|
//成功回调
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList[${this.data.orderList.length}]`
|
|
var num = result.data.current
|
|
var finished = result.data.current >= result.data.pages
|
|
if(this.data.form.pageNum == 1){
|
|
this.setData({
|
|
[nowList]: respList,
|
|
total: result.data.total,
|
|
['form.pageNum']: (num + 1),
|
|
top: 0,
|
|
finished,
|
|
requesting: false,
|
|
loading: false
|
|
})
|
|
} else {
|
|
this.setData({
|
|
[nowList]: respList,
|
|
total: result.data.total,
|
|
['form.pageNum']: (num + 1),
|
|
finished,
|
|
requesting: false,
|
|
loading: false
|
|
})
|
|
}
|
|
} else {
|
|
this.setData({
|
|
finished: true,
|
|
requesting: false,
|
|
loading: false
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({
|
|
requesting: false,
|
|
finished: true,
|
|
loading: false
|
|
})
|
|
})
|
|
},
|
|
lookItem: function (e) {
|
|
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.navigateTo({ url: '/pages/purchase/detail/index?id=' + item.id })
|
|
}
|
|
|
|
})
|