index.vue
3.81 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
<template>
<div>
<el-input placeholder="请输入内容" v-model="plateNo" maxlength="6" @input="onInput" :disabled="disabled">
<template slot="prepend">
<el-popover v-model="showPopover" ref="popover" placement="bottom-start" width="490" trigger="click" :disabled="disabled">
<div>
<div class="province-select">
<el-tag class="el_tag" v-for="item in provinceArr" :key="item" :effect="plateProvince==item ?'dark':'light'" :type="plateProvince==item?'primary':'info'" @click="selectProvince(item)">{{ item }}</el-tag>
</div>
<div class="no-select">
<el-tag class="el_tag" v-for="item in letterArr" :key="item" :effect="plateLetter==item ?'dark':'light'" :type="plateLetter==item?'primary':'info'" @click="selectLetter(item)">{{ item }}</el-tag>
</div>
</div>
<template slot="reference">
<div class="plate_show">
<span class="plate_name" v-if="!plateProvince && !plateLetter">请选择</span>
<span class="plate_name">{{plateProvince}}</span>
<span class="plate_name">{{plateLetter}}</span>
<i :class="showPopover?'el-icon-arrow-up':'el-icon-arrow-down'"></i>
</div>
</template>
</el-popover>
</template>
</el-input>
</div>
</template>
<script>
export default {
name: "PlateNumberInput",
props: {
value: {
type: String,
default: "",
},
disabled: {
type: Boolean,
default: false,
},
},
model: {
prop: "",
},
data() {
return {
provinceArr: [
"粤",
"京",
"沪",
"闽",
"川",
"辽",
"皖",
"苏",
"鄂",
"晋",
"吉",
"冀",
"宁",
"豫",
"黑",
"鲁",
"浙",
"桂",
"蒙",
"渝",
"津",
"云",
"湘",
"新",
"赣",
"甘",
"陕",
"贵",
"青",
"藏",
"琼",
],
letterArr: [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
],
showPopover: false,
plateNo: "",
plateProvince: "",
plateLetter: "",
};
},
watch: {
value: {
handler: function (n, o) {
console.log(n);
this.value = n;
if (!n) {
this.plateNo = "";
this.plateProvince = "";
this.plateLetter = "";
}
if (n) {
this.plateProvince = n.substr(0, 1);
this.plateLetter = n.substr(1, 1);
this.plateNo = n.substr(2, n.length - 2);
}
},
},
},
created() {
console.log(this.disabled)
},
methods: {
// 选择省份
selectProvince(e) {
this.plateProvince = e;
this.toParent();
},
// 选择字母
selectLetter(e) {
this.plateLetter = e;
this.toParent();
},
// 监听输入
onInput(e) {
this.toParent();
},
// 传递参数给父组件
toParent() {
let plate = `${this.plateProvince || ""}${this.plateLetter || ""}${
this.plateNo || ""
}`;
this.$emit("input", plate);
},
// 打开键盘
openKeyboard() {
console.log(this.disabled);
if (this.disabled) {
return false;
}
this.showPopover = !this.showPopover;
},
},
};
</script>
<style lang="scss" scoped>
.el_tag {
cursor: pointer;
margin: 4px;
}
.plate_show {
cursor: pointer;
}
.plate_name {
margin: 0 2px 0 0;
}
</style>