PlateNumberInput.vue
3.72 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
<template>
<el-form-item :label="label" :prop="prop" >
<el-button v-popover:popover class="select-btn" :disabled="disabled">
{{term?term:'请选择'}}
<i :class="visible?'el-icon-arrow-up':'el-icon-arrow-down'"></i>
</el-button>
<el-input maxlength="8" size="mini" placeholder="请输入剩余车牌号" v-model.trim="restNum" style="width:128px" @change="restNumChange" :disabled="disabled"></el-input>
<el-popover
ref="popover"
placement="bottom-start"
width="340"
v-model="visible"
v-show="!disabled"
trigger="click">
<div class="province-select">
<el-button :type="provinceSelected==item?'primary':'text'" v-for="item in provinceArr" :key="item" @click="selectProvince(item)">{{item}}</el-button>
</div>
<div class="no-select">
<el-button :type="noSelected==item?'primary':'text'" v-for="item in noArr" :key="item" @click="selectNo(item)">{{item}}</el-button>
</div>
</el-popover>
</el-form-item>
</template>
<script>
export default{
props: ['plateNumber', 'prop', 'label', 'init', 'disabled'],
data(){
return {
restain: this.plateNumber,
provinceArr: ["粤","京","沪","闽","川","辽","皖","苏","鄂","晋","吉","冀","宁","豫","黑","鲁","浙","桂","蒙","渝","津","云","湘","新","赣","甘","陕","贵","青","藏","琼"],
noArr: ["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"],
provinceSelected: '',
noSelected: '',
visible: false,
restNum: ''
}
},
computed:{
term:{
get(){
let term = '请选择';
if(this.init){
this.provinceSelected = '';
this.noSelected = '';
this.restNum = '';
this.$emit('onPlateNumberInitChange');
}else{
if(this.plateNumber&&this.plateNumber.length>1){
const s1 = this.plateNumber.substr(0,1);
const s2 = this.plateNumber.substr(1,1);
if(this.provinceArr.indexOf(s1)>-1 && this.noArr.indexOf(s2)>-1){
this.provinceSelected = s1;
this.noSelected = s2;
term = this.provinceSelected+this.noSelected;
this.restNum = this.plateNumber.substr(2);
}else{
this.restNum = this.plateNumber;
//this.$emit('onPlateNumberChange', '');
}
//this.restain = '';
}else if(this.provinceSelected && this.noSelected){
term = this.provinceSelected+this.noSelected;
}
}
return term;
}
}
},
watch:{
plateNumber(newValue){
//this.restain = newValue;
}
},
methods: {
selectProvince(province){
this.provinceSelected = province;
if(/^\w{5,8}$/.test(this.restNum)&&this.provinceSelected&&this.noSelected){
this.$emit('onPlateNumberChange', this.provinceSelected+this.noSelected+this.restNum)
}
},
selectNo(no){
this.noSelected = no;
if(/^\w{5,8}$/.test(this.restNum)&&this.provinceSelected&&this.noSelected){
this.$emit('onPlateNumberChange', this.provinceSelected+this.noSelected+this.restNum)
}
},
restNumChange(){
if(/^\w{5,8}$/.test(this.restNum)&&this.provinceSelected&&this.noSelected){
this.$emit('onPlateNumberChange', this.provinceSelected+this.noSelected+this.restNum)
}else{
this.restNum = ''
this.$emit('onPlateNumberChange', this.provinceSelected+this.noSelected)
}
}
}
}
</script>
<style scoped>
.el-button.select-btn{
padding: 7px 10px;
}
.el-button{
margin: 0px 5px;
padding: 4px 8px;
color: #999;
}
.el-button.el-button--primary{
color: #fff;
}
.el-button.el-button--primary:hover{
color: #fff;
}
.el-button:hover{
background-color: #094;
color: #fff;
}
.no-select{
border-top: 1px solid #eee;
padding-top: 10px;
margin-top: 10px;
}
</style>