com_screen.js
6.34 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
const ut = require("../../utils/util.js");
var regeneratorRuntime = require('../../utils/runtime.js');
var oo = getApp().globalData.setting;
module.exports = {
//下拉排序
bind_pk_sort:function (e,th){
var index=e.detail.value;
var ob=th.data.more_sort_arr[index];
var url = th.data.requestUrl;
if (th.data.tabname!=ob.value){
var txt='desc';
if(ob.value=='sort') txt='asc'
th.setData({ tabname: ob.value, adname:txt });
}
th.resetData();
//开始点击分类
if(th.requestGoodsList) {
//-- 开始点击分类 --
th.requestGoodsList(url);
}else if(th.requestSearch){
//-- 重新开始搜索 --
th.requestSearch(url);
}
},
//-- 获取列表 --
set_screen:async function (url,th){
if(!url) url=th.data.requestUrl;
var arr=url.split('1=1&');
url='/api/weshop/goods/goodsBrandGroup?'+arr[1];
var screen_brand=null;
var screen_nation=null;
var screen_price=null;
var screen_cate=null;
//如果有分类的话
if( th.data.cat_id && !th.data.screen_cate){
var c_url="/api/weshop/goodscategory/get/"+oo.stoid+"/"+ th.data.cat_id;
var f_cate=null;
await getApp().request.promiseGet(c_url,{
}).then(res=>{
if(res.data.code==0 && res.data.data){
f_cate=res.data.data;
}
})
//分类必须有parent_id_path值
if(f_cate && f_cate['parent_id_path']){
var new_arr=f_cate['parent_id_path'].split('_');
c_url='/api/weshop/goodscategory/page?store_id='+oo.stoid+'&parent_id_path='+(new_arr[0]+"_"+new_arr['1']);
await getApp().request.promiseGet(c_url,{
data:{level:2,pageSize:1000}
}).then(res=>{
if(ut.ajax_ok(res) ){
screen_cate=res.data.data.pageData.filter(function(e){
return e.name
});
}
})
}
}
if(url.indexOf('brand_id')==-1) {
var url1 = url + "&grouptype=1";
await getApp().request.promiseGet(url1, {
data: {is_mainshow: 1, isonsale: 1, store_id: oo.stoid}
}).then(res => {
if (res.data.code == 0 && res.data.data && res.data.data.length) {
screen_brand = res.data.data.filter(function(e){
return e.name
});
}
})
}
if(url.indexOf('nation_id')==-1) {
url1 = url + "&grouptype=2";
await getApp().request.promiseGet(url1, {
data: {is_mainshow: 1, isonsale: 1, store_id: oo.stoid}
}).then(res => {
if (res.data.code == 0 && res.data.data && res.data.data.length) {
screen_nation = res.data.data.filter(function(e){
return e.name;
});
}
})
}
if(url.indexOf('startprice')==-1) {
url1 = url + "&grouptype=3";
await getApp().request.promiseGet(url1, {
data: {is_mainshow: 1, isonsale: 1, store_id: oo.stoid}
}).then(res => {
if (res.data.code == 0 && res.data.data && res.data.data.length) {
var price = res.data.data;
var max_price = price[0].final_price;
var psize = Math.ceil(max_price / 5); // 每一段累积的价钱
var parr = [];
for (var i = 0; i < 5; i++) {
var start = i * psize;
var end = start + psize;
// 如果没有这个价格范围的商品则不列出来
var ii = false;
for (var v in price) {
var item_p = price[v];
if (item_p.final_price > start && item_p.final_price <= end) {
ii = true;
}
}
if (ii == false) continue;
var obj = {};
obj['price'] = start + "-" + end;
if (i == 0) obj['name'] = end + "元以下";
else if (i == 4) obj['name'] = start + "元以上";
else obj['name'] = start + "-" + end + '元';
parr.push(obj)
}
screen_price = parr;
}
})
}
th.setData({screen_brand,screen_nation,screen_price,screen_cate})
},
filterGoods:function (e,th){
var index=e.currentTarget.dataset.index;
var type=e.currentTarget.dataset.type;
var url=th.data.requestUrl;
switch (type){
case "1"://分类
var item=th.data.screen_cate[index];
if( th.data.cat_id){
var arr_m=url.split("1=1&");
var arr_m2=arr_m[1].split('&');
var url="";
for(var jj in arr_m2){
if(arr_m2[jj].indexOf('cat_id')>=-1){
url+="&cat_id="+item.id;
}else if(arr_m2[jj].indexOf('pid')>=-1){
url+="&pid="+item.parent_id;
}else{
url+="&"+arr_m2[jj];
}
}
}else {
url+="&cat_id="+item.id+"&pid="+item.parent_id;
}
url=arr_m[0]+"1=1&"+url;
break;
case "2"://国别
var item=th.data.screen_nation[index];
url+="&nation_id="+item.nation_id;
break;
case "3"://品牌
var item=th.data.screen_brand[index];
url+="&brand_id="+item.brand_id;
break;
case "4"://价格
var item=th.data.screen_price[index];
var p_arr=item.price.split('-');
url+="&startprice="+p_arr[0]+"&endprice="+p_arr[1];
break;
}
th.setData({screen_brand:null,screen_nation:null,openFilterModal:0,is_go:0,
screen_price:null,screen_cate:null,requestData:null})
th.data.currentPage=1;
//进行筛选
this.set_screen(url,th);
th.setData({
tabname:"sort", //排序的字段
adname:"asc", //升降的字段
})
//开始点击分类
if(th.requestGoodsList) {
//-- 开始点击分类 --
th.requestGoodsList(url);
}else if(th.requestSearch){
//-- 重新开始搜索 --
th.requestSearch(url);
}
},
//-- 展开和收起的控制 --
open_more:function(e,th){
var type=e.currentTarget.dataset.type;
switch(type){
case "1":
if(th.data.fil_cate_state==0 || th.data.fil_cate_state==2) th.setData({fil_cate_state:1})
else th.setData({fil_cate_state:2})
break;
case "2":
if(th.data.fil_nation_state==0 || th.data.fil_nation_state==2) th.setData({fil_nation_state:1})
else th.setData({fil_nation_state:2})
break;
case "3":
if(th.data.fil_brand_state==0 || th.data.fil_brand_state==2) th.setData({fil_brand_state:1})
else th.setData({fil_brand_state:2})
break;
case "4":
if(th.data.fil_price_state==0 || th.data.fil_price_state==2) th.setData({fil_price_state:1})
else th.setData({fil_price_state:2})
break;
}
},
clear_fil(th){
var url=th.data.old_req_url;
th.setData({screen_brand:null,screen_nation:null,openFilterModal:0,is_go:0,
screen_price:null,screen_cate:null,requestData:null})
th.data.currentPage=1;
//进行筛选
this.set_screen(url,th);
if(th.requestGoodsList) {
//-- 开始点击分类 --
th.requestGoodsList(url);
}else if(th.requestSearch){
//-- 重新开始搜索 --
th.requestSearch(url);
}
}
}