113 lines
2.4 KiB
JavaScript
113 lines
2.4 KiB
JavaScript
// packageE/groupCode/groupCodeGoodsList/groupCodeGoodsList.js
|
|
var n = 1;
|
|
var app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
groupId: '',
|
|
|
|
goods: [],
|
|
allLoaded: true,
|
|
loading: false,
|
|
classifyBol: true,
|
|
goods_template: '',
|
|
requestLoading: true,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if (options.id) {
|
|
this.setData({groupId: options.id});
|
|
}
|
|
this.getData();
|
|
},
|
|
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
getData (page=1) {
|
|
let that = this;
|
|
let urlStr = app.getNetAddresss("plugin.group-code.api.group-code.get-goods");
|
|
app._getNetWork({
|
|
showToastIn: false,
|
|
url: urlStr,
|
|
data: {
|
|
id: that.data.groupId,
|
|
page: page
|
|
},
|
|
success: function (resdata) {
|
|
var res = resdata.data;
|
|
if (res.result == 1) {
|
|
that.setData({
|
|
loading: false,
|
|
allLoaded: false
|
|
});
|
|
// 搜索结果为空
|
|
if (res.data.data.length <= 0) {
|
|
that.setData({
|
|
loading: true,
|
|
allLoaded: true
|
|
});
|
|
return;
|
|
}
|
|
// 如果当前页数大于总页数 就不加载了
|
|
if (res.data.current_page > res.data.last_page) {
|
|
that.setData({
|
|
loading: true,
|
|
allLoaded: true
|
|
});
|
|
return;
|
|
}
|
|
let goods = that.data.goods;
|
|
goods.push(...res.data.data);
|
|
for (let i = 0; i < goods.length; i++) {
|
|
if (parseInt(Number(goods[i].market_price == 0))) {
|
|
goods[i].notMarket_price = 0;
|
|
} else {
|
|
goods[i].notMarket_price = 1;
|
|
}
|
|
}
|
|
that.setData({
|
|
goods: goods,
|
|
requestLoading: false
|
|
});
|
|
if (res.data.data.length < 15) {
|
|
that.setData({
|
|
loading: true,
|
|
allLoaded: true
|
|
});
|
|
return;
|
|
}
|
|
}else{
|
|
that.setData({
|
|
requestLoading: false
|
|
});
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
|
|
}
|
|
});
|
|
},
|
|
|
|
onReachBottom: function () {
|
|
if (!this.data.allLoaded) {
|
|
n++;
|
|
let loading = true;
|
|
this.getData(n, loading);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}); |