<template>
|
<el-dialog
|
:title="title"
|
:width="width"
|
top="50px"
|
:close-on-click-modal="false"
|
:close-on-press-escape="false"
|
:visible.sync="isVisible"
|
>
|
<el-form ref="form" :model="dicItem" :rules="rules" label-dic-item="right" label-width="165px">
|
<el-form-item label="字典项名称" prop="dicItemName">
|
<el-input v-model="dicItem.dicItemName" />
|
</el-form-item>
|
<el-form-item label="字典项代码" prop="dicItemCode">
|
<el-input v-model="dicItem.dicItemCode" />
|
</el-form-item>
|
<el-form-item label="字典项说明" prop="dicItemDescribe">
|
<el-input v-model="dicItem.dicItemDescribe" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="warning" plain :loading="buttonLoading" @click="isVisible = false">
|
{{ $t('common.cancel') }}
|
</el-button>
|
<el-button type="primary" plain :loading="buttonLoading" @click="submitForm">
|
{{ $t('common.confirm') }}
|
</el-button>
|
</div>
|
</el-dialog>
|
</template>
|
<script>
|
export default {
|
name: 'DicItemEdit',
|
props: {
|
dialogVisible: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: ''
|
},
|
type: {
|
type: String,
|
default: ''
|
}
|
},
|
data() {
|
return {
|
screenWidth: 0,
|
buttonLoading: false,
|
width: this.initWidth(),
|
dicItem: this.initdicItem(),
|
rules: {
|
dicItemName: [
|
{ required: true, message: this.$t('rules.require'), trigger: 'blur' }
|
],
|
dicItemCode: [
|
{ required: true, message: this.$t('rules.require'), trigger: 'blur' }
|
],
|
authorizedGrantTypes: { required: true, message: this.$t('rules.require'), trigger: 'blur' }
|
},
|
grantTypes: [
|
{ type: 'refresh_token' },
|
{ type: 'authorization_code' },
|
{ type: 'dicItem_credentials' },
|
{ type: 'password' },
|
{ type: 'implicit' }
|
]
|
}
|
},
|
computed: {
|
isVisible: {
|
get() {
|
return this.dialogVisible
|
},
|
set() {
|
this.close()
|
this.reset()
|
}
|
}
|
},
|
mounted() {
|
window.onresize = () => {
|
return (() => {
|
this.width = this.initWidth()
|
})()
|
}
|
},
|
methods: {
|
initWidth() {
|
this.screenWidth = document.body.dicItemWidth
|
if (this.screenWidth < 991) {
|
return '90%'
|
} else if (this.screenWidth < 1400) {
|
return '45%'
|
} else {
|
return '800px'
|
}
|
},
|
initdicItem() {
|
return {
|
dicItemId: '',
|
dicItemName: '',
|
dicItemCode: '',
|
dicId: '',
|
dicItemDescribe: ''
|
}
|
},
|
setaddDicItem(val) {
|
this.dicItem.dicId = val
|
},
|
setdicItem(val) {
|
this.dicItem = { ...val }
|
},
|
submitForm() {
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
this.buttonLoading = true
|
if (this.type === 'add') {
|
// create
|
this.$post('system/dicItem', { ...this.dicItem }).then(() => {
|
this.buttonLoading = false
|
this.isVisible = false
|
this.$message({
|
message: this.$t('tips.createSuccess'),
|
type: 'success'
|
})
|
this.$emit('success')
|
})
|
} else {
|
// update
|
this.$put('system/dicItem', { ...this.dicItem }).then(() => {
|
this.buttonLoading = false
|
this.isVisible = false
|
this.$message({
|
message: this.$t('tips.updateSuccess'),
|
type: 'success'
|
})
|
this.$emit('success')
|
})
|
}
|
} else {
|
return false
|
}
|
})
|
},
|
close() {
|
this.$emit('close')
|
},
|
reset() {
|
this.$refs.form.clearValidate()
|
this.$refs.form.resetFields()
|
this.dicItem = this.initdicItem()
|
}
|
}
|
}
|
</script>
|