行政区域 新增数字校验

This commit is contained in:
a0049873 2022-11-14 14:48:30 +08:00
parent 786ca5438b
commit eb4bc77894
1 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,7 @@
<el-input v-model="dataForm.name" :placeholder="$t('region.name')"></el-input> <el-input v-model="dataForm.name" :placeholder="$t('region.name')"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="id" :label="$t('region.id')"> <el-form-item prop="id" :label="$t('region.id')">
<el-input v-model="dataForm.id" :disabled="!insert" :placeholder="$t('region.id')"></el-input> <el-input v-model="dataForm.id" :disabled="!insert" :placeholder="$t('region.id')" @change="changeId"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="sort" :label="$t('region.sort')"> <el-form-item prop="sort" :label="$t('region.sort')">
<el-input-number v-model="dataForm.sort" controls-position="right" :min="0" :label="$t('region.sort')"></el-input-number> <el-input-number v-model="dataForm.sort" controls-position="right" :min="0" :label="$t('region.sort')"></el-input-number>
@ -26,6 +26,7 @@ import debounce from 'lodash/debounce'
export default { export default {
data () { data () {
return { return {
flag: true,
visible: false, visible: false,
insert: true, insert: true,
regionList: [], regionList: [],
@ -60,7 +61,7 @@ export default {
this.visible = true this.visible = true
this.dataForm.pid = '0' this.dataForm.pid = '0'
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].resetFields() this.$refs.dataForm.resetFields()
this.dataForm.id = id this.dataForm.id = id
if (this.dataForm.id) { if (this.dataForm.id) {
this.insert = false this.insert = false
@ -68,6 +69,13 @@ export default {
} }
}) })
}, },
changeId (val) {
if (val == parseInt(val)) {
this.flag = true
} else {
this.flag = false
}
},
// //
getInfo () { getInfo () {
this.$http.get(`/sys/region/${this.dataForm.id}`).then(({ data: res }) => { this.$http.get(`/sys/region/${this.dataForm.id}`).then(({ data: res }) => {
@ -83,10 +91,17 @@ export default {
}, },
// //
dataFormSubmitHandle: debounce(function () { dataFormSubmitHandle: debounce(function () {
this.$refs['dataForm'].validate((valid) => { this.$refs.dataForm.validate((valid) => {
if (!valid) { if (!valid) {
return false return false
} }
if (!this.flag) {
this.$message({
message: '区域标识只能为数字!',
type: 'warning'
})
return false
}
this.$http[this.insert ? 'post' : 'put']('/sys/region', this.dataForm).then(({ data: res }) => { this.$http[this.insert ? 'post' : 'put']('/sys/region', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return this.$message.error(res.msg) return this.$message.error(res.msg)
@ -102,7 +117,7 @@ export default {
}) })
}).catch(() => {}) }).catch(() => {})
}) })
}, 1000, { 'leading': true, 'trailing': false }) }, 1000, { leading: true, trailing: false })
} }
} }
</script> </script>