search.js
8.01 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
var t = function(t) {
return t && t.__esModule ? t : {
default: t
};
}(require("../../../utils/LoadMore.js")), ut = require("../../../utils/util.js"),
a = getApp(), e = new t.default(), rq = a.request, oo = a.globalData.setting;
Page({
data: {
url: a.globalData.setting.imghost,
resourceUrl: a.globalData.setting.resourceUrl,
currentPage: 1,
requestData: null,
allData: null,
openFilterModal: !1,
openSearchModal: !1,
baseUrl: "/api/weshop/goods/page?1=1",
requestUrl: "",
//hotWords: [ [ "手机", "小米", "iphone" ], [ "三星", "华为", "冰箱" ] ]
hotWords: null,
tabname: "goods_id", //排序的字段
adname: "desc", //升降的字段
},
onLoad: function(t) {
//接受有没有导购的参数
var first_leader=t.first_leader;
if(first_leader){
getApp().globalData.first_leader=first_leader;
//调用接口判断是不是会员
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/"+oo.stoid+"/"+first_leader,{}).then(res=>{
if(res.data.code==0){
getApp().globalData.guide_id=res.data.data.id;
}
})
}
var th=this;
a.getConfig2(function(rs){
var arr=new Array(),arr2=new Array();
if (rs.hot_keywords != null && ut.trim(rs.hot_keywords)!="" ){
var arr1 = rs.hot_keywords.split('|');
for (var i = 0; i < arr1.length;i++){
if(i%5==0 && i!=0){
arr.push(arr2);
arr2=[];
}else{
arr2.push(arr1[i]);
}
}
if (arr2.length > 0) arr.push(arr2);
th.setData({ hotWords: arr});
}
//计算等级价相关
var swithc_list=rs.switch_list;
var sw_arr=JSON.parse(swithc_list);
//---如果后台又开等级卡的开关---
if(sw_arr.rank_switch && sw_arr.rank_switch=="2"){
th.setData({rank_switch:true});
var user=getApp().globalData.userInfo;
var ti=setInterval(function(){
if(!user) return false;
clearInterval(ti);
//---回调卡的列表---
th.getPlusCardType(function(ob){
th.setData({card_list:ob.card_list});
if(user.card_field ){
var str = user['card_expiredate'].replace(/-/g, '/');
var end = new Date(str);
end = Date.parse(end) / 1000;
var now = ut.gettimestamp();
//--- 判断是等级会员,且在有效期范围内 ---
if(user.card_field && now<end){
var card_name=ob.name_map.get(user.card_field);
if(card_name.length>4) card_name=card_name.substring(0,4);
th.setData({card_field:user.card_field,card_name:card_name,card_list:ob.card_list});
}
}
})
},500)
}
})
e.init(this, "", "requestData");
var url = this.data.baseUrl;
//扫一扫过来,显示搜索的内容
var s_key = t.s_key;
if (s_key){
this.search(s_key); this.openSearchModal();
return;
}
if (0 != t.brand_id && t.brand_id!=undefined){ url += "&brand_id=" + t.brand_id;}
if (0 != t.nation_id && t.nation_id!=undefined) { url += "&nation_id=" + t.nation_id;}
if (0 != t.max_price && t.max_price!=undefined) { url += "&min_pirce=" + t.min_pirce + "&max_price=" + t.max_price;}
if (url != this.data.baseUrl) return this.requestSearch(url);
this.openSearchModal();
},
changeTab: function(t) {
var ord = t.currentTarget.dataset.href;
var ad = t.currentTarget.dataset.ad;
var url = this.data.requestUrl;
if (this.data.tabname != ord) {
this.setData({ tabname: ord, adname: "desc" });
} else {
ad = ad == "desc" ? "asc" : "desc";
this.setData({ adname: ad });
}
this.resetData(), this.requestSearch(url);
},
//-----------真的调用地址进行搜索------------
requestSearch: function(t) {
var a = this;
this.data.requestUrl = t,
//t += "&orderField=" + a.data.tabname;
//t += "&orderType=" + a.data.adname;
//t += "&page=" + a.data.currentPage,
e.request(t, function(t) {
a.data.currentPage++ ,
null == a.data.allData && (a.data.allData = t.data.data.pageData),
a.closeSearchModal();
},
null, { is_mainshow: 1, isonsale: 1, store_id: oo.stoid,
orderField: a.data.tabname, orderType: a.data.adname, page: a.data.currentPage}
);
},
onReachBottom: function() {
this.data.openSearchModal || e.canloadMore() && this.requestSearch(this.data.requestUrl);
},
openFilterModal: function() {
this.setData({
openFilterModal: !0
});
},
closeFilterModal: function() {
this.setData({
openFilterModal: !1
});
},
filterGoods: function(t) {
this.resetData(), this.requestSearch(t.currentTarget.dataset.href), this.closeFilterModal();
},
resetData: function() {
e.resetConfig(), this.data.requestData = null, this.data.currentPage = 1;
},
//---回复最初的设置---显示全部分类--
restoreData: function() {
this.setData({
requestData: this.data.allData,
});
this.data.currentPage=2;
},
openSearchModal: function() {
this.setData({
openSearchModal: !0
});
},
closeSearchModal: function() {
this.setData({
openSearchModal: !1
});
},
submitSearch: function(t) {
this.search(t.detail.value.word);
},
//热搜关键字
searchHotWord: function(t) {
this.search(t.currentTarget.dataset.word);
},
//-----点击搜索按钮----
search: function(t) {
if ("string" != typeof t || "" == t) return a.showWarning("请输入搜索关键词");
this.resetData(), this.requestSearch(this.data.baseUrl + "&key_str=" + encodeURIComponent(t));
},
//---------分享配置--------
onShareAppMessage: function (e) {
var curPage=this;
var pagePath = curPage.route; //当前页面url
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
if(getApp().globalData.user_id){
if(pagePath.indexOf("?")>0){
pagePath+="&first_leader="+getApp().globalData.user_id;
}else{
pagePath+="?first_leader="+getApp().globalData.user_id;
}
}
return {
title: "商品搜索",
path:pagePath,
}
},
//---------图片失败,默认图片--------
bind_bnerr: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = this.data.url+ "/miniapp/images/default_g_img.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
//--- 获取卡类列表 ---
getPlusCardType: function (func) {
var storid = oo.stoid;
var th = this;
getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => {
var plusCard = res.data.data;
var arr = [1219, 2089, 3031];
var new_arr = new Array();
var card_name_map=new Map();
var user = getApp().globalData.userInfo;
for (var i = 0; i < plusCard.length; i++) {
if ((user.card_field==null || user.card_field=="") && (plusCard[i].IsStopBuy==true)) {
continue;
}
var name="card"+plusCard[i].CorrPrice.toLowerCase();
card_name_map.set(name,plusCard[i].CardName);
new_arr.push(plusCard[i]);
}
var ob={"card_list":new_arr,"name_map":card_name_map};
func(ob);
})
},
});