|
|
|
@ -0,0 +1,131 @@ |
|
|
|
// pages/goods/index/index.js
|
|
|
|
import { paperCategoryList, getProductList } from "../../../../api/ztb" |
|
|
|
const event = require('../../../../utils/event') |
|
|
|
const app = getApp() |
|
|
|
|
|
|
|
Component({ |
|
|
|
options: { |
|
|
|
addGlobalClass: true, |
|
|
|
multipleSlots: true |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
height: app.globalData.fragmentHeight - 90, |
|
|
|
kg: app.globalData.kg, |
|
|
|
loading: true, |
|
|
|
requesting: false, |
|
|
|
finished: false, |
|
|
|
cateList: [], |
|
|
|
tabList: [], |
|
|
|
tabIndex: 0, |
|
|
|
cateScroll: false, |
|
|
|
top: 0, |
|
|
|
orderList: [], |
|
|
|
form: { |
|
|
|
firstCategoryId: '', |
|
|
|
pageNum: 1, |
|
|
|
pageSize:15 |
|
|
|
} |
|
|
|
}, |
|
|
|
lifetimes: { |
|
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
|
|
attached: function () { |
|
|
|
event.on('EventMessage', this, this.onEvent) |
|
|
|
}, |
|
|
|
detached: function () { |
|
|
|
event.remove('EventMessage', this) |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
onRestart: function(){ |
|
|
|
if (!this.data.firstShow) { |
|
|
|
this.setData({ height: app.globalData.fragmentHeight - 90, kg: app.globalData.kg }) |
|
|
|
this.fetchCateList() |
|
|
|
this.fetchGoodsList() |
|
|
|
} |
|
|
|
this.data.firstShow = true |
|
|
|
}, |
|
|
|
fetchCateList: function(){ |
|
|
|
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({ tabList: tabList, cateScroll: size > 14 }) |
|
|
|
}) |
|
|
|
}, |
|
|
|
onCategoryChange: function ({detail}) { |
|
|
|
if(this.data.tabIndex == Number(detail.index)){ |
|
|
|
return |
|
|
|
} |
|
|
|
this.data.tabIndex = Number(detail.index) |
|
|
|
if(this.data.tabIndex == 0){ |
|
|
|
this.data.form.firstCategoryId = '' |
|
|
|
} else { |
|
|
|
this.data.form.firstCategoryId = this.data.cateList[this.data.tabIndex - 1].id |
|
|
|
} |
|
|
|
this.onRefreshList() |
|
|
|
}, |
|
|
|
// 下拉刷新...
|
|
|
|
onRefreshList: function () { |
|
|
|
if (this.data.requesting) { |
|
|
|
return |
|
|
|
} |
|
|
|
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 }) |
|
|
|
} |
|
|
|
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 = 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, loading: false }) |
|
|
|
}) |
|
|
|
}, |
|
|
|
lookItem: function (e) { |
|
|
|
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index] |
|
|
|
wx.navigateTo({ url: '/submodel/pages/purchase/detail/index?id=' + item.id }) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |