| | |
| | | <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 ref="ruleFormRef" :model="departmentForm" :rules="rules" size="default" 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-select v-model="departmentForm.depLevel" placeholder="请输入部门等级" class="input-add" clearable> |
| | | <el-form-item label="部门等级" prop="depLevel"> |
| | | <el-select v-model="departmentForm.depLevel" placeholder="请选择部门等级" class="input-add" clearable> |
| | | <el-option |
| | | v-for="item in depLevelList" |
| | | :key="item.id" |
| | |
| | | </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="parentDepId"> |
| | | <el-cascader :options="deptData" class="input-add" :props="{ emitPath: false, checkStrictly: true, value: 'depId', label: 'depName' }" placeholder="请选择部门" clearable v-model="departmentForm.parentDepId"> </el-cascader> |
| | | </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> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="部门编号" prop="depCode"> |
| | | <el-input v-model="departmentForm.depCode" class="input-add" placeholder="请输入部门编号" clearable></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20"> |
| | | <el-form-item label="部门描述"> |
| | |
| | | <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(ruleFormRef)" size="default">确 定</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | |
| | | <script lang="ts"> |
| | | import { ElMessage } from 'element-plus'; |
| | | import { reactive, toRefs, onMounted, defineComponent } from 'vue'; |
| | | import { ref, reactive, toRefs, onMounted, defineComponent } from 'vue'; |
| | | import { departmentApi } from '/@/api/systemManage/department'; |
| | | |
| | | import type { FormInstance, FormRules } from 'element-plus' |
| | | // 定义接口来定义对象的类型 |
| | | interface TableDataRow { |
| | | name: string; |
| | |
| | | isShowDialog: boolean; |
| | | departmentForm: { |
| | | depName: string; |
| | | depCode: string; |
| | | depInfo: string; |
| | | parentDepId: string; |
| | | depLevel:null | number |
| | | }; |
| | | deptData: Array<TableDataRow>; |
| | | depLevelList: Array<Type>; |
| | | depLevelList: Array<Type> |
| | | } |
| | | interface Type{ |
| | | id:number; |
| | |
| | | isShowDialog: false, |
| | | departmentForm: { |
| | | depName: '', |
| | | depCode: '', |
| | | parentDepId: '', |
| | | depInfo: '', |
| | | depLevel:null, |
| | |
| | | {id:3,name:'车间'}, |
| | | ] // 部门数据 |
| | | }); |
| | | |
| | | const checkCode = (rule: any, value: any, callback: any) => { |
| | | if (!value) { |
| | | return callback(new Error('请输入部门编号')) |
| | | } |
| | | setTimeout(() => { |
| | | const regex = /^[a-zA-Z0-9]+$/ |
| | | if (regex.test(value)) { |
| | | callback() |
| | | } else { |
| | | callback(new Error('部门编号只能有英文字母和数字构成')) |
| | | } |
| | | }, 1000) |
| | | } |
| | | const ruleFormRef = ref<FormInstance>() |
| | | const rules = reactive<FormRules>({ |
| | | depName: [{ required: true, message: '请填写部门名称', trigger: 'blur' }], |
| | | parentDepId: [{ required: true, message: '请选择上级部门', trigger: 'blur' }], |
| | | depLevel: [{ required: true, message: '请选择部门等级', trigger: 'blur' }], |
| | | depCode: [{ required: true, validator: checkCode, trigger: 'blur' }] |
| | | }); |
| | | // 打开弹窗 |
| | | const openDialog = (type: string, value: any, departmentList: []) => { |
| | | state.isShowDialog = true; |
| | |
| | | state.title = '新增部门'; |
| | | state.departmentForm = { |
| | | depName: '', |
| | | depCode: '', |
| | | parentDepId: '', |
| | | depLevel:null, |
| | | depInfo: '' |
| | |
| | | closeDialog(); |
| | | }; |
| | | // 新增 |
| | | const onSubmit = async () => { |
| | | if (state.title === '新增部门') { |
| | | let res = await departmentApi().addDepartment(state.departmentForm); |
| | | if (res.data.code === '200') { |
| | | const onSubmit = async (formEl: FormInstance | undefined) => { |
| | | if (!formEl) return |
| | | await formEl.validate(async (valid, fields) => { |
| | | if (valid) { |
| | | if (state.title === '新增部门') { |
| | | let res = await departmentApi().addDepartment(state.departmentForm); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '部门新增成功', |
| | | duration: 2000 |
| | | type: 'success', |
| | | message: '部门新增成功', |
| | | duration: 2000 |
| | | }); |
| | | closeDialog(); |
| | | context.emit('getDepartmentList'); |
| | | } else { |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | } else { |
| | | let res = await departmentApi().modDepartment(state.departmentForm); |
| | | if (res.data.code === '200') { |
| | | } |
| | | } else { |
| | | let res = await departmentApi().modDepartment(state.departmentForm); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: '部门修改成功', |
| | | duration: 2000 |
| | | type: 'success', |
| | | message: '部门修改成功', |
| | | duration: 2000 |
| | | }); |
| | | closeDialog(); |
| | | context.emit('getDepartmentList'); |
| | | } else { |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | console.log('error submit!', fields) |
| | | } |
| | | }) |
| | | }; |
| | | // 初始化部门数据 |
| | | const initTableData = () => {}; |
| | |
| | | initTableData(); |
| | | }); |
| | | return { |
| | | ruleFormRef, |
| | | rules, |
| | | openDialog, |
| | | closeDialog, |
| | | onCancel, |