| | |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="onCancel" size="default">取 消</el-button> |
| | | <el-button type="primary" @click="onSubmit" size="default">确 定</el-button> |
| | | <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | <script lang="ts"> |
| | | import { ElMessage } from 'element-plus'; |
| | | import { reactive, toRefs, onMounted, defineComponent } from 'vue'; |
| | | import { departmentApi } from "/@/api/department"; |
| | | import { departmentApi } from '/@/api/department'; |
| | | |
| | | // 定义接口来定义对象的类型 |
| | | interface TableDataRow { |
| | | name:string, |
| | | info:string, |
| | | parentId:string, |
| | | id:number, |
| | | name: string; |
| | | info: string; |
| | | parentId: string; |
| | | id: number; |
| | | } |
| | | interface DeptSate { |
| | | title:string; |
| | | isShowDialog: boolean; |
| | | departmentForm: { |
| | | depName:string, |
| | | depInfo:string, |
| | | parentDepId:string |
| | | depName: string; |
| | | depInfo: string; |
| | | parentDepId: string; |
| | | }; |
| | | deptData: Array<TableDataRow>; |
| | | } |
| | |
| | | departmentForm: { |
| | | depName:'', |
| | | parentDepId:'', |
| | | depInfo:'', |
| | | depInfo: '' |
| | | }, |
| | | deptData: [], // 部门数据 |
| | | deptData: [] // 部门数据 |
| | | }); |
| | | // 打开弹窗 |
| | | const openDialog = (type:string, value: any,departmentList: []) => { |
| | | state.isShowDialog = true; |
| | | state.deptData = JSON.parse(JSON.stringify(departmentList)) |
| | | state.deptData = JSON.parse(JSON.stringify(departmentList)); |
| | | if(type === '新增'){ |
| | | state.title = '新增部门' |
| | | state.title = '新增部门'; |
| | | state.departmentForm = { |
| | | depName:'', |
| | | parentDepId:'', |
| | | depInfo:'', |
| | | } |
| | | depInfo: '' |
| | | }; |
| | | }else{ |
| | | state.title = '修改部门' |
| | | state.departmentForm = JSON.parse(JSON.stringify(value)) |
| | | state.title = '修改部门'; |
| | | state.departmentForm = JSON.parse(JSON.stringify(value)); |
| | | } |
| | | }; |
| | | // 关闭弹窗 |
| | |
| | | // 新增 |
| | | const onSubmit = async () => { |
| | | if(state.title === '新增部门'){ |
| | | let res = await departmentApi().addDepartment(state.departmentForm) |
| | | let res = await departmentApi().addDepartment(state.departmentForm); |
| | | if(res.data.code === '200'){ |
| | | ElMessage({ |
| | | type:'success', |
| | | message:'部门新增成功', |
| | | duration:2000 |
| | | }) |
| | | }); |
| | | closeDialog(); |
| | | context.emit('getDepartmentList') |
| | | context.emit('getDepartmentList'); |
| | | }else{ |
| | | ElMessage({ |
| | | type:'warning', |
| | | message:res.data.msg |
| | | }) |
| | | }); |
| | | } |
| | | }else{ |
| | | let res = await departmentApi().modDepartment(state.departmentForm) |
| | | let res = await departmentApi().modDepartment(state.departmentForm); |
| | | if(res.data.code === '200'){ |
| | | ElMessage({ |
| | | type:'success', |
| | | message:'部门修改成功', |
| | | duration:2000 |
| | | }) |
| | | }); |
| | | closeDialog(); |
| | | context.emit('getDepartmentList') |
| | | context.emit('getDepartmentList'); |
| | | }else{ |
| | | ElMessage({ |
| | | type:'warning', |
| | | message:res.data.msg |
| | | }) |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | | // 初始化部门数据 |
| | | const initTableData = () => { |
| | | |
| | | }; |
| | | const initTableData = () => {}; |
| | | // 页面加载时 |
| | | onMounted(() => { |
| | | initTableData(); |
| | |
| | | closeDialog, |
| | | onCancel, |
| | | onSubmit, |
| | | ...toRefs(state), |
| | | ...toRefs(state) |
| | | }; |
| | | }, |
| | | } |
| | | }); |
| | | </script> |