<template>
|
<div>
|
<el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" @close="closeDialog" :destroy-on-close="true" :append-to-body="true" :close-on-click-modal="false">
|
<el-form :model="dictTypeForm" :rules="dictTypeRules" ref="dictTypeForm" size="small">
|
<el-form-item label="字典类型" :label-width="formLabelWidth" prop="dictTypeName">
|
<el-input v-model="dictTypeForm.dictTypeName" autocomplete="off"></el-input>
|
</el-form-item>
|
<el-form-item label="字典key" :label-width="formLabelWidth" prop="dictTypeKey">
|
<el-input v-model="dictTypeForm.dictTypeKey" autocomplete="off"></el-input>
|
</el-form-item>
|
<el-form-item label="备注" :label-width="formLabelWidth" prop="remark">
|
<el-input v-model="dictTypeForm.remark" autocomplete="off"></el-input>
|
</el-form-item>
|
<el-form-item label="排序" :label-width="formLabelWidth" prop="dictSort">
|
<el-input v-model="dictTypeForm.dictSort" autocomplete="off"></el-input>
|
</el-form-item>
|
<el-form-item label="状态" :label-width="formLabelWidth" prop="dictStatus">
|
<el-radio-group v-model="dictTypeForm.dictStatus">
|
<el-radio label="0">正常</el-radio>
|
<el-radio label="1">禁用</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="closeDialog" size="small">取 消</el-button>
|
<el-button type="primary" @click="addOrEditDictType" size="small">确 定</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import {Message} from "element-ui";
|
import {addDictType, editDictType, getDictTypes} from "@/api/dict-type";
|
|
export default {
|
name: "RoleDialog",
|
data() {
|
return {
|
formLabelWidth: '120px',
|
dictTypeRules: {
|
dictTypeName: [
|
{ required: true, message: '请输入角色名称', trigger: 'blur' }
|
],
|
dictTypeKey: [
|
{ required: true, message: '请输入角色key', trigger: 'blur' }
|
],
|
dictStatus: [
|
{ required: true, message: '请选择角色状态', trigger: 'change' }
|
],
|
}
|
}
|
},
|
computed: {
|
dialogFormVisible: {
|
get() {
|
return this.$store.state.dictType.dialogFormVisible;
|
},
|
set(value) {
|
this.$store.state.dictType.dialogFormVisible = value;
|
}
|
},
|
dialogTitle() {
|
return this.$store.state.dictType.dialogTitle;
|
},
|
dictTypeForm: {
|
get() {
|
return this.$store.state.dictType.dictTypeForm;
|
},
|
set(value) {
|
this.$store.state.dictType.dictTypeForm = value;
|
}
|
}
|
},
|
methods: {
|
refreshData() {
|
var params = {
|
"current": this.$store.state.dictType.currentPage,
|
"size": this.$store.state.dictType.pageSize
|
};
|
// 刷新
|
getDictTypes(params).then((res) => {
|
this.$store.state.dictType.tableData = res.data.data;
|
this.$store.state.dictType.total = res.data.total;
|
this.clearForm();
|
})
|
},
|
clearForm() {
|
Object.keys(this.dictTypeForm).forEach((key) => {
|
this.dictTypeForm[key] = null;
|
})
|
},
|
closeDialog() {
|
this.$store.state.dictType.dialogFormVisible = false;
|
this.clearForm();
|
},
|
addOrEditDictType() {
|
this.$refs["dictTypeForm"].validate((valid) => {
|
if (valid) {
|
if (this.dialogTitle === "添加字典类型") {
|
addDictType(this.dictTypeForm).then((res) => {
|
Message.success(res.data.msg);
|
this.dialogFormVisible = false;
|
this.refreshData();
|
})
|
} else {
|
editDictType(this.dictTypeForm).then((res) => {
|
Message.success(res.data.msg);
|
this.dialogFormVisible = false;
|
this.refreshData();
|
})
|
}
|
} else {
|
console.log('error submit!!');
|
return false;
|
}
|
});
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|