市北互联平台前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.5 KiB

3 years ago
<template>
3 years ago
<el-form :model="inputForm"
:rules="rules"
class="demo-form-inline">
<div class="flex-div">
<el-form-item prop="start">
<el-input v-model="inputForm.start"
class="wd50"
size="small"
:type="inputType"
clearable
placeholder="请输入"
@change="handleChange" />
</el-form-item>
<div class="div_middle">-</div>
<el-form-item prop="end">
<el-input v-model="inputForm.end"
class="wd50"
size="small"
:type="inputType"
clearable
placeholder="请输入"
@change="handleChange"
@blur="handleBlur" />
</el-form-item>
</div>
</el-form>
3 years ago
</template>
<script>
export default {
name: 'inputRange',
model: {
prop: 'value',
event: 'change'
},
props: {
value: {
type: Object,
3 years ago
default: () => {
3 years ago
return {
start: '',
end: ''
}
3 years ago
}
3 years ago
},
type: {
type: String,
default: ''
}
},
3 years ago
data () {
3 years ago
let checkAge = (rule, value, callback) => {
3 years ago
// debugger
3 years ago
if (value === '') {
callback(new Error('请输入内容'))
} else {
3 years ago
if (parseInt(value) < parseInt(this.inputForm.start)) {
3 years ago
callback(new Error('结束值不能小于开始值'))
3 years ago
} else {
callback()
3 years ago
}
3 years ago
3 years ago
}
}
return {
3 years ago
inputForm: { ...this.value },
3 years ago
rules: {
end: [
3 years ago
{ validator: checkAge, trigger: 'blur' }
],
3 years ago
}
}
},
computed: {
3 years ago
inputType () {
3 years ago
if (this.type == 'num') return 'number'
}
},
watch: {
3 years ago
'value.start' (val) {
3 years ago
this.inputForm.start = val
},
3 years ago
'value.end' (val) {
3 years ago
this.inputForm.end = val
},
},
methods: {
3 years ago
handleChange (val) {
3 years ago
3 years ago
// if ()
3 years ago
this.$emit('change', { ...this.inputForm })
3 years ago
},
3 years ago
handleBlur () {
3 years ago
}
}
}
</script>
<style lang="scss" scoped>
.flex-div {
display: flex;
align-items: center;
3 years ago
max-width: 200px;
3 years ago
}
3 years ago
// .wd50 {
// // width: 45%;
// }
3 years ago
.demo-form-inline {
3 years ago
::v-deep {
.el-form-item {
flex: 1;
width: 40%;
margin: 0;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
3 years ago
input[type="number"] {
3 years ago
-moz-appearance: textfield;
}
3 years ago
}
}
3 years ago
.div_middle {
padding: 0 10px;
}
3 years ago
</style>