search.js
5.19 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
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 th=this;
a.getConfig2(function(rs){
console.log("onload");
console.log(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});
}
})
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;
console.log("changeTab");
console.log(ord + ":" + ad + ":" + this.data.requestUrl);
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;
console.log('requestSearch');
console.log(t,"扫描商品的搜索商品1111111111111111111111111111");
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) {
console.log(t,"是什么的");
if ("string" != typeof t || "" == t) return a.showWarning("请输入搜索关键词");
this.resetData(), this.requestSearch(this.data.baseUrl + "&key_str=" + encodeURIComponent(t));
},
//---------图片失败,默认图片--------
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) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
});