cardList.js
5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// pages/i_service/cardList/cardList.js
const app = getApp();
let self = null;
Page({
/**
* 页面的初始数据
*/
data: {
list: null,
isLoading: false, // 检测是否已经发送请求,防止重复发送请求
noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据
pageNum: 1, // 当前页数
currentQuery: {
store_id: app.globalData.setting.stoid,
},
default_img: '/miniapp/images/default_g_img.gif',
object:null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
self = this;//保存全局指针
app.isLogin().then(function(data) {//进入页面前已经授权登录成功
self.setData({
userInfo: data,
imghost: app.globalData.setting.imghost,
});
});
var url="/api/weshop/store_module/gets/"+app.globalData.setting.stoid+"/0/5";
getApp().promiseGet(url,{}).then(res=>{
if(res.data.code==0 && res.data.data && res.data.data.length>0){
var json=JSON.parse(res.data.data[0].json_str);
var content=json[0].content;
self.setData({object:content});
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let url = '/api/weshop/serviceCard/page';
let currentQuery = this.data.currentQuery;
if(app.globalData.userInfo) {
if(!this.data.isLogin) {
this.setData({
userInfo: app.globalData.userInfo,
imghost: app.globalData.setting.imghost,
isLogin: true,
});
currentQuery.page=1;
this.getData(true, url, currentQuery);
// app.request.promiseGet("/api/weshop/ad/page?pid=2&store_id=" + app.globalData.setting.stoid, {
// data: {
// enabled: 1
// }
// }).then(res => {
// console.log('res==>1', res);
// });
app.request.promiseGet("/api/weshop/ad/page?pid=2&store_id=" + app.globalData.setting.stoid, {
data: {
enabled: 1
}
}).then(res => {
if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){
var a = res.data.data.pageData;
var arr = new Array();
for (var i = 0; i < a.length; i++) {
var tt = {
'ad_code': self.data.imghost + a[i].ad_code,
'media_link': '',
'ad_weapplink':a[i].ad_weapplink
};
arr.push(tt);
}
if (arr.length > 0) self.setData({
banner: arr,
});
console.log('banner==>', arr);
wx.stopPullDownRefresh();
}
})
};
};
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.scrollToLower('/api/weshop/serviceCard/page', this.data.currentQuery);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
/**
* promiseGet请求数据
*/
getData: function(isInit, url, data,callback) {
app.request.promiseGet(url, {
data: data,
isShowLoading: true,
})
.then(function(res) {
// console.log('1121', res.data.code);
if(res.data.code == 0) {
self.setData({
isLoading: false
});
if(isInit) {// 第一次加载
self.setData({
list: res.data.data
});
} else {
self.setData({
'list.pageData': self.data.list.pageData.concat(res.data.data.pageData)
});
};
if((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) {
self.setData({
noMore: true
});
};
} else {
self.setData({
'list.pageData': []
});
};
if(callback) callback();
})
.catch(function(err) {
console.log('出错拉!!!!',err);
self.setData({
'list.pageData': []
});
if(callback) callback();
});
},
/**
* 上拉加载数据
*/
scrollToLower(url, requestData, callback) {
// 数据总量
let total = this.data.list.total;
// 单页最大数据量
let pageSize = this.data.list.pageSize;
// 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’
if((total != 0)&&(total <= pageSize)) {
this.setData({
noMore: true
});
};
if(!this.data.isLoading && !this.data.noMore) {
this.setData({
isLoading: true,
pageNum: this.data.pageNum + 1
});
requestData.page = this.data.pageNum;
this.getData(false, url, requestData,callback)
};
},
go_goods: function(e) {
var gid = e.currentTarget.dataset.gid;
var url = "/packageA/pages/goodsInfo/goodsInfo?goods_id=" + gid;
app.goto(url);
},
//图片失败,默认图片
bind_bnerr: function(e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = "/miniapp/images/default_g_img.gif";
this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
})