From 85e935b85bbae57e4ec1fab28d7027b867998ec2 Mon Sep 17 00:00:00 2001
From: 祖安之光 <11848914+light-of-zuan@user.noreply.gitee.com>
Date: 星期二, 29 七月 2025 16:14:11 +0800
Subject: [PATCH] 修改新增

---
 src/views/build/conpanyFunctionConsult/staffManage/staffRegister/components/staffDialog.vue |  290 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 135 insertions(+), 155 deletions(-)

diff --git a/src/views/build/conpanyFunctionConsult/staffManage/staffRegister/components/staffDialog.vue b/src/views/build/conpanyFunctionConsult/staffManage/staffRegister/components/staffDialog.vue
index 055431f..7bba3b4 100644
--- a/src/views/build/conpanyFunctionConsult/staffManage/staffRegister/components/staffDialog.vue
+++ b/src/views/build/conpanyFunctionConsult/staffManage/staffRegister/components/staffDialog.vue
@@ -67,8 +67,8 @@
             <el-radio :label="0" v-if="state.currentUserType == 0">系统管理员</el-radio>
             <el-radio :label="6" v-if="state.currentUserType == 0 || state.currentUserType == 6 ">企业管理员</el-radio>
             <el-radio :label="1" v-if="state.currentUserType == 0 || state.currentUserType == 6 || state.currentUserType ==1">企业用户</el-radio>
-            <el-radio :label="2" v-if="state.currentUserType !== 3">部门级</el-radio>
-            <el-radio :label="3">车间(岗位)级</el-radio>
+<!--            <el-radio :label="2" v-if="state.currentUserType !== 3">部门级</el-radio>-->
+<!--            <el-radio :label="3">车间(岗位)级</el-radio>-->
 <!--            <el-radio :label="4" v-if="state.currentUserType == 0">其他</el-radio>-->
           </el-radio-group>
           <span v-else>{{state.currentUserType === 0 ? '系统管理员' : state.currentUserType === 1 ? '企业用户' : state.currentUserType === 6 ? '企业管理员' : state.currentUserType === 2 ? '部门级' : state.currentUserType === 3 ? '车间级' :'其他'}}</span>
@@ -81,13 +81,13 @@
 <!--            <el-radio :label="4" >其他</el-radio>-->
 <!--          </el-radio-group>-->
         </el-form-item>
-        <el-form-item label="所属企业:" prop="companyName" v-if="state.title !== '修改密码' && showCompany">
+        <el-form-item label="所属企业:" prop="companyName" v-if="state.title !== '修改密码' && state.form.userType !== 0">
           <el-select
               clearable
               v-if="state.isAdmin"
               v-model="state.form.companyName"
               filterable
-              :disabled="disabled || state.title =='编辑'"
+              :disabled="disabled || (state.title =='编辑' && state.currentUserType !== 0)"
               remote
               @change="selectValue"
               reserve-keyword
@@ -125,21 +125,21 @@
 
 
         </el-form-item>
-        <el-form-item label="所属上级账号:" prop="companyName" v-if="showChild">
-          <scorllSelect
-              :disabled="disabled || state.title =='编辑'"
-              ref="scrollRef"
-              v-model="state.form.parentName"
-              @getval = "getSelectUser"
-              placeholder="请选择"
-              clearable
-              style="width: 45%;"
-              filterable
-              remote
-              searchKey="username"
-              :methods="getUser">
-          </scorllSelect>
-        </el-form-item>
+<!--        <el-form-item label="所属上级账号:" prop="companyName" v-if="state.form.userType == 3">-->
+<!--          <scorllSelect-->
+<!--              :disabled="disabled"-->
+<!--              ref="scrollRef"-->
+<!--              v-model="state.form.parentName"-->
+<!--              @getval = "getSelectUser"-->
+<!--              placeholder="请选择"-->
+<!--              clearable-->
+<!--              style="width: 45%;"-->
+<!--              filterable-->
+<!--              remote-->
+<!--              searchKey="username"-->
+<!--              :methods="getUser">-->
+<!--          </scorllSelect>-->
+<!--        </el-form-item>-->
         <el-form-item label="部门:" prop="deptId" v-if="state.title !== '修改密码' && state.form.userType !== 0">
           <el-select
               clearable
@@ -148,6 +148,7 @@
               :disabled="disabled"
               placeholder="请选择部门"
               style="width: 100%"
+              @change="getParentId"
           >
             <el-option
                 v-for="item in state.deptList"
@@ -162,6 +163,24 @@
         </el-form-item>
         <el-form-item label="专业:" prop="post" v-if="state.title !== '修改密码' && state.form.userType !== 0">
           <el-input v-model.trim="state.form.post" :disabled="disabled" placeholder="请输入专业"></el-input>
+        </el-form-item>
+        <el-form-item label="角色:" prop="roles" v-if="state.title !== '修改密码'">
+          <el-select
+              clearable
+              v-model="state.form.roles"
+              filterable
+              :disabled="disabled"
+              placeholder="请选择角色"
+              multiple
+              style="width: 100%"
+          >
+            <el-option
+                v-for="item in state.roleList"
+                :key="item.roleId"
+                :label="item.roleName"
+                :value="item.roleId"
+            />
+          </el-select>
         </el-form-item>
       </el-form>
       <template #footer v-if="state.title !='查看'">
@@ -192,7 +211,7 @@
 import {getDepart} from "@/api/orgStructure/depart";
 const emit = defineEmits(["getList"]);
 const dialogVisible = ref(false)
-const superRef = ref(null)
+const superRef = ref()
 const scrollRef = ref(null)
 
 
@@ -206,7 +225,7 @@
 
 const validateUserPhone = (rule, value, callback)=>{
   if(value === ''){
-    callback()
+    callback(new Error('请输入手机号'))
   }else{
     if(!verifyPhone(value)){
       callback(new Error('手机号格式有误'))
@@ -294,7 +313,8 @@
     post: '',
     age: null,
     personType: null,
-    positional: ''
+    positional: '',
+    roles: []
   },
   formRules:{
     name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
@@ -303,16 +323,18 @@
     username: [{ required: true, message: '请选择用户名', trigger: 'blur' }],
     password: [{ required: true, validator: validatePwd, trigger: 'blur' }],
     confirmPassword: [{ required: true, validator: equalToPassword, trigger: 'blur' }],
-    // phone: [{ validator: validateUserPhone, trigger: 'blur' }],
+    phone: [{ validator: validateUserPhone,required: true, trigger: 'blur' }],
     userType: [{ required: true, message: '请选择用户类型', trigger: 'blur' }],
     // idCard: [{ validator: verifyId, trigger: 'blur' }],
     entryTime: [{ required: true, message: '请选择入职时间', trigger: 'blur' }],
     age: [{ required: true, message: '请输入年龄', trigger: 'blur' }],
     personType: [{ required: true, message: '请选择人员类别', trigger: 'blur' }],
-    positional: [{ required: true, message: '请输入职称', trigger: 'blur' }]
+    positional: [{ required: true, message: '请输入职称', trigger: 'blur' }],
+    roles: [{ required: true, message: '请选择角色', trigger: 'blur' }]
   },
   companyList: [],
   userList: [],
+  roleList: [],
   keyword:'',
   pageNum: 1,
   pageSize: 10,
@@ -328,16 +350,16 @@
   UisMounted.value = true;
 
 });
-const showCompany = ref(false)
-const showChild = ref(false)
 const disabled = ref(false);
 const userInfo = ref()
-const openDialog = async (type, value, companyId) => {
+const openDialog = async (type, value, companyId, roleList) => {
   userInfo.value = JSON.parse(Cookies.get('userInfo'))
+  await getCompanyList()
   state.currentUserType = userInfo.value.userType
+  state.roleList = roleList
   if(state.currentUserType === 0){
     state.isAdmin = true;
-    state.form.companyId = companyId;
+    state.form.companyId = null;
   }else {
     state.isAdmin = false;
     state.form.companyId = userInfo.value.companyId;
@@ -361,20 +383,8 @@
     const res = await getUserById(value.id);
     if(res.code === 200){
       state.form = res.data
-      if(res.data.userType === 3){
-        showCompany.value = true;
-        showChild.value = true
-      }else if(res.data.userType === 2 || res.data.userType === 1 || res.data.userType === 4){
-        showCompany.value = true;
-        showChild.value = false;
-      }
-      if(res.data.userType === 3){
-        if(!res.data.parentId){
-          state.form.parentId = ''
-          state.form.parentName = '无上级账号'
-        }
-      }
     }
+    state.form.roles = value.roles.map(i=>i.roleId)
   }
   if(type == 'pwd'){
     state.form.id = value.id
@@ -390,60 +400,18 @@
 const finshed = ref(false)
 const loading = ref(false)
 
-const getCompanyList = async (val)=>{
-  if(val != ""){
-    loading.value = true;
-    const queryParams = {
-      name: val
-    }
-    const res = await getCompany(queryParams)
-    if (res.code == 200) {
-      loading.value = false;
-      state.companyList = res.data.list
-
-    } else {
-      ElMessage.warning(res.message)
-    }
-  }else {
-    loading.value = true;
-    const queryParams = {
-      pageNum: 1,
-      pageSize: 10
-    }
-    const res = await getCompany(queryParams)
-    if (res.code == 200) {
-      loading.value = false;
-      state.companyList = res.data.list
-
-    } else {
-      ElMessage.warning(res.message)
-    }
+const getCompanyList = async ()=>{
+  const queryParams = {
+    pageNum: 1,
+    pageSize: 999
   }
-
-  // if (type === 'open' && state.pageNum !== 1) {
-  // } else {
-  //   const queryParams = {
-  //     pageNum: state.pageNum,
-  //     pageSize: state.pageSize,
-  //   }
-  //   const res = await getCompany(queryParams)
-  //   if (res.code == 200) {
-  //     if (res.data.pageNum === state.pageNum) {
-  //       finshed.value = false;
-  //       if (state.pageNum == 1) {
-  //         state.companyList = res.data.list
-  //       } else {
-  //         state.companyList = state.companyList.concat(res.data.list)
-  //       }
-  //     } else {
-  //       finshed.value = true;
-  //     }
-  //
-  //   } else {
-  //     ElMessage.warning(res.message)
-  //   }
-  //   console.log("state.companyList",state.companyList)
-  // }
+  const res = await getCompany(queryParams)
+  if (res.code == 200) {
+    state.companyList = res.data.list?res.data.list:[]
+    // data.queryParams.companyId = data.companyList[0].id
+  } else {
+    ElMessage.warning(res.message)
+  }
 }
 
 const getdeptList = async (companyId)=> {
@@ -468,8 +436,14 @@
       return;
     }
     if(state.title == '新增'){
-      const {confirmPassword,id,...data} = state.form
+      const {confirmPassword,id,...data} = JSON.parse(JSON.stringify(state.form))
       data.password = Base64.encode(data.password)
+      data.roles = data.roles.map((item)=>{
+        return {
+          roleId: item,
+          roleName: state.roleList.find(i=>i.roleId == item)?.roleName
+        }
+      })
       const res = await addUser(data)
       if(res.code == 200){
         ElMessage.success(res.message)
@@ -477,11 +451,18 @@
         handleClose()
         dialogVisible.value = false;
       }else{
+
         ElMessage.warning(res.message)
       }
     }else if(state.title == '编辑'){
-      const {confirmPassword,...data} = state.form
+      const {confirmPassword,...data} = JSON.parse(JSON.stringify(state.form))
       data.password = Base64.encode(data.password)
+      data.roles = data.roles.map((item)=>{
+        return {
+          roleId: item,
+          roleName: state.roleList.find(i=>i.roleId == item)?.roleName
+        }
+      })
       const param = {
         name: data.name,
         sex:data.sex,
@@ -501,7 +482,8 @@
         companyName: data.companyName,
         age: data.age,
         personType: data.personType,
-        positional: data.positional
+        positional: data.positional,
+        roles: data.roles
       }
 
       const res = await editUser(param)
@@ -535,63 +517,54 @@
   scrollRef.value.getList(param,'change');
 }
 const changeType = async (val) => {
-  state.companyList = [];
-  if(state.isAdmin && val !=0){
-    await getCompanyList("")
-  }
-  state.form.parentId = null;
-  state.form.parentName = '';
-  state.form.companyId = null;
-  state.form.companyName = '';
+  // state.companyList = [];
+  // if(state.isAdmin){
+  //   await getCompanyList("")
+  // }
+  // state.form.parentId = null;
+  // state.form.parentName = '';
+  // state.form.companyId = null;
+  // state.form.companyName = '';
   //当前是管理员级用户
-  console.log(state.currentUserType,'type')
-  if(state.currentUserType === 0){
+
     if(state.form.userType === 0){
-      showCompany.value = false;
-      showChild.value = false;
-    }else {
-      showCompany.value = true;
-      if(state.form.userType === 3){
-        showChild.value = true
-      }else{
-        showChild.value = false;
-      }
-
+      state.form.deptId = null;
+      state.form.parentId = null;
+      state.form.companyId = null;
+      state.form.companyName = '';
+      state.form.duty = ''
+      state.form.post = ''
     }
-  }else{
-    state.form.companyId = userInfo.value.companyId;
-    state.form.companyName = userInfo.value.companyName
-    showCompany.value = true
-  }
+
   //当前是企业级/其他用户选择部门
-  if((state.currentUserType === 1 && state.form.userType === 2) || (state.currentUserType === 4 && state.form.userType === 2) || (state.currentUserType === 6 && state.form.userType === 2)){
-    state.form.parentId = userInfo.value.id;
-    state.form.companyName = userInfo.value.companyName
-    state.form.companyId = userInfo.value.companyId;
-    showChild.value = false;
-    // showCompany.value = true;
-
-  } else if((state.currentUserType === 1 && state.form.userType === 3) || (state.currentUserType === 4 && state.form.userType === 3)|| (state.currentUserType === 6 && state.form.userType === 3)){
-    state.form.companyName = userInfo.value.companyName
-    state.form.companyId = userInfo.value.companyId;
-    // showCompany.value = true;
-    showChild.value = true;
-    const param = {
-      userType: 2,
-      companyId: state.form.companyId,
-    }
-    nextTick(() => {
-      scrollRef.value.getList(param,'change');
-    })
-  }
-  //当前是部门级选择车间
-  if((state.currentUserType === 2 && state.form.userType === 3)){
-    state.form.parentId = userInfo.value.id;
-    state.form.companyName = userInfo.value.companyName
-    state.form.companyId = userInfo.value.companyId;
-    // showCompany.value = true;
-    showChild.value = false;
-  }
+  // if((state.currentUserType === 1 && state.form.userType === 2) || (state.currentUserType === 4 && state.form.userType === 2) || (state.currentUserType === 6 && state.form.userType === 2)){
+  //   state.form.parentId = userInfo.value.id;
+  //   state.form.companyName = userInfo.value.companyName
+  //   state.form.companyId = userInfo.value.companyId;
+  //   showChild.value = false;
+  //   // showCompany.value = true;
+  //
+  // } else if((state.currentUserType === 1 && state.form.userType === 3) || (state.currentUserType === 4 && state.form.userType === 3)|| (state.currentUserType === 6 && state.form.userType === 3)){
+  //   state.form.companyName = userInfo.value.companyName
+  //   state.form.companyId = userInfo.value.companyId;
+  //   // showCompany.value = true;
+  //   showChild.value = true;
+  //   const param = {
+  //     userType: 2,
+  //     companyId: state.form.companyId,
+  //   }
+  //   nextTick(() => {
+  //     scrollRef.value.getList(param,'change');
+  //   })
+  // }
+  // //当前是部门级选择车间
+  // if((state.currentUserType === 2 && state.form.userType === 3)){
+  //   state.form.parentId = userInfo.value.id;
+  //   state.form.companyName = userInfo.value.companyName
+  //   state.form.companyId = userInfo.value.companyId;
+  //   // showCompany.value = true;
+  //   showChild.value = false;
+  // }
 }
 
 const handleClose = () => {
@@ -615,10 +588,9 @@
     post: '',
     age: null,
     personType: null,
-    positional: ''
+    positional: '',
+    roles: []
   }
-  showCompany.value = false;
-  showChild.value = false;
   state.userList = [];
   state.companyList = [];
   state.pageNum = 1;
@@ -640,7 +612,6 @@
 
 const selectValue = (val) => {
   state.form.parentId = null;
-  state.form.parentName = null;
   state.companyList.forEach(item => {
     if(item.name === val){
       state.form.companyId = item.id
@@ -648,8 +619,17 @@
   })
   getdeptList(state.form.companyId)
 }
+
+const getParentId = (val)=>{
+  state.form.parentId = null;
+  state.deptList.forEach(item => {
+    if(item.deptId === val){
+      state.form.deptId = item.deptId
+      state.form.parentId = item.parentId
+    }
+  })
+}
 const getSelectUser = (val) => {
-  console.log("valllllllll",val)
   state.form.parentId = val;
 }
 

--
Gitblit v1.9.2