lex-xin 3 anni fa
parent
commit
c5c970fd40
1 ha cambiato i file con 49 aggiunte e 26 eliminazioni
  1. 49 26
      src/views/categroyManager/insideSetting/staffManager.vue

+ 49 - 26
src/views/categroyManager/insideSetting/staffManager.vue

@@ -217,7 +217,20 @@
                        :value="item.id"></el-option>
           </select-all>
         </el-form-item>
-
+        <el-form-item label="所属部门"
+                      prop="deptIds"
+                      :label-width="formLabelWidth">
+          <el-cascader
+                v-model="form.deptIds"
+                placeholder="请选择所属部门"
+                clearable
+                style="width: 100%;"
+                :options="deptList"
+                :show-all-levels="false"
+                :collapse-tags="true"
+                :props="{ multiple: true, checkStrictly: false }"
+              ></el-cascader>
+        </el-form-item>
         <div v-for="(postDeptIds, index) in form.postDeptIds" :key="index">
           <el-form-item
                 :label="'岗位管理' + (index + 1)"
@@ -229,7 +242,7 @@
               <el-select
                       filterable
                       clearable
-                      placeholder="请选择所属岗位"
+                      placeholder="所属岗位(必填)"
                       style="width: 180px !important"
                       v-model.trim="postDeptIds.postId">
                 <el-option v-for="item in postList"
@@ -242,10 +255,11 @@
                 class="setWidth"
                 style="margin: 0 10px;width: 190px !important;"
                 :prop="'postDeptIds.' + index + '.deptIds'"
-                :rules="[{ type: 'array', required: true, message: '请选择所属部门', trigger: 'change' }]"
               >
                 <el-cascader
                   v-model="postDeptIds.deptIds"
+                  placeholder="所属部门(非必填)"
+                  clearable
                   :options="deptList"
                   :show-all-levels="false"
                   :collapse-tags="true"
@@ -424,7 +438,7 @@ export default {
           postId: null,
           deptIds: []
         }],
-        // deptIds: [],
+        deptIds: [],
         // postIds: [],
         jobNature: null,
         entryDate: null,
@@ -437,7 +451,7 @@ export default {
         phone: [{ type: 'number', required: true, validator: validPhone, trigger: 'blur' }, { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }],
         roleIds: [{ type: 'array', required: true, message: '请选择分类', trigger: 'change' }],
         organIdLists: [{ type: 'array', required: true, message: '请选择所属分部', trigger: 'change' }],
-        // deptIds: [{ type: 'array', required: true, message: '请选择所属部门', trigger: 'change' }],
+        deptIds: [{ type: 'array', required: true, message: '请选择所属部门', trigger: 'change' }],
         // postIds: [{ type: 'array', required: true, message: '请选择所属岗位', trigger: 'change' }],
         jobNature: [{ required: true, message: '请选择工作类型', trigger: 'change' }],
         entryDate: [{ required: true, message: '请选择入职时间', trigger: 'blur' }],
@@ -471,7 +485,7 @@ export default {
     onRoleSubmit (formName) {
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          const { organIdLists, postDeptIds, ...res } = this.form
+          const { organIdLists, postDeptIds, deptIds, ...res } = this.form
           let tempPost = []
           postDeptIds.forEach(post => {
             let tempIds = []
@@ -483,10 +497,15 @@ export default {
               deptIds: tempIds
             })
           })
+          const tempDeptIds = []
+          deptIds.forEach(ds => {
+            tempDeptIds.push(ds[ds.length - 1])
+          })
 
           let tempForm = {
             postDeptIds: JSON.stringify(tempPost),
             organIdList: organIdLists.join(','),
+            deptIds: tempDeptIds,
             ...res
           }
           if (this.formActionTitle == 'create') {
@@ -612,32 +631,34 @@ export default {
       if (type == 'update') {
         // 初始化数据
         let postDeptArr = []
-        if(data.postDeptIds) {
-          const postDept = JSON.parse(data.postDeptIds) || []
-          if(postDept.length > 0) {
-            postDept.forEach(dept => {
-              let deptIds = dept.deptIds || []
-              let deptArr = []
-              deptIds.forEach(ds => {
-                deptArr.push(this.formatParentId(ds, this.deptList))
-              })
-              postDeptArr.push({
-                postId: dept.postId,
-                deptIds: deptArr
-              })
+        const postDept = data.postDeptIds ? JSON.parse(data.postDeptIds) : []
+
+        if(postDept.length > 0) {
+          postDept.forEach(dept => {
+            let deptIds = dept.deptIds || []
+            let deptArr = []
+            deptIds.forEach(ds => {
+              deptArr.push(this.formatParentId(ds, this.deptList))
             })
-          } else {
-            postDeptArr = [{
-              postId: null,
-              deptIds: []
-            }]
-          }
+            postDeptArr.push({
+              postId: dept.postId,
+              deptIds: deptArr
+            })
+          })
         } else {
           postDeptArr = [{
             postId: null,
             deptIds: []
           }]
         }
+
+        const deptIds = data.deptIds ? eval(data.deptIds) : []
+        const tempDeptIds = []
+        if(deptIds.length > 0) {
+          deptIds.forEach(ds => {
+            tempDeptIds.push(this.formatParentId(ds, this.deptList))
+          })
+        }
         this.form = {
           id: data.id,
           realName: data.realName,
@@ -649,7 +670,8 @@ export default {
           entryDate: data.entryDate,
           contactAddress: data.contactAddress,
           postalCode: data.postalCode,
-          postDeptIds: postDeptArr
+          postDeptIds: postDeptArr,
+          deptIds: tempDeptIds
         }
       }
     },
@@ -679,6 +701,7 @@ export default {
         entryDate: null,
         contactAddress: null,
         postalCode: null,
+        deptIds: [],
         postDeptIds: [{
           postId: null,
           deptIds: []