collect_list.js
7.28 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
var t = function(t) {
return t && t.__esModule ? t : {
default: t
};
}(require("../../../utils/LoadMore.js")),
e = getApp(),
a = e.request,
o = new t.default();
var oo = e.globalData.setting,
app_d = e.globalData;
var ut = require('../../../utils/util.js');
Page({
data: {
url: e.globalData.setting.imghost,
resourceUrl: e.globalData.setting.resourceUrl,
iurl: e.globalData.setting.imghost,
collects: null,
currentPage: 1,
curpage: 1,
ismore: 0,
iscollects: 0,
editEd: 0, //商品编辑按钮是否点击
isall: false, //是否全选
sum: 0,
total_collects: 0,
is_goods: 0,
pageSize: 8, //分页数量
isdelete: 0
},
onLoad: function() {
o.init(this, "", "collects"),
this.requestCollectList();
},
requestCollectList: function() {
var th = this;
e = "/api/weshop/goodscollect/list?" + "pageSize=" + th.data.pageSize + "&user_id=" +
app_d.user_id + "&store_id=" + oo.stoid + "&page=" + th.data.currentPage;
o.request(e, function(e) {
th.data.currentPage++;
if (th.data.total_collects == 0) {
th.setData({
iscollects: 1,
total_collects: e.data.data.total
})
}
if (th.data.total_collects < th.data.pageSize) {
th.setData({
is_goods: 1
})
var goods_list = th.selectComponent("#goods_recommend"); //组件的id
goods_list.init();
setTimeout(function () { goods_list.get_list(); }, 300)
}
});
},
//--到底部刷新---
onReachBottom: function() {
if ((this.data.currentPage - 1) * this.data.pageSize < this.data.total_collects) {
this.requestCollectList();
} else {
if (this.data.is_goods == 0) this.setData({
is_goods: 1
});
var goods_list = this.selectComponent("#goods_recommend"); //组件的id
goods_list.get_list();
}
},
//--取消收藏---
cancelCollect: function(t) {
var e = t.currentTarget.dataset.id,
o = this;
a.delete("/api/weshop/goodscollect/del/" + oo.stoid + "/" + e, {
success: function(t) {
o.deleteItemData(e);
}
});
},
deleteItemData: function(t) {
for (var e = 0; e < this.data.collects.length; e++)
if (this.data.collects[e].collect_id == t) {
this.data.collects.splice(e, 1), this.setData({
collects: this.data.collects
});
break;
}
},
//图片失败,默认图片
bind_bnerr: function(e) {
var _errImg = e.currentTarget.dataset.errimg;
var _errObj = {};
_errObj[_errImg] = this.data.iurl + "/miniapp/images/default_g_img.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
requestList: function() {
var e = this;
a.get("/api/weshop/goods/page", {
isShowLoading: 0,
data: {
store_id: 1,
user_id: oo.user_id,
page: e.data.curpage,
pageSize: 10
},
success: function(t) {
e.data.curpage++;
var arr1 = e.data.collects_Recommend;
var arr2 = t.data.data.pageData;
var arr3 = [...arr1, ...arr2];
var ismore = 0;
if (arr3.length == t.data.data.total) ismore = 1
e.setData({
collects_Recommend: arr3,
total_goods: t.data.data.total,
ismore_goods: ismore,
loadName: null
}), wx.stopPullDownRefresh();
}
});
},
goto: function(ee) {
wx.navigateTo({
url: '/pages/index/index/index',
})
},
//编辑商品显示
editcollects: function() {
var th = this.data;
var t = this;
if (th.editEd == 0) {
t.select_checked(false, null)
t.setData({
editEd: 1,
isall:0
})
} else {
t.select_checked(false, null)
t.setData({
editEd: 0
})
}
},
iconClick: function(e) {
var th = this.data;
var index = e.currentTarget.dataset.index;
var url = e.currentTarget.dataset.url;
var item=this.data.collects[index];
if(url){
console.log("---");
console.log(item.add_time);
console.log(ut.gettimestamp());
if(ut.gettimestamp()-item.add_time<3600*24 && item.guide_id>0)
url+="&c_guide_id="+item.guide_id;
getApp().goto(url);
return false;
}
var collect = "collects[" + index + "].checked";
if (this.data.collects[index].checked == true) {
this.setData({
[collect]: false,
isall: 0,
sum: --th.sum
})
} else {
var id = th.collects[index].collect_id;
this.setData({
[collect]: true,
sum: ++th.sum
})
if (th.sum == th.collects.length) {
this.setData({
isall: 1
})
}
}
},
//全选为收藏商品checked为true
allClick: function() {
var th = this;
var list = th.data.collects;
//判断是否全选
if (th.data.isall) {
for (var i = 0; i < list.length; i++) {
list[i].checked = false;
}
this.setData({
sum: 0,
isall: 0,
collects: list
})
} else {
for (var i = 0; i < list.length; i++) {
list[i].checked = true;
}
this.setData({
sum: th.data.collects.length,
collects: list,
isall: 1
})
}
},
//分页删除
alldelete: function(e) {
var th = this;
if (th.data.isdelete) return false;
// 全选的话直接删除
if (th.data.isall) {
a.delete("/api/weshop/goodscollect/removeUser/" + oo.stoid + "/" + app_d.user_id, {
isShowLoading: 0,
success: function(e) {
th.setData({
collects: [],
total_collects: 0,
isdelete:0
})
getApp().my_warnning("取消成功", 1, th);
}
})
} else { //按照多个id删除收藏商品
var new_colls = [];
var collectId = th.data.collects;
var str = "";
for (var i = 0; i < th.data.collects.length; i++) {
if (collectId[i].checked) {
str += collectId[i].collect_id + ",";
} else {
new_colls.push(collectId[i]);
}
}
if(str.length==""){
getApp().my_warnning("请选择商品", 0, th);
return false;
}
th.setData({
isdelete: 1
})
str = str.substr(0, str.length - 1);
var url = "/api/weshop/goodscollect/removeByIds/" + oo.stoid + "/" + app_d.user_id + "/" + str;
a.delete(url, {
isShowLoading: 0,
success: function(e) {
th.setData({
collects: new_colls,
sum: 0,
total_collects: new_colls.length,
isdelete: 0
})
// th.select_checked(false,null);
getApp().my_warnning("取消收藏成功", 1, th);
}
})
}
},
select_checked: function(check, sum) {
var th = this;
if (sum == null) {
for (var i = 0; i < this.data.collects.length; i++) {
var collect = "collects[" + i + "].checked";
th.setData({
[collect]: check,
sum:0
})
}
} else {
var collect = "collects[" + sum + "].checked";
th.setData({
[collect]: check
})
}
},
go_to: function(e) {
var th = this;
var url = e.currentTarget.dataset.url;
getApp().goto(url);
}
});