index.vue
2.18 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
<template>
<div>
<div class="input-number-range" :class="{ 'is-disabled': disabled }">
<div class="flex">
<div class="from">
<el-input ref="input_from" v-model="formData[keyObj.from]" :disabled="disabled" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入" @change="handleInputChangeFrom"></el-input>
</div>
<div class="center">
<span>至</span>
</div>
<div class="to">
<el-input ref="input_to" v-model="formData[keyObj.to]" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" :disabled="disabled" placeholder="请输入" @change="handleInputChangeTo"></el-input>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'InputNumberRange',
props: {
// 是否禁用
disabled: {
type: Boolean,
default: false
},
formData: {
type: Object,
default: () => {
return {}
}
},
keyObj: {
type: Object,
default: () => {
return {
from: 'a',
to: 'b'
}
}
}
},
data() {
return {}
},
methods: {
// from输入框change事件
handleInputChangeFrom(value) {
let from = this.formData[this.keyObj.from]
let to = this.formData[this.keyObj.to]
if (+from > +to) {
this.formData[this.keyObj.to] = from
}
},
// to输入框change事件
handleInputChangeTo(value) {
let from = this.formData[this.keyObj.from]
let to = this.formData[this.keyObj.to]
if (+from > +to) {
this.formData[this.keyObj.to] = from
}
}
}
}
</script>
<style lang="scss" scoped>
.input-number-range {
background-color: #fff;
border: 1px solid #dcdfe6;
border-radius: 4px;
}
.flex {
display: flex;
flex-direction: row;
width: 100%;
justify-content: center;
align-items: center;
/deep/ .el-input .el-input__inner {
border: 0px;
margin: 0;
padding: 0 10px;
background-color: transparent;
}
.center {
margin-top: 1px;
}
.unit {
margin-right: 10px;
}
}
.is-disabled {
background-color: #eef0f6;
border-color: #e4e7ed;
color: #c0c4cc;
cursor: not-allowed;
}
</style>