searchList.js
3.7 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
import {
request
} from "../../request/index.js"
const a = getApp()
Page({
data: {
imagesUrl: a.globalData.baseUrl,
searchStoreList: [],
size: 5,
nominate_switch: ' ', // 推荐
showDialog: false,
time_id: '', //上架时间:2=由新到旧,1=由旧到新[非必传]
price_id: '', //价格:2=由高到低,1=由低到高[非必传]
kw: '',
msg: '',
limit: 11, //显示数据量
list: '',
page: 1, //当前页
load: true,
loading: false, //加载动画的显示
all: 0,
total: '',
pageNum: 1,
nomore: false
},
onShow: function () {},
onLoad: function (options) {
let that = this
// console.log(options);
that.setData({
kw: options.kw || ''
})
wx.stopPullDownRefresh() //刷新完成后停止下拉刷新动效
that.getSearch()
},
onReachBottom() {
var that = this;
let pageNum = that.data.pageNum
if (that.data.searchStoreList.length < that.data.total) {
pageNum++
that.setData({
pageNum,
nomore: false
})
that.getSearch()
} else {
that.setData({
nomore: true
})
}
},
getInput(e) {
this.setData({
searchValue: e.detail.value
})
},
async getSearch(e) { // 获取搜索
let that = this;
// console.log(e);
if (e) {
that.setData({
kw: e.detail.value.input ? e.detail.value.input : e.detail.value,
searchStoreList: []
})
}
wx.showLoading({
title: '加载中',
})
try {
const {
data: {
data
}
} = await
request({
url: 'api/shop/sou',
data: {
price_id: that.data.price_id,
time_id: that.data.time_id,
kw: that.data.kw,
page: that.data.pageNum
}
})
// console.log(data);
if (data.data.length != 0) {
that.setData({
total: data.total,
searchStoreList: [...that.data.searchStoreList, ...data.data],
})
wx.hideLoading()
} else {
if (that.data.kw) {
that.setData({
msg: '没有找到与' + '"' + that.data.kw + '"' + '相关的结果',
kw: '',
})
a.popTest(that.data.msg)
} else {
a.popTest('暂无数据')
wx.hideLoading()
}
}
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
},
topTime() { //上架时间
let that = this
let time_id = that.data.time_id
if (time_id == 2) {
that.setData({
time_id: 1,
page: 1,
searchStoreList: []
})
that.getSearch()
} else {
that.setData({
time_id: 2,
page: 1,
searchStoreList: []
})
// console.log(that.data.time_id);
that.getSearch()
}
},
topPrice() { // 价格
let that = this
let price_id = that.data.price_id
if (price_id == '') {
that.setData({
price_id: 1,
page: 1,
searchStoreList: []
})
that.getSearch()
} else if (price_id == 1) {
that.setData({
price_id: 2,
page: 1,
searchStoreList: []
})
that.getSearch()
} else if (price_id == 2) {
that.setData({
price_id: 1,
page: 1,
searchStoreList: []
})
that.getSearch()
}
},
goDeailItem(e) { // 普通商品详情
let goods_id = e.currentTarget.dataset.goods_id
wx.navigateTo({
url: '/pages/productdetailsImg/productdetailsImg?id=' + goods_id
})
},
toggleDialog() {
this.setData({
showDialog: !this.data.showDialog
})
},
getSearchStoreList() {
},
})