| | |
| | | <template> |
| | | <div class="system-add-dept-container"> |
| | | <el-dialog :title="title" v-model="isShowDialog" width="600px"> |
| | | <el-form :model="departmentForm" size="default" label-width="90px"> |
| | | <el-form :model="departmentForm" size="default" ref="depRef" :rules="depFormRules" label-width="90px"> |
| | | <el-row :gutter="35"> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="上级部门"> |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="部门名称"> |
| | | <el-form-item label="部门名称" prop="depName"> |
| | | <el-input v-model="departmentForm.depName" class="input-add" placeholder="请输入部门名称" clearable></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="onCancel" size="default">取 消</el-button> |
| | | <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button> |
| | | <el-button type="primary" v-throttle @click="onSubmit(depRef)" size="default">确 定</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | |
| | | <script lang="ts"> |
| | | import { ElMessage } from 'element-plus'; |
| | | import { reactive, toRefs, onMounted, defineComponent } from 'vue'; |
| | | import {reactive, toRefs, onMounted, defineComponent, ref} from 'vue'; |
| | | import { departmentApi } from '/@/api/systemManage/department'; |
| | | |
| | | // 定义接口来定义对象的类型 |
| | |
| | | }; |
| | | deptData: Array<TableDataRow>; |
| | | depLevelList: Array<Type>; |
| | | depFormRules:{ |
| | | |
| | | } |
| | | } |
| | | interface Type{ |
| | | id:number; |
| | |
| | | {id:2,name:'事业部'}, |
| | | {id:3,name:'车间'}, |
| | | {id:4,name:'班组'} |
| | | ] // 部门数据 |
| | | ], // 部门数据 |
| | | depFormRules:{ |
| | | depName: [{ required: true, message: '请填写部门名称', trigger: 'blur' }], |
| | | }, |
| | | }); |
| | | |
| | | const depRef = ref() |
| | | const findParentById=(tree:Array<any>,id:number|null,depName:string)=>{ |
| | | const parent = tree.find(i=>i.id == id) |
| | | if(parent){ |
| | |
| | | }; |
| | | // 新增 |
| | | const onSubmit = async () => { |
| | | depRef.value.validate(async (valid:Boolean) => { |
| | | if(valid){ |
| | | if (state.title === '新增部门') { |
| | | let res = await departmentApi().addDepartment(state.departmentForm); |
| | | if (res.data.code === 100) { |
| | |
| | | }); |
| | | } |
| | | } |
| | | }else{ |
| | | ElMessage({ |
| | | type:'warning', |
| | | message:'请完善基本信息' |
| | | }) |
| | | } |
| | | }) |
| | | }; |
| | | // 初始化部门数据 |
| | | const initTableData = () => {}; |
| | |
| | | initTableData(); |
| | | }); |
| | | return { |
| | | depRef, |
| | | findParentById, |
| | | openDialog, |
| | | closeDialog, |