select_index.js
13.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
// pages/index/select_index/select_index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
ids: [],
goods: [],
imgUrl: app.globalData.imgUrl,
wangge: 0,
show_cart_mask: false,
value: '',
goods_item: [],
goods_id: 0,
skuid_price: 0,
old_skuid_price: 0,
vip_skuid_price: 0,
skuid_arr: [],
skuid: 0,
item: 1,
sku_values: ''
},
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值")
},
//点击添加购物车数量
dec_item() {
let item = this.data.item;
if (item <= 1) {
wx.showToast({
title: '已经是最少了哦',
icon: 'none'
})
return;
}
item--;
this.setData({
item: item
});
},
add_item() {
let item = this.data.item;
item++;
this.setData({
item: item
});
},
//根据传过来的ids获取渲染数据
fetchGoodsLists() {
let ids = this.data.ids;
let url = '/wxapp/product/getProductListByScreen'
let params = {
ids: this.data.ids,
}
app.post(url, params).then(r => {
this.setData({
goods: r.data.list
});
console.log(this.data.goods)
});
},
//切换网格列表状态
changeWangGe0() {
this.setData({
wangge: 0
});
},
changeWangGe1() {
this.setData({
wangge: 1
});
},
changeWangGe2() {
this.setData({
wangge: 2
});
},
// 跳转商品详情
get_goodsDetial(e) {
wx.navigateTo({
url: '/pages/index/goodsDetial/goodsDetial?id=' + e.currentTarget.dataset.goods
})
},
//点击商品列表显示加购弹框
show_cart_mask(e) {
let id = e.currentTarget.dataset.goods;
this.setData({
show_cart_mask: true,
goods_id: id
});
this.fetchGoodsData();
},
//点击加入购物车
jump_cart_id(e) {
let id = this.data.goods_id
let url = '/wxapp/cart/addCart'
let params = {
skuid: this.data.skuid,
num: this.data.item
}
if (e.currentTarget.dataset.limit >= this.data.item || e.currentTarget.dataset.limit == 0) {
app.post(url, params).then(r => {
console.log(r)
if (r.code == 1) {
wx.showToast({
title: '添加购物车成功',
icon: 'none'
})
} else {
wx.showToast({
title: r.msg,
icon: 'none'
})
}
});
} else {
wx.showToast({
title: '限购' + e.currentTarget.dataset.limit + '件',
icon: 'none'
})
}
this.setData({
show_cart_mask: false,
item: 1
});
},
fetchGoodsData() {
let id = this.data.goods_id;
let url = '/wxapp/product/getProductInfo?id=' + id
let sku_values = ''
app.post(url).then(r => {
if (r.code == 1) {
console.log(r.data)
for (let i = 0; i < r.data.attr.attr_sku.length; i++) {
sku_values += r.data.attr.attr_sku[i].item[0].attribute_value
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)
})
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
}
}
this.setData({
goods_item: r.data,
skuid_price: skuid_price,
old_skuid_price: old_skuid_price,
vip_skuid_price: vip_skuid_price,
skuid: skuid,
skuid_arr: arr,
sku_values: sku_values
});
} else {
wx.showToast({
title: r.msg,
icon: 'none'
})
}
});
},
//关闭加购框
close_jump_msk() {
this.setData({
show_cart_mask: false
});
},
//关闭筛选
close_all() {
this.setData({
flag: !this.data.flag
});
let ids = this.data.ids;
console.log(ids);
if (ids == undefined) {
wx.showToast({
title: '请选择属性',
icon: 'none'
})
return;
} else {
wx.navigateTo({
url: '../select_index/select_index?ids=' + ids + '&keyword=' + this.data.value
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({
ids: options.idss,
});
this.fetchGoodsLists()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})