search.vue
5.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
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
<template>
<view class="">
<view class="minBox">
<!-- 搜索框 -->
<view class="search">
<u-search bgColor='#F6F6F6' :showAction="false" placeholder="搜索" v-model="keyword" @search="search(keyword)">
</u-search>
</view>
<view class="" v-if="status==0">
<!-- 历史搜索 -->
<view class="history flexJ" v-if="historyList.length">
<view class="searchHistory">搜索历史</view>
<image src="../../static/delete.png" mode="" style="width: 32rpx; height:32rpx;" @click="clear"></image>
</view>
<!-- 历史记录 -->
<view class="historyRecord" >
<view class="historyRecordBox flexC" v-for="item in historyList" :key="item.id">
{{item}}
</view>
</view>
</view>
</view>
<view class="minBoxs">
<!-- 搜索出的结果 -->
<view class="" v-if="status==1">
<view class="searchResult flexJ" v-for="(item,idx) in displayLIstanbul" :key="item.id">
<view class="left">
<image src="../../static/Frame 181@2x.png" mode=""></image>
</view>
<view class="right">
<view class="top">{{item.name}}</view>
<view class="center flexA">
<view class="two">¥110</view>
</view>
<view class="bottom flexJ">
<view class="flexA">
<view class="flexA">
<view class="money">¥</view>
<view class="moneys">{{item.price}}</view>
</view>
<view class="price flexA">
<view class="">¥</view>
<view class="">{{item.prics}}</view>
</view>
</view>
<image src="../../static/Group 5@2x.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
</view>
</view>
</view>
</view>
</view>
<!-- 搜索结果为空 -->
<view class="searchNull" v-if="status==2">
<image src="../../static/Frame 181@2x.png" mode="" style="width: 320rpx; height: 320rpx;"></image>
<view class="null">
暂无搜素结果
</view>
</view>
<!-- 模态框是否确认删除 -->
<u-modal :show="show" :title="title" :content='content' showCancelButton=true @confirm="confirm"
@cancel="cancel"></u-modal>
</view>
</template>
<script>
export default {
data() {
return {
keyword: '',
historyList: ['薯片','薯片配啤酒','可乐','巴啦啦小魔仙裙子','减肥的药能首发式地方'],
show: false,
title: '确定清空搜索历史吗',
searchList: [{id:1,name:'薯片',price:20,prics:15},{id:2,name:'辣条',price:20,prics:15}, {id: 3,name:'可乐',price:20,prics:15},{id:4,name:'裙子',price:200,prics:150}, {id:5,name:'减肥的药',price:80,prics:60}, {id:6,name:'泡面',price:20,prics:15}], //搜索数组
displayLIstanbul:[], //存放搜索到的内容
status:0,
}
},
onLoad() {
},
methods: {
clear() {
this.show = true
},
//模态框的确认键
confirm() {
this.show = false
this.historyList = []
uni.showToast({
title: '清空成功'
})
},
//模态框的取消键
cancel() {
this.show = false
},
// 回车事件
search(keyword) {
// console.log(keyword)
// console.log('按下了回车')
this.historyList.push(keyword)
this.searchList.forEach(item=>{
if (item.name.indexOf(this.keyword) !== -1) {
// console.log('看看是啥',item.name.indexOf(this.keyword))
console.log('搜到了')
this.displayLIstanbul.push(item)
console.log(item)
this.status = 1
this.keyword = ''
} else {
console.log('没搜到')
this.status = 2
this.keyword = ''
}
})
}
},
}
</script>
<style lang="scss">
.minBox {
margin: 16rpx 32rpx;
}
.search {
width: 100%;
height: 72rpx;
border-radius: 38rpx;
margin-bottom: 16rpx;
}
.history{
margin-top: 32rpx;
}
.searchHistory {
color: rgba(0, 0, 0, 1);
font-size: 24rpx;
font-weight: 700;
}
.historyRecord {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
width: 100%;
margin-top: 30rpx;
.historyRecordBox {
height: 52rpx;
border-radius: 0 16rpx 0 16rpx;
background: rgba(235, 249, 238, 1);
color: rgba(0, 0, 0, 1);
font-size: 26rpx;
padding: 6rpx 16rpx;
box-sizing: border-box;
margin-bottom: 32rpx;
}
}
.minBoxs {
width: 750rpx;
height: auto;
background-color: #F6F6F6;
}
.searchResult {
width: 686rpx;
height: 268rpx;
border-radius: 8rpx;
background: #fff;
margin: 24rpx 32rpx;
.left {
padding: 21rpx 22rpx 22rpx 21rpx;
box-sizing: border-box;
margin-right: 24rpx;
image {
width: 177rpx;
height: 177rpx;
}
}
.right {
height: 220rpx;
width: 394rpx;
.top {
height: 72rpx;
color: rgba(0, 0, 0, 1);
font-size: 28rpx;
}
.center {
margin-top: 24rpx;
height: 40rpx;
background-image: url('@/static/tabBar/Group 42@2x.png');
background-repeat: no-repeat;
background-size: 114rpx 40rpx;
.two {
height: 28rpx;
width: 42rpx;
margin-left: 50rpx;
padding: 2rpx 1rpx 1rpx 1rpx;
box-sizing: border-box;
color: rgba(255, 223, 177, 1);
font-size: 20rpx;
font-weight: 700;
}
}
.bottom {
margin-top: 44rpx;
.money {
color: rgba(9, 94, 28, 1);
font-size: 24rpx;
font-weight: 700;
}
.moneys {
color: rgba(9, 94, 28, 1);
font-size: 32rpx;
font-weight: 700;
}
.price {
color: rgba(179, 179, 179, 1);
font-size: 24rpx;
text-decoration: line-through;
text-decoration-color: #B9B9B9;
margin-top: 5rpx;
margin-left: 8rpx;
}
}
}
}
.searchNull{
margin: 196rpx 214rpx 32rpx 216rpx;
.null{
width: 168rpx;
height: 40rpx;
color: rgba(0,0,0,0.6);
font-size: 28rpx;
margin-left: 76rpx;
}
}
</style>