special_list.js
15.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
// pages/index/special_list/special_list.js
const app=getApp();
Page({
/**
* 页面的初始数据
*/
data: {
imgUrl: app.globalData.imgUrl,
id:0,
special_list:[],
info:{},
show_cart_mask:false,
goods_id:0,
item:1,
sku_values:'',
idss:[],
skuid:-1,
skuid_price:0,
old_skuid_price:0,
vip_skuid_price:0,
skuid_arr:[],
stock:-1
},
//加购筛选
// changeIds(e) {
// let t = this;
// let goods_item = t.data.goods_item;
// let listAll = t.data.goods_item.attr.attr_sku;
// let list = listAll[e.currentTarget.dataset.parent].item;
// let x = e.currentTarget.dataset.index;
// // 当前点击Id
// let nowId = e.currentTarget.dataset.id;
// //当前点击value
// let nowValue = e.currentTarget.dataset.item;
// // 父级索引
// let parent = e.currentTarget.dataset.parent;
// // 子集索引
// let nowIndex = e.currentTarget.dataset.index;
// // 当前可否多选
// let is_checkMore = false
// let new_arr = t.data.skuid_arr
// let foo = new_arr.indexOf(nowId)
// if (foo > -1) {
// new_arr.splice(foo, 1)
// } else {
// goods_item.attr.attr_sku.forEach(function (ele, indexxxx) {
// if (indexxxx == parent) {
// for (let i = 0; i < ele.item.length; i++) {
// let havId = goods_item.attr.attr_sku[indexxxx].item[i].id
// let have = new_arr.indexOf(havId)
// if (have > -1) {
// new_arr.splice(have, 1)
// }
// }
// }
// })
// }
// // 当前点击父级值
// let tempArry = JSON.parse(JSON.stringify(this.data.goods_item.attr.attr_sku[parent]));
// !tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
// !tempArry.chooseValue ? tempArry.chooseValue = [] : '';
// // 是否多选
// if (is_checkMore) { } else {
// tempArry.chooseValue.pop();
// tempArry.chooseValue.push(nowValue);
// tempArry.chooseIndex.pop();
// console.log(tempArry.chooseIndex)
// tempArry.chooseIndex.push(nowId);
// for (let obj of tempArry.item) {
// obj.t = false
// }
// tempArry.item[nowIndex].t = true;
// }
// this.data.goods_item.attr.attr_sku[parent] = tempArry;
// this.setData({
// goods_item: this.data.goods_item
// })
// let sys_attrprice = goods_item.sys_attrprice;
// // let new_arr = []
// // let new_arr_item=[];
// let str = ''
// let skuid = 0
// let skuid_price = 0
// let old_skuid_price = 0
// let vip_skuid_price = 0
// let sku_values = ''
// goods_item.attr.attr_sku.forEach(function (ele, indexx) {
// if (indexx == parent) {
// new_arr = new_arr.concat(ele.chooseIndex);
// }
// })
// new_arr = new_arr.sort()
// str = new_arr.join('_');
// console.log(new_arr)
// console.log(str + "组合后的str")
// for (let i in sys_attrprice) {
// if (i == str) {
// skuid = sys_attrprice[i].skuid
// skuid_price = sys_attrprice[i].price
// old_skuid_price = sys_attrprice[i].old_price
// vip_skuid_price = sys_attrprice[i].vip_price
// sku_values = sys_attrprice[i].sku_values
// }
// }
// this.setData({
// idss: new_arr,
// skuid: skuid,
// skuid_price: skuid_price,
// old_skuid_price: old_skuid_price,
// vip_skuid_price: vip_skuid_price,
// skuid_arr: new_arr,
// sku_values: sku_values
// });
// console.log(skuid + "组合后的id值")
// },
//加购筛选
changeIds(e) {
let t = this;
let goods_item = t.data.goods_item;
let listAll = t.data.goods_item.attr.attr_sku;
let list = listAll[e.currentTarget.dataset.parent].item;
let x = e.currentTarget.dataset.index;
// 当前点击Id
let nowId = e.currentTarget.dataset.id;
//当前点击value
let nowValue = e.currentTarget.dataset.item;
// 父级索引
let parent = e.currentTarget.dataset.parent;
// 子集索引
let nowIndex = e.currentTarget.dataset.index;
// 当前可否多选
let is_checkMore = false
let new_arr = t.data.skuid_arr
let foo = new_arr.indexOf(nowId)
if (foo > -1) {
new_arr.splice(foo, 1)
} else {
goods_item.attr.attr_sku.forEach(function (ele, indexxxx) {
if (indexxxx == parent) {
for (let i = 0; i < ele.item.length; i++) {
let havId = goods_item.attr.attr_sku[indexxxx].item[i].id
let have = new_arr.indexOf(havId)
if (have > -1) {
new_arr.splice(have, 1)
}
}
}
})
}
// 当前点击父级值
let tempArry = JSON.parse(JSON.stringify(this.data.goods_item.attr.attr_sku[parent]));
!tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
!tempArry.chooseValue ? tempArry.chooseValue = [] : '';
// 是否多选
if (is_checkMore) { } else {
tempArry.chooseValue.pop();
tempArry.chooseValue.push(nowValue);
tempArry.chooseIndex.pop();
console.log(tempArry.chooseIndex)
tempArry.chooseIndex.push(nowId);
for (let obj of tempArry.item) {
obj.t = false
}
tempArry.item[nowIndex].t = true;
}
this.data.goods_item.attr.attr_sku[parent] = tempArry;
this.setData({
goods_item: this.data.goods_item
})
let sys_attrprice = goods_item.sys_attrprice;
// let new_arr = []
// let new_arr_item=[];
let str = ''
let skuid = 0
let skuid_price = 0
let old_skuid_price = 0
let vip_skuid_price = 0
let sku_values = ''
goods_item.attr.attr_sku.forEach(function (ele, indexx) {
if (indexx == parent) {
new_arr = new_arr.concat(ele.chooseIndex);
}
})
new_arr = new_arr.sort()
str = new_arr.join('_');
console.log(new_arr)
console.log(str + "组合后的str")
for (let i in sys_attrprice) {
if (i == str) {
skuid = sys_attrprice[i].skuid
skuid_price = sys_attrprice[i].price
old_skuid_price = sys_attrprice[i].old_price
vip_skuid_price = sys_attrprice[i].vip_price
sku_values = sys_attrprice[i].sku_values
}
}
this.setData({
idss: new_arr,
skuid: skuid,
skuid_price: skuid_price,
old_skuid_price: old_skuid_price,
vip_skuid_price: vip_skuid_price,
skuid_arr: new_arr,
sku_values: sku_values
});
console.log(skuid + "组合后的id值")
},
//返回
get_back(){
wx.navigateBack({
})
},
//渲染专题列表
fetchSpecialList(){
let url ='/wxapp/product/getSpecialList'
var params={
id:this.data.id
}
app.post(url, params).then(r=>{
console.log(r);
this.setData({
special_list: r.data.list,
info: r.data.info
});
});
},
//点击轮播图跳转相应页面
jump(e){
var jump=e.currentTarget.dataset.url
wx.navigateTo({
url:'../../navigate/navigate??url='+jump
})
},
// 跳转商品详情
get__itemDetial(e) {
wx.navigateTo({
url: '/pages/index/goodsDetial/goodsDetial?id=' + e.currentTarget.dataset.goods
})
},
//渲染商品列表
fetchGoodsData() {
let id = this.data.goods_id;
let url = '/wxapp/product/getProductInfo?id=' + id
let stock=this.data.stock
let sku_values=''
app.post(url).then(r => {
if (r.code == 1) {
for (let i = 0; i < r.data.attr.attr_sku.length; i++) {
for (let x = 0; x < r.data.attr.attr_sku[i].item.length; x++) {
r.data.attr.attr_sku[i].item[x].t = false;
}
}
let skuid = 0;
let skuid_price = 0
let old_skuid_price = 0
let vip_skuid_price = 0
let arr = []
r.data.attr.attr_sku.forEach(function (ele, index) {
ele.item[0].t = true;
arr.push(ele.item[0].id)
sku_values += ele.item[0].attribute_value
})
arr = arr.sort()
let str = arr.join('_');
let sys_attrprice = r.data.sys_attrprice
for (let i in sys_attrprice) {
if (i == str) {
skuid = sys_attrprice[i].skuid
skuid_price = sys_attrprice[i].price
old_skuid_price = sys_attrprice[i].old_price
vip_skuid_price = sys_attrprice[i].vip_price
stock: sys_attrprice[i].stock
}
}
this.setData({
goods_item: r.data,
// skuid_price: r.data.info.price,
skuid_price: skuid_price,
// old_skuid_price: r.data.info.old_price,
old_skuid_price: old_skuid_price,
// vip_skuid_price: r.data.info.vip_price,
vip_skuid_price: vip_skuid_price,
skuid: skuid,
skuid_arr: arr,
stock:stock,
sku_values:sku_values
});
} else {
wx.showToast({
title: r.msg,
icon: 'none'
})
}
});
},
//点击进入商品详情
get_goodsDetial(e){
wx.navigateTo({
url: '../goodsDetial/goodsDetial?id='+e.currentTarget.dataset.id,
})
},
//点击商品列表显示加购弹框
show_cart_mask(e) {
let id = e.currentTarget.dataset.goods;
this.setData({
show_cart_mask: true,
goods_id: id
});
this.fetchGoodsData();
},
//关闭加购框
close_jump_msk() {
this.setData({
show_cart_mask: false
});
},
//点击添加购物车数量
dec_item() {
let item = this.data.item;
if (item <= 1) {
return;
}
item--;
this.setData({
item: item
});
},
add_item() {
let item = this.data.item;
item++;
this.setData({
item: item
});
},
//点击加入购物车
jump_cart_id(e) {
let id = this.data.goods_id
let url = '/wxapp/cart/addCart'
let limit=e.currentTarget.dataset.limit
let stock=this.data.stock
let params = {
skuid: this.data.skuid,
num: this.data.item
}
if(stock>=this.data.item){
if (limit >= this.data.item || limit == 0) {
app.post(url, params).then(r => {
if (r.code == 1) {
wx.showToast({
title: r.msg,
icon: 'none'
})
} else {
wx.showToast({
title: r.msg,
icon: 'none'
})
}
});
} else {
wx.showToast({
title: '限购' + limit + '件',
icon: 'none'
})
}
}else{
wx.showToast({
title: '已经售罄',
icon:'none'
})
}
this.setData({
show_cart_mask: false
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
});
this.fetchSpecialList();
this.fetchGoodsData();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})