SearchBox.vue
2.31 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
<template>
<form :class="['search-box','flex',{'max':!showDropdown}]" action="">
<van-search
v-model="searchValue"
:placeholder="placeholder"
@search="onEmit($event,'search')"
@clear="onEmit('','search')"
@focus="onEmit('','focus')"
:maxlength="maxlength"
/>
<template v-if="showDropdown">
<van-dropdown-menu active-color="#3975C6">
<van-dropdown-item
:options="option"
v-model="value"
@change="onEmit($event,'change')"
>
<template #title>
<div class="menu-title flex">
{{option[value].text}}
<div class="sprite-icon icon-down"></div>
</div>
</template>
</van-dropdown-item>
</van-dropdown-menu>
</template>
<template v-if="showMenu">
<dropdown-menu
@confirm="onEmit($event,'menuSelect')"
:single="single"
:title="title"
:data="option"
></dropdown-menu>
</template>
</form>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'SearchBox',
props: {
keyword: String,
index: {
type: Number,
default: 0
},
updata: {
type: Number,
default: new Date().getTime()
},
showDropdown: {
type: Boolean,
default: true
},
placeholder: String,
maxlength: {
type: Number,
default: 30
},
showMenu: Boolean,
option: {
type: Array,
default: () => []
},
single: Boolean,
title: String
},
data () {
return {
value: 0,
searchValue: ''
}
},
watch: {
'updata' (n) {
this.value = this.index
},
'keyword' (n) {
this.searchValue = n
}
},
methods: {
onEmit (e, name) {
this.$emit(name, e)
}
}
}
</script>
<style lang='scss'>
.search-box {
height: 50px;
background: #fff;
box-shadow: 0px 1px 0px 0px #e9e9e9;
padding-right: 16px;
position: relative;
margin-bottom: 0;
.van-search {
width: 263px;
padding: 4.5px 8px;
height: 100%;
background: #fff;
.van-search__content {
background-color: #fff;
border: 1px solid #cdd1d4;
border-radius: 16px;
}
}
}
.max {
padding-right: 0;
.van-search {
width: 100%;
}
}
.van-icon-search:before {
color: #cdd1d4;
}
</style>