search.vue
3.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
<template>
<view class="page">
<!-- <u-search :style="{width:'100%',height: '32px',fontSize: '14px'}" bg-color="#F7F7F7" placeholder="请输入学生姓名/学号/手机号"
search-icon-color="#D9D9D9" placeholder-color="#8C8C8C" input-align="left" :clearabled="true"
:show-action="false" v-model="search" focus=true @search="handelLink()">
</u-search> -->
<u-search placeholder="请输入学生姓名/学号/手机号" placeholderColor="#C1C1C9" searchIconSize="36" height="64rpx"
bgColor="#F4F4F4" :showAction="false" shape="round" v-model="search" @search="handelLink()" @clear="clearInput()">
</u-search>
<view style="display: flex; justify-content: space-between; align-items: center; margin-top: 40rpx;">
<view class="title">
历史搜索
</view>
<u-image width="16px" height="16px" src='/static/img/home/delete.png' @click="clear"></u-image>
</view>
<view class="his">
<view class="historyItem" v-for="(item,index) in history" :key="index" @click="clickItem(item)">
{{item}}
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
type: '',
search: '',
history: [],
}
},
onLoad(option) {
console.log('onshow', option)
if (option && option.type) {
this.type = option.type
this.search = option.searchkey
}
},
onShow() {
let that = this
uni.getStorage({
key: 'search_history',
success: function(res) {
console.log('123', res)
that.history = res.data;
}
});
},
methods: {
handelLink(e) {
let that = this
// if (e == '' || !e) {
// this.$u.toast('请输入搜索条件')
// return
// }
if (e != '') {
if (this.history.indexOf(e) == -1) {
this.history.push(e)
uni.setStorage({
key: 'search_history',
data: that.history,
success: function() {
console.log('success');
}
});
}
}
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.keyword = e;
uni.navigateBack({
delta: 1
});
},
clearInput() {
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.keyword = '';
uni.navigateBack({
delta: 1
});
},
clear() {
let that = this
uni.removeStorage({
key: 'search_history',
success: function(res) {
that.history = [];
}
});
},
clickItem(e) {
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.keyword = e;
uni.navigateBack({
delta: 1
});
},
}
}
</script>
<style lang="scss" scoped>
.page {
padding: 20rpx 40rpx;
.title {
font-size: 16px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #000000;
}
.his {
margin-top: 20rpx;
display: flex;
flex-wrap: wrap;
}
.historyItem {
// height: 32px;
background: rgba(0, 0, 0, 0.03);
border-radius: 16px;
padding: 12rpx 32rpx;
font-size: 14px;
font-family: PingFangSC-Light, PingFang SC;
font-weight: 300;
color: rgba(0, 0, 0, 0.65);
text-align: center;
margin-right: 20rpx;
margin-bottom: 10px;
}
}
</style>