search.vue
8.2 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
<template>
<view class="container">
<view class="searhtoppage flextwo">
<view class="searchtopk flextwo">
<image src="../../static/search.png" mode="" class="search"></image>
<view class='searchleft'>
<input type="text" placeholder="输入您搜索的内容" v-model="keyword" @blur="searchbtn" />
</view>
</view>
<view class="cancelname" @click="cancel">取消</view>
</view>
<!-- 搜索 -->
<view class="searchbox" v-if="search">
<view>
<view class="searchboxtop flextwo">
<view class='searchboxleft flexone'>
<view class="hotname">历史搜索</view>
</view>
<view class="qingkong flexone" @click="clear">
<view class="qingkongname">清空</view>
<image src="../../static/shanchu.png" mode="" class="delimg"></image>
</view>
</view>
<view class="nodata" v-if="searchhis.length==0">暂无数据</view>
<view class="lishibox flexone" v-else>
<view class="lishoboxitme" v-for="(item,index) in searchhis" :key="index" @click="searchitem(item)">{{item}}</view>
</view>
</view>
<view class="searchboxtop flextwo" @click="more">
<view class='searchboxleft flexone'>
<image src="../../static/hot.png" mode="" class="hot"></image>
<view class="hotname">热门品类推荐</view>
</view>
<view class="more flexone">
更多
<img src="../../static/yourow.png" alt="" class="yourow">
</view>
</view>
<goodkind :wantlist="wantlist"></goodkind>
</view>
<!-- 搜索列表 -->
<view class="searchlist" v-else>
<!--有搜搜结果 -->
<view class="searchitem flextwo" v-if="anchor.length!=0">
<view class="searchitemleft flexone" @click="enterpeople(anchor.id)">
<image :src="anchor.avatar" mode="" class="headimg"></image>
<view class="searchheadname">{{anchor.name}}</view>
</view>
<view class="dingyue" v-if="anchor.user_anchor==0" @click="dingyuepeople">订阅直播</view>
<view class="canceltixing" v-else @click="dingyuepeople">取消订阅</view>
</view>
<view class="searchitem flextwo" v-if="cate.length!=0">
<view class="searchitemleft flexone">
<image :src="cate.image" mode="" class="headimg"></image>
<view class="searchheadname">{{cate.name}}</view>
</view>
<view class="dingyue" v-if="cate.user_cate==0" @click="dingyuezhibo">订阅直播</view>
<view class="canceltixing" v-else @click="dingyuezhibo">取消订阅</view>
</view>
<view class="want flextwo">
<view class="wantleft flexone">
<image src="../../static/zan.png" mode="" class="likeimg"></image>
与“{{keyword}}”有关的直播
</view>
<view class="more flexone">
更多
<img src="../../static/yourow.png" alt="" class="yourow">
</view>
</view>
<view>
<view class="nodata" v-if="zhigoodlist.length==0">暂无数据</view>
<view v-else>
<!-- 商品列表 -->
<goodlist :zhigoodlist="zhigoodlist"></goodlist>
</view>
</view>
<view class="want flextwo" @click='more'>
<view class='searchboxleft flexone'>
<image src="../../static/hot.png" mode="" class="hot"></image>
<view class="hotname">热门品类推荐</view>
</view>
<view class="more flexone">
更多
<img src="../../static/yourow.png" alt="" class="yourow">
</view>
</view>
<goodkind :wantlist="wantlist"></goodkind>
</view>
</view>
</template>
<script>
import app from "../../App.vue";
import goodkind from "../../compontent/goodkind.vue"
import goodlist from "../../compontent/goodlist.vue"
import {
Toast
} from "../../utils/toast.js"
var that
export default {
components: {
goodkind,
goodlist
},
data() {
return {
search: true,
havesou: false,
goodshow: false,
wantlist: [],
keyword: '',
zhigoodlist: [],
showpull: true,
page: 1,
searchhis: [],
anchor: '',
cate: ''
}
},
onReachBottom() {
that = this
let newpage = that.page;
newpage++
that.page = newpage;
if (that.showpull == true) {
console.log(38493409)
Toast('没有更多了~')
} else {
that.getsearchresult()
}
},
onLoad() {
// 获取热门品类
this.getwant()
// 获取搜索列表
this.getsoulist()
},
methods: {
cancel() {
this.search = true;
this.keyword = ''
this.getsoulist()
},
// 获取搜索列表
getsoulist() {
let that = this;
var url = "keyword_log/getKeyword"
let param = {
}
app.post(url, param, "post").then(res => {
console.log('搜索列表', res)
that.searchhis = res
}).catch(err => {
console.log(err)
})
},
// 热门品类
getwant() {
let that = this;
var url = "category/getRandCategory"
let param = {
type: 2,
limit: 8
}
app.post(url, param, "post").then(res => {
console.log('我想要的', res)
that.wantlist = res
}).catch(err => {
console.log(err)
})
},
// 清空搜素记录
clear() {
let that = this;
uni.showModal({
title: '',
content: '是否清空搜索记录',
success: function(res) {
if (res.confirm) {
var url = "keyword_log/delKeyword"
let param = {
}
app.post(url, param, "post").then(res => {
Toast("删除成功");
that.searchhis = []
}).catch(err => {
console.log(err)
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
// 获取搜索
searchbtn() {
this.search = false;
this.page=1;
this.zhigoodlist=[];
this.getsearchresult();
},
// 获取搜索结果
getsearchresult() {
let that = this;
var url = "goods/search"
let param = {
keyword: that.keyword,
page: that.page,
per_apge: 20
}
app.post(url, param, "post").then(res => {
console.log('搜索结果', res)
that.anchor = res.anchor;
that.cate = res.cate
that.zhigoodlist = that.zhigoodlist.concat(res.list.data);
if (that.page > 1) {
if (res.list.data == 0) {
that.showpull = false
}
}
}).catch(err => {
console.log(err)
})
},
// 热门推荐更多
more() {
uni.navigateTo({
url: '/pages/xinyuan/zhiboknow'
})
},
// 订阅人
dingyuepeople() {
let that = this;
var url = "anchor/addUserAnchor"
let param = {
anchor_id: that.anchor.id
}
app.post(url, param, "post").then(res => {
console.log('搜索结果', res)
if (that.anchor.user_anchor == 0) {
that.anchor.user_anchor = 1;
Toast("订阅成功")
} else {
that.anchor.user_anchor = 0;
Toast("取消订阅成功")
}
that.anchor = that.anchor;
that.$forceUpdate()
}).catch(err => {
console.log(err)
})
},
// 订阅品类
dingyuezhibo() {
let that = this;
var url = "category/addUserCate"
let param = {
cate_id: that.cate.id
}
app.post(url, param, "post").then(res => {
console.log('搜索结果', res)
if (that.cate.user_cate == 0) {
that.anchor.user_cate = 1;
Toast("订阅成功")
} else {
that.anchor.user_cate = 0;
Toast("取消订阅成功")
}
that.cate = that.cate;
that.$forceUpdate()
}).catch(err => {
console.log(err)
})
},
searchitem(item) {
this.keyword = item;
this.getsearchresult();
this.search = false
},
// 进入主播详情
enterpeople(id){
console.log(id)
uni.navigateTo({
url:'/pages/xinyuan/zhibodetail?id='+id
})
}
}
}
</script>
<style>
@import url('../../style/xinyuan');
page {
padding: 0 32rpx;
box-sizing: border-box;
}
.searhtoppage {
padding: 0 32rpx;
box-sizing: border-box;
}
.fuzhi {
margin-top: 92rpx
}
.copybtn {
margin: 64rpx auto 32rpx
}
.fuzhitext {
text-align: center;
}
.lishibox {
margin-top: 24rpx;
flex-wrap: wrap;
}
.lishoboxitme {
background: #f7f8fa;
border-radius: 8rpx;
padding: 8rpx 16rpx;
box-sizing: border-box;
color: #252F3E;
font-size: 24rpx;
margin-bottom: 20rpx;
margin-right: 10rpx;
}
.canceltixing {
width: 144rpx;
height: 48rpx;
background: #bbbbbb;
border-radius: 10rpx;
color: #fff;
font-size: 24rpx;
text-align: center;
line-height: 48rpx;
}
</style>