collect_list.js
6.6 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
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;
Page({
data: {
url: e.globalData.setting.imghost,
resourceUrl: e.globalData.setting.resourceUrl,
iurl: e.globalData.setting.imghost,
collects: null,
currentPage: 1,
curpage: 1,
collects_Recommend: [],
ismore: 0,
iscollects: 0,
loadName: null,
editEd: 0, //商品编辑按钮是否点击
isall: false, //是否全选
sum: 0,
total_collects:0,
total_goods:0,
pageSize:8,//分页数量
},
onLoad: function() {
o.init(this, "", "collects"),
this.requestCollectList();
// this.requestList();
},
requestCollectList: function() {
isShowLoading: 0;
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)
th.setData({ iscollects: 1, total_collects:e.data.data.total})
if (th.data.total_collects<th.data.pageSize){
th.requestList();
}
});
},
//--到底部刷新---
onReachBottom: function() {
if (this.data.currentPage*this.data.pageSize<this.data.total_collects){
this.requestCollectList();
}else{
this.requestList();
}
},
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.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = this.data.url + "/miniapp/images/del/logo.jpg";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
//图片失败,默认图片
bind_bnerr2: function(e) {
var _errImg = e.target.dataset.errorimg;
var th = this;
this.setData({
[_errImg]: th.data.iurl + "/miniapp/images/default_g_img.gif",
})
},
requestList: function() {
this.setData({
loadName: '加载中...'
})
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) {
// e.goto("/pages/index/index/index");
wx.switchTab({
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,
})
} else {
t.select_checked(false, null)
t.setData({
editEd: 0
})
}
},
iconClick: function(e) {
var th = this.data;
var index = e.currentTarget.dataset.index;
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;
//判断是否全选
if (th.data.isall) {
for (var i = 0; i <= th.data.collects.length; i++) {
var collect = "collects[" + i + "].checked";
this.setData({
[collect]: false,
isall: 0
})
}
this.setData({
sum: 0
})
} else {
for (var i = 0; i <= th.data.collects.length; i++) {
var collect = "collects[" + i + "].checked";
this.setData({
[collect]: true,
isall: 1
})
}
this.setData({
sum: th.data.collects.length
})
}
},
//分页删除
alldelete: function(e) {
var th = this;
// 全选的话直接删除
if (th.data.isall) {
a.delete("/api/weshop/goodscollect/removeUser/" + oo.stoid + "/" + app_d.user_id, {
isShowLoading: 0,
success: function(e) {
th.setData({
collects: []
})
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]);
}
}
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
})
// 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
})
}
}else{
var collect = "collects[" + sum + "].checked";
th.setData({
[collect]: check
})
}
}
});