<template>
|
<div class="system-add-user-container">
|
<el-dialog :title="title" v-model="isShowUserDialog" width="769px">
|
<el-form :model="dutyForm" size="default" ref="dutyRef" :rules="dutyFormRules" label-width="90px">
|
<el-row :gutter="35">
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="职务名称" prop="positionName">
|
<el-input v-model.trim="dutyForm.positionName" placeholder="请输入职务名称" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
<el-form-item label="职务编号" prop="positionCode">
|
<el-input v-model.trim="dutyForm.positionCode" placeholder="请输入职务编号" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="isShowUserDialog = !isShowUserDialog" size="default">取 消</el-button>
|
<el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
|
import { ElMessageBox, ElMessage } from 'element-plus';
|
import { dutyApi } from '/@/api/systemManage/duty';
|
|
// 定义接口来定义对象的类型
|
interface DeptData {}
|
interface roleData {}
|
interface sexData {}
|
interface UserState {
|
title: string;
|
disabled: boolean;
|
isShowUserDialog: boolean;
|
dutyForm: {
|
positionName:string;
|
positionCode:string
|
};
|
dutyFormRules:{}
|
}
|
|
export default defineComponent({
|
name: 'dutyDialog',
|
setup(props, context) {
|
const dutyRef = ref()
|
const state = reactive<UserState>({
|
title: '',
|
disabled: false,
|
isShowUserDialog: false,
|
dutyForm: {
|
positionName: '',
|
positionCode: ''
|
},
|
dutyFormRules:{
|
positionName: [{ required: true, message: '请填写职务名称', trigger: 'blur' }],
|
positionCode: [{ required: true, message: '请填写职务编号', trigger: 'blur' }]
|
}
|
});
|
// 打开弹窗
|
const openDialog = (type: string, value: any) => {
|
state.isShowUserDialog = true;
|
if (type === '新增') {
|
state.disabled = false
|
state.title = '新增职务';
|
state.dutyForm = {
|
positionName: '',
|
positionCode: ''
|
};
|
} else {
|
state.disabled = true
|
state.title = '修改职务';
|
state.dutyForm = JSON.parse(JSON.stringify(value));
|
}
|
};
|
|
// 新增修改
|
const onSubmit = async () => {
|
dutyRef.value.validate(async (valid:Boolean) => {
|
if(valid){
|
if (state.title === '新增职务') {
|
let res = await dutyApi().addDuty(state.dutyForm);
|
if (res.data.code === '200') {
|
ElMessage({
|
type: 'success',
|
message: '职务新增成功',
|
duration: 2000
|
});
|
state.isShowUserDialog = false;
|
context.emit('getDutyList')
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
} else {
|
let res = await dutyApi().modDuty(state.dutyForm);
|
if (res.data.code === '200') {
|
ElMessage({
|
type: 'success',
|
message: '职务修改成功',
|
duration: 2000
|
});
|
state.isShowUserDialog = false;
|
context.emit('getDutyList')
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
}
|
}else{
|
ElMessage({
|
type:'warning',
|
message:'请完善基本信息'
|
})
|
}
|
})
|
|
};
|
|
// 页面加载时
|
onMounted(() => {});
|
return {
|
dutyRef,
|
openDialog,
|
onSubmit,
|
...toRefs(state)
|
};
|
}
|
});
|
</script>
|