usedkind.js
8.3 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
439
440
// pages/home/usedkind/usedkind.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
used_id: '',
page: 1,
num: 4,
classifyList: [],
// currTab: 0,
moneyId: "",
filState: false,
keyword:'',
city:'',
//包邮
if_freight:'',
//全新
degree_id:'',
low_price:'',
hight_price:'',
provincearray: ['全国', '北京', "天津",'安徽', "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北", "河南", "黑龙江", "湖北", "湖南", "吉林", "江苏", "江西", "辽宁", "内蒙古", "宁夏", "青海", "山东", "山西", "陕西", "上海", "四川", "西藏", "新疆", "云南", "浙江", "重庆", "香港", "澳门", "台湾"],
provinceindex:0,
provincename:'',
selectbtn:false,
orderindex:0,
orderarray:["最新发布","最低价格","价格最高"],
order:'',
currTab1:"",
currTab2:"",
currTab3:"",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
console.log(options )
let used_id = options.used_id;
let usename = options.used_name
this.setData({
used_id: used_id
})
wx.setStorageSync('used_id', used_id)
this.getClassify();
// this.getLocation();
wx.setNavigationBarTitle({
title: usename //页面切换,更换页面标题
})
},
//获取省
bindprovinceChange(e) {
let that = this;
that.setData({
classifyList:[],
page:1
})
console.log(e)
let provinceindex = e.detail.value;
if (provinceindex==0){
that.setData({
provinceindex: e.detail.value,
provincename:''
})
}else{
that.setData({
provinceindex: e.detail.value,
provincename: that.data.provincearray[provinceindex]
})
}
that.getClassify();
},
getLocation: function () {
let that = this
// that.setData({
// classifyList: []
// })
wx.getLocation({
type: 'gcj02', //默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
console.log(res)
// success
var longitude = res.longitude
var latitude = res.latitude
that.loadCity(longitude, latitude)
}
})
},
loadCity: function (longitude, latitude) {
let that = this
wx.request({
url: 'https://api.map.baidu.com/geocoder/v2/?ak=vS9SYsggGGfBZKpa62UXuPCfocAxPibG&location=' + latitude + ',' + longitude + '&output=json',
data: {},
header: {
'Content-Type': 'application/json'
},
success: function (res) {
// success
console.log(res);
var city = res.data.result.addressComponent.city;
that.setData({
city: city
});
},
fail: function () {
page.setData({ currentCity: "获取定位失败" });
},
})
},
// 获取分类列表
getClassify: function(e) {
let that = this;
let url = "/api/portal/goods/getGoodsList";
let params = {
token: wx.getStorageSync('token'),
goods_cate_id: this.data.used_id,
page: this.data.page,
num: this.data.num,
keyword: this.data.keyword,
city:that.data.city,
province: that.data.provincename,
if_freight: that.data.if_freight,
degree_id: that.data.degree_id,
low_price: that.data.low_price,
hight_price: that.data.hight_price,
order: that.data.order
}
app.post(url, params).then((res) => {
console.log(res)
that.setData({
classifyList: that.data.classifyList.concat(res.list)
})
}).catch((errMsg) => {
})
},
//商品详情页
goodtail: function (e) {
let goods_id = e.currentTarget.dataset.goods_id;
wx.setStorageSync('goods_id', goods_id);
wx.navigateTo({
url: '../goodtail/goodtail?goods_id=' + goods_id,
})
},
// 快捷标签切换
filtrTap1: function(e){
var that = this;
console.log(that.data.currTab1)
if (that.data.currTab1==""){
console.log(999)
that.setData({
currTab1:3
})
that.getLocation();
} else if (that.data.currTab1 == 3){
that.setData({
currTab1:'',
city:''
})
}
},
filtrTap2: function (e) {
var that = this;
if (that.data.currTab2=="") {
that.setData({
currTab2: 1,
degree_id: 1,
})
} else if (that.data.currTab2== 1) {
that.setData({
currTab2: '',
degree_id: "",
})
}
},
filtrTap3: function (e) {
var that = this;
if (that.data.currTab3 == "") {
that.setData({
currTab3:2,
if_freight:1
})
} else if (that.data.currTab3 == 2) {
that.setData({
currTab3: '',
if_freight:''
})
}
},
//最低输入
enterlow(e){
this.setData({
low_price:e.detail.value
})
if (this.data.hight_price == "" && this.data.low_price == "") {
this.setData({
selectbtn: false
})
} else {
this.setData({
selectbtn: true
})
}
},
//高价输入
enterhigh(e){
this.setData({
hight_price: e.detail.value
})
if (this.data.hight_price == "" && this.data.low_price=="") {
this.setData({
selectbtn: false
})
} else{
this.setData({
selectbtn: true
})
}
},
//排序
bindorderChange(e) {
this.setData({
orderindex: e.detail.value,
classifyList:[],
page:1
})
if (e.detail.value==0){
this.setData({
order:1
})
this.getClassify()
} else if (e.detail.value == 1){
this.setData({
order: 2
})
this.getClassify()
} else if (e.detail.value == 2) {
this.setData({
order: 3
})
this.getClassify()
}
},
// 价格切换
moneyTap: function(e){
let that = this;
that.setData({
moneyId: e.target.dataset.money
})
if (e.target.dataset.money==1){
that.setData({
hight_price:100
})
} else if (e.target.dataset.money == 2) {
that.setData({
hight_price: 200
})
}else if (e.target.dataset.money == 3) {
that.setData({
hight_price: 300
})
} else if (e.target.dataset.money == 4) {
that.setData({
hight_price: 500
})
} else if(e.target.dataset.money == 5) {
that.setData({
hight_price: 1000
})
} else if (e.target.dataset.money == 6) {
that.setData({
hight_price: 3000
})
}
},
// 显示筛选条件
chooseTap: function(){
let that = this;
that.setData({
filState: true
})
},
affirmTap: function(){
this.setData({
classifyList:[],
page:1
})
if (this.data.hight_price!=""&&this.data.low_price > this.data.hight_price) {
wx.showToast({
title: '最低价要低于最高价',
icon: 'none'
})
}else{
this.setData({
filState: false
})
this.getClassify()
}
},
//重置
reset(){
this.setData({
currTab1:"",
currTab2: "",
currTab3: "",
low_price: '',
hight_price: '',
moneyId:"",
selectbtn:false,
})
},
//搜索
entersearch(e){
this.setData({
page:1,
keyword:e.detail.value,
})
if (e.detail.value==""||e.detail.value==null){
this.getClassify()
}
},
searchgood(){
let that = this;
that.setData({
classifyList:[],
page:1
})
that.getClassify()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
console.log(666)
this.data.page++;
this.getClassify();
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
})