SearchBox.vue
2.63 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
<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
v-model="value"
:options="option"
@change="onEmit($event,'change')"
/>
<div class="arrow y-center">
<div class="sprite-icon icon-down"></div>
</div>
</van-dropdown-menu>
</template>
<template v-if="custom">
<slot></slot>
</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
},
custom: Boolean
},
data () {
return {
value: 0,
option: [
{ text: '优惠券', value: 0 },
{ text: '精品礼券', value: 1 },
{ text: '商品订单', value: 2 },
{ text: '会员服务', value: 3 }
],
searchValue: ''
}
},
mounted () {
},
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;
}
}
.van-dropdown-menu {
margin-left: auto;
.arrow {
right: 8px;
z-index: 998;
}
.van-dropdown-menu__bar--opened ~ .arrow .sprite-icon {
transform: rotate(-180deg);
transition: all 0.25s;
}
.van-dropdown-menu__bar {
background-color: #fff;
box-shadow: none;
.van-dropdown-menu__title {
color: #545454 !important;
font-size: 16px;
&::after {
display: none;
}
}
}
}
}
.max {
padding-right: 0;
.van-search {
width: 100%;
}
}
.van-icon-search:before {
color: #cdd1d4;
}
</style>