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

230 lines
6.3 KiB

// pages/goods/index/index.js
const request = require('../../../utils/request'); //导入模块
const util = require('../../../utils/util');
const event = require('../../../utils/event.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight,
kg: app.globalData.kg,
loading: true,
requesting: false,
finished: false,
cateList: [],
cateScroll: false,
tabiList: [],
pageIndex: 0,
top: 0,
orderList: [],
form: {
firstCategoryId: '',
pageNum: 1
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
event.on('EventMessage', this, this.onEvent)
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
if(options.storeId){
this.data.form['storeId'] = options.storeId
}
this.fetchCateList()
this.fetchGoodsList()
},
onEvent: function (message) {
if (message.what == 412) {
this.onRefreshList()
}
},
onRefreshList: function () {
this.setData({
orderList: [],
['form.firstCategoryId']: this.data.form.firstCategoryId,
['form.pageNum']: 1,
loading: true,
finished: false
})
this.fetchGoodsList()
},
fetchCateList: function(){
request.post('/recycle-service/paperCategoryList', { type: 1 }).then(result => {
//成功回调
var tabList = ['全部']
var size = 0
for (let index = 0; index < result.data.length; index++) {
tabList.push(result.data[index].name)
size += result.data[index].name.length
}
this.data.cateList = result.data
this.setData({
tabiList: tabList,
cateScroll: size > 14,
height: app.globalData.fragmentHeight - 90,
kg: app.globalData.kg,
CustomBar: app.globalData.CustomBar
})
})
},
onCategoryChange: function ({detail}) {
if(this.data.pageIndex == Number(detail.index)){
return
}
this.data.pageIndex = Number(detail.index)
if(this.data.pageIndex == 0){
this.data.form.firstCategoryId = ''
} else {
this.data.form.firstCategoryId = this.data.cateList[this.data.pageIndex - 1].id
}
this.onRefreshList()
},
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/store-product-list 商家获取店铺采购商品列表接口
request.get('/recycle-service/purchase/get/store-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 = this.data.form.pageNum
var finished = this.data.form.pageNum >= 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,
loading: false
})
util.showToast(err)
})
},
editItem: function (e) {
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
wx.navigateTo({
url: '/pages/purchase/create/index?id=' + item.id
})
},
shelvesItem: function (e) {
var page = e.currentTarget.dataset.page
var index = e.currentTarget.dataset.index
var item = this.data.orderList[page][index]
var that = this
if(item.status == 1){
this.wuxDialog.open({
resetOnClose: true,
title: '温馨提示',
content: '确定下架该商品?',
buttons: [{
text: '取消'
}, {
text: '确定',
type: 'primary',
onTap(e) {
that.statusItem(item, page, index, 2)
}
}]
})
} else {
that.statusItem(item, page, index, 1)
}
},
statusItem: function(item, page, index, status){
wx.showLoading({ title: '处理中', mask: true })
// /purchase/update/product-status 上架下架采购商品接口
request.post('/recycle-service/purchase/update/product-status', {productId: item.id, status}).then(result => {
//成功回调
this.setData({ ['orderList[' + page + '][' + index + '].status']: status })
wx.hideLoading()
if(status == 2){
util.showToast('采购下架成功!')
} else {
util.showToast('采购上架成功!')
}
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
removeItem: function (e) {
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
var that = this
this.wuxDialog.open({
resetOnClose: true,
title: '温馨提示',
content: '确定删除该采购信息?',
buttons: [{
text: '取消'
}, {
text: '确定',
type: 'primary',
onTap(e) {
that.deleteItem(item)
}
}]
})
},
deleteItem: function(item){
wx.showLoading({ title: '处理中', mask: true })
// // /purchase/delete/product删除采购商品接口
request.post('/recycle-service/purchase/delete/product', {productId: item.id}).then(result => {
//成功回调
wx.hideLoading()
this.onRefreshList()
util.showToast('商品删除成功!')
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
onTabChange: function (e) {
if (this.data.form.bidType == e.detail.key) {
return
}
this.data.form.bidType = e.detail.key
this.data.form.firstCategoryId = ''
this.onRefreshList()
},
onUnload: function(){
event.remove('EventMessage', this)
}
})