From 048a1d039d347cf109e053961865f7b01d721643 Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期三, 27 八月 2025 16:36:27 +0800
Subject: [PATCH] 修改

---
 src/views/safetyReview/projectManage/components/chooseExpert.vue |  293 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 246 insertions(+), 47 deletions(-)

diff --git a/src/views/safetyReview/projectManage/components/chooseExpert.vue b/src/views/safetyReview/projectManage/components/chooseExpert.vue
index d966997..0e8a5e9 100644
--- a/src/views/safetyReview/projectManage/components/chooseExpert.vue
+++ b/src/views/safetyReview/projectManage/components/chooseExpert.vue
@@ -8,14 +8,22 @@
             v-model.trim="queryParams.num"
             placeholder="请输入专家总人数"
             style="width: 150px;"
-            @input="queryParams.num = queryParams.num.replace(/[^1-9]/g,'')"
-            :disabled="randomDataList.length != 0"
+            @input="queryParams.num = queryParams.num.replace(/[^0-9]/g,'')"
+            :disabled="!state.isAble || state.newProgress >=3 "
+
         >
         </el-input>
       </div>
       <div class="fTop">
-        <span style="font-size: 14px">专家组组长</span>
-        <el-button type="primary" :disabled="state.info.step == 4 || state.isAdmin" style="width: 120px;margin-bottom: 10px" @click="chooseExpert('选取专家')">选取专家组组长</el-button>
+        <div style="font-size: 16px;display: flex;align-items: center">
+          专家组组长
+          <el-icon style="margin-left: 10px;margin-right: 4px;margin-top: 2px;color: #FE8E8A"><InfoFilled /></el-icon>
+          <span style="font-size: 14px;color: #FE8E8A">仅专家组组长允许固定选取,仅允许固定选取1人</span>
+        </div>
+        <div>
+          <el-button type="primary"  :disabled="state.info.step == 4 || state.isAdmin" style="width: 120px;margin-bottom: 10px" @click="chooseExpert('选取专家')">选取专家组组长</el-button>
+          <el-button type="primary"  :disabled="state.info.step == 4 || state.isAdmin" style="width: 120px;margin-bottom: 10px" @click="addOutExpertLeader">填报库外专家</el-button>
+        </div>
       </div>
       <el-table v-loading="fLoading"  :data="fixedDataList" :border="true" ref="fTableRef" style="width: 100%;">
         <el-table-column label="姓名" prop="name" align="center" />
@@ -39,7 +47,11 @@
       </el-table>
     </div>
     <div style="display: flex;flex-direction: column">
-      <span style="font-weight: 600">随机选用部分</span>
+      <div style="display: flex;align-items: center">
+        <span style="font-weight: 600">随机选用部分</span>
+        <el-icon style="margin-left: 10px;margin-right: 4px;margin-top: 2px;color: #FE8E8A"><InfoFilled /></el-icon>
+        <span style="font-size: 14px;color: #FE8E8A">随机人数为 {{queryParams.num-1}} 的5倍,可根据实际情况选取{{queryParams.num-1}} 人</span>
+      </div>
       <el-form :model="queryParams" ref="queryForm" :inline="true" style="margin-top: 10px" label-width="90px">
         <el-row :gutter="24">
           <el-col :span="8">
@@ -62,14 +74,23 @@
               <el-checkbox-group v-model="queryParams.ratingLevel" >
                 <el-checkbox v-for="item in state.levelList" :label="item.id" :key="item.id">{{ item.name }}</el-checkbox>
               </el-checkbox-group>
+
             </el-form-item>
           </el-col>
+
           <el-col :span="8">
-            <el-form-item style="float: right;" v-if="randomDataList.length == 0 && Number(queryParams.num) !=1 && queryParams.num!=''">
-              <el-button style="width: 100px;margin-right: -32px;"  :disabled="state.info.step == 4 || state.isAdmin" type="primary" @click="random">随机抽取</el-button>
-            </el-form-item>
+            <div style="display: flex;align-items: center;justify-content: flex-end">
+            <div style="float: right;" v-if=" state.newProgress < 3  && state.isAble && Number(queryParams.num) !=1 && queryParams.num!=''">
+                <el-button style="width: 100px;margin-bottom: 20px;margin-right: 10px"  :disabled="state.info.step == 4 || state.isAdmin" type="primary" @click="random">随机抽取</el-button>
+            </div>
+            <el-button type="primary"  :disabled="state.info.step == 4 || state.isAdmin" style="width: 120px;margin-bottom: 20px" @click="addOutExpertLists">填报库外专家</el-button>
+            </div>
           </el-col>
         </el-row>
+        <div style="display: flex;align-items: center;justify-content: flex-end;margin-top: -15px;margin-bottom: 10px" v-if="state.newProgress < 3">
+          <el-icon style="margin-left: 10px;margin-right: 4px;color: #FE8E8A"><InfoFilled /></el-icon>
+          <span style="font-size: 14px;color: #FE8E8A">最多可随机3次,剩余{{3-state.randomNum}}次</span>
+        </div>
 <!--        <el-row :gutter="24">-->
 <!--          <el-col :span="24">-->
 <!--            <el-form-item label="拟选用人数:">-->
@@ -84,7 +105,8 @@
 <!--          </el-col>-->
 <!--        </el-row>-->
       </el-form>
-      <el-table v-loading="rLoading"  :data="randomDataList" :border="true" ref="rTableRef" style="width: 100%;">
+      <el-table v-loading="rLoading"  :data="randomDataList" :border="true" ref="rTableRef" style="width: 100%;" @selection-change="handleSelectionChange">
+        <el-table-column type="selection" width="55" />
         <el-table-column label="姓名" prop="name" align="center" />
         <el-table-column label="性别" prop="sex" align="center" >
           <template #default="scope">
@@ -98,14 +120,15 @@
           </template>
         </el-table-column>
         <el-table-column label="专业领域" prop="domain" align="center" />
-        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
-          <template #default="scope">
-            <el-button link type="primary" @click="delR(scope.row)" :disabled="state.info.step == 4 || state.isAdmin">删除</el-button>
-          </template>
-        </el-table-column>
+<!--        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">-->
+<!--          <template #default="scope">-->
+<!--            <el-button link type="primary" @click="delR(scope.row)" :disabled="state.info.step == 4 || state.isAdmin">删除</el-button>-->
+<!--          </template>-->
+<!--        </el-table-column>-->
       </el-table>
     </div>
     <experts-list ref="expertsListRef" @getName="getSelected"></experts-list>
+    <out-expert ref="outRef" @getList="getOutItem"></out-expert>
   </div>
 </template>
 
@@ -116,9 +139,11 @@
 import {ElMessage} from "element-plus";
 import {addProject, choose, expertRound, getCheckInfo, getProjectInfo} from "@/api/projectManage";
 import Cookies from "js-cookie";
+import outExpert from './addOutExpertDialog.vue'
 
 const emit = defineEmits(["getNextStatus"]);
 const fTableRef  = ref(null);
+const outRef  = ref(null);
 const expertsListRef = ref(null)
 const fLoading = ref(false);
 const rLoading = ref(false);
@@ -140,7 +165,9 @@
     id:null,
     step: 2,
     saveData: [],
-    delData: []
+    delData: [],
+    saveOutData: [],
+    delOutData: []
   },
   info: {},
   levelList: [
@@ -159,21 +186,21 @@
   ],
   isAdmin: false,
   projectId: null,
-  newProgress: null
-
+  newProgress: null,
+  randomNum:0,
+  isAble: true
 })
-
-
+const choosedRandomList = ref([])
 const userInfo = ref()
 onMounted(async () =>{
   // localStorage.removeItem('numData')
   // localStorage.removeItem('fixedDataList')
-  // localStorage.removeItem('randomDataList')
+  // localStorage.removeItem('randomNum')
+
   if(prop.projectId){
     state.projectId = prop.projectId
     await getProjectProcess()
   }
-
   const fixListData = localStorage.getItem('fixedDataList');
   let fixDataArr = []
   if(fixListData){
@@ -181,6 +208,12 @@
     fixDataArr.forEach(item => {
       if(item.projectId == state.projectId){
         fixedDataList.value = [item.fixedData]
+        const uniqueItem = fixedDataList.value.find(itemA =>
+            !itemA.id && !state.formData.saveOutData.some(itemB => itemB.name === itemA.name)
+        );
+        if(uniqueItem){
+          state.formData.saveOutData.push(uniqueItem)
+        }
       }
     })
   }
@@ -191,7 +224,12 @@
     rondomDataArr.forEach(item => {
       if(item.projectId == state.projectId){
         randomDataList.value = item.rondomData
-
+        const uniqueItem = randomDataList.value.find(itemA =>
+            !itemA.id && !state.formData.saveOutData.some(itemB => itemB.name === itemA.name)
+        );
+        if(uniqueItem){
+          state.formData.saveOutData.push(uniqueItem)
+        }
       }
     })
   }
@@ -205,7 +243,19 @@
       }
     })
   }
-
+  const randomNumData = localStorage.getItem('randomNum')
+  let randomNumArr = []
+  if(randomNumData){
+    randomNumArr = JSON.parse(randomNumData)
+    randomNumArr.forEach(item => {
+      if(item.projectId == state.projectId){
+        state.randomNum = Number(item.randomNum)
+      }
+    })
+  }
+  if(state.randomNum == 3){
+      state.isAble = false
+  }
   userInfo.value = JSON.parse(Cookies.get('userInfo'))
   state.isAdmin = userInfo.value.admin
   await getDomain()
@@ -228,6 +278,7 @@
       fixedData: newVal[0]
     }
     if(state.newProgress < 2){
+
       saveObjectToLocalStorage('fixedDataList',data)
     }
   }
@@ -277,9 +328,13 @@
   localStorage.setItem(key, JSON.stringify(dataArray));
 }
 
-
+const typeNow = ref('')
+const firstRandomList = ref([])
 const riskOpen = async (type,val) => {
+  typeNow.value = type
   console.log("type",type,val)
+  state.projectId = val
+  await getProjectProcess()
   if(type === 'add' || type === 'clickEdit'){
     if (state.isAdmin) {
       ElMessage.warning("当前用户暂无权限");
@@ -294,13 +349,17 @@
     //   return;
     // }
   }
+
+
   //保存按钮
   if(type === 'add'){
+    // choosedRandomList.value = randomDataList.value
     let fData = []
     let rData = []
     //成功后自动到下一步 项目id
     const {...data} = state.formData
     data.id = val
+
     if(fixedDataList.value && fixedDataList.value.length > 0){
       fData = fixedDataList.value.map(item => {
         return {
@@ -312,14 +371,16 @@
       })
     }
 
-
-
-    if(randomDataList.value && randomDataList.value.length > Number(queryParams.num) - 1){
-      ElMessage.warning(`仅可保留${Number(queryParams.num) - 1}名随机专家`);
+    if(choosedRandomList.value && choosedRandomList.value.length > Number(queryParams.num) - 1){
+      ElMessage.warning(`仅可选取${Number(queryParams.num) - 1}名随机专家`);
       return
     }
-    if(randomDataList.value && randomDataList.value.length > 0){
-      rData = randomDataList.value.map(item => {
+    if(choosedRandomList.value.length < Number(queryParams.num) - 1){
+      ElMessage.warning(`随机专家数不能低于${Number(queryParams.num) - 1}人`)
+      return
+    }
+    if(choosedRandomList.value && choosedRandomList.value.length > 0){
+      rData = choosedRandomList.value.map(item => {
         return {
           expertId: item.id,
           expertName:item.name,
@@ -328,7 +389,26 @@
         }
       })
     }
+    fData = fData.filter(i => i.expertId)
+    rData = rData.filter(i => i.expertId)
+    const chooseIds = choosedRandomList.value.map(i => i.id)
+    const x = randomDataList.value.filter(i => !chooseIds.includes(i.id))
+    x.forEach(i => {
+      if(i.expertType == 1 && i.expertId){
+        data.delData.push(i.id)
+      }else if(i.expertType == 2 ){
+        if( i.id){
+          data.delOutData.push(i.id)
+          data.saveOutData = data.saveOutData.filter(f => f.id != i.id)
+        }else {
+          data.saveOutData = data.saveOutData.filter(f => f != i)
+        }
+      }
+    })
     data.saveData = fData.concat(rData)
+    data.saveOutData.forEach(item => {
+      item.projectId = state.projectId
+    })
 
     const res = await choose(data);
     if(res.code == 200){
@@ -340,24 +420,36 @@
       ElMessage.warning(res.message)
     }
   }else if(type === 'clickEdit'){
+    // choosedRandomList.value = randomDataList.value
     let fData = []
     let rData = []
     const {...data} = state.formData
     data.id = val
+
     if(fixedDataList.value && fixedDataList.value.length > 0){
       fData = fixedDataList.value.map(item => {
         return {
+          ...item,
           id: item.expertId ? item.id : '',
           expertId: item.expertId ? item.expertId : item.id,
           expertName:item.name,
           selectionMode: 1,
-          teamLeader: 1
+          teamLeader: 1,
         }
       })
     }
-    if(randomDataList.value && randomDataList.value.length > 0){
-      rData = randomDataList.value.map(item => {
+    if(choosedRandomList.value && choosedRandomList.value.length > Number(queryParams.num) - 1){
+      ElMessage.warning(`仅可选取${Number(queryParams.num) - 1}名随机专家`);
+      return
+    }
+    if(choosedRandomList.value.length < Number(queryParams.num) - 1){
+      ElMessage.warning(`随机专家数不能低于${Number(queryParams.num) - 1}人`)
+      return
+    }
+    if(choosedRandomList.value && choosedRandomList.value.length > 0){
+      rData = choosedRandomList.value.map(item => {
         return {
+          ...item,
           id: item.expertId ? item.id : '',
           expertId: item.expertId ? item.expertId : item.id,
           expertName:item.name,
@@ -366,7 +458,30 @@
         }
       })
     }
+    fData = fData.filter(i => i.expertType == 1)
+    rData = rData.filter(i => i.expertType == 1)
+    console.log('randon',randomDataList.value)
+    console.log('choodse',choosedRandomList.value)
+    const chooseIds = choosedRandomList.value.map(i => i.id)
+    const x = randomDataList.value.filter(i => !chooseIds.includes(i.id))
+    x.forEach(i => {
+      if(i.expertType == 1 && i.expertId){
+        data.delData.push(i.id)
+      }else if(i.expertType == 2 ){
+        if( i.id){
+          data.delOutData.push(i.id)
+          data.saveOutData = data.saveOutData.filter(f => f.id != i.id)
+        }else {
+          data.saveOutData = data.saveOutData.filter(f => f != i)
+        }
+      }
+    })
+
     data.saveData = fData.concat(rData)
+    data.saveOutData.forEach(item => {
+      item.projectId = state.projectId
+    })
+
     const res = await choose(data);
     if(res.code == 200){
       ElMessage.success('修改成功')
@@ -382,7 +497,11 @@
     if(res.code == 200){
       fixedDataList.value = res.data.projectExpertCheckResp.filter(item => item.selectionMode === 1)
       randomDataList.value = res.data.projectExpertCheckResp.filter(item => item.selectionMode === 2)
+      firstRandomList.value = res.data.projectExpertCheckResp.filter(item => item.selectionMode === 2)
+      const fdata = fixedDataList.value.filter(i => i.expertType == 2)
+      const rdata = randomDataList.value.filter(i => i.expertType == 2)
       state.info = res.data
+      state.formData.saveOutData = fdata.concat(rdata)
       console.log('res',fixedDataList.value)
       queryParams.num = res.data.expertNum
       removeLocal()
@@ -393,10 +512,10 @@
 }
 
 const chooseExpert = (type) => {
-  // if(fixedDataList.value && fixedDataList.value.length >0){
-  //   ElMessage.warning('只能选择一个组长')
-  //   return
-  // }
+  if(fixedDataList.value && fixedDataList.value.length >0){
+    ElMessage.warning('仅允许选择1位组长')
+    return
+  }
   expertsListRef.value.openDialog(type,fixedDataList.value,domainList.value)
 }
 
@@ -404,9 +523,11 @@
   const fData = localStorage.getItem('fixedDataList');
   const rData = localStorage.getItem('randomDataList')
   const nData = localStorage.getItem('numData')
+  const rnData = localStorage.getItem('randomNum')
   let fDataArray = [];
   let rDataArray = []
   let nDataArray = []
+  let rnDataArray = []
   if (fData) {
     try {
       fDataArray = JSON.parse(fData);
@@ -445,9 +566,27 @@
     nDataArray.splice(indexN,1)
   }
   localStorage.setItem('numData', JSON.stringify(nDataArray));
+
+  // if (rnData) {
+  //   try {
+  //     rnDataArray = JSON.parse(rnData);
+  //   } catch (e) {
+  //     console.error('数据解析失败,重置为空数组');
+  //   }
+  // }
+  // const indexRN = rnDataArray.findIndex(obj => obj.projectId == state.projectId)
+  // if(indexRN !== -1){
+  //   rnDataArray.splice(indexRN,1)
+  // }
+  // localStorage.setItem('randomNum', JSON.stringify(rnDataArray));
+}
+const handleSelectionChange = (val) => {
+  choosedRandomList.value = val
 }
 
 const getSelected = (type,data)=>{
+  data[0].expertType = 1
+
   const selectData = JSON.parse(JSON.stringify(data))
   // if(fixedDataList.value && fixedDataList.value.length > 0){
   //   fixedDataList.value.forEach(item => {
@@ -463,13 +602,22 @@
   if(fixedDataList.value && fixedDataList.value.length >0){
     state.formData.delData.push(fixedDataList.value[0].id)
   }
-
   fixedDataList.value = selectData
 }
 const delF = (val) => {
-  if(val.expertId){
-    state.formData.delData.push(val.id)
+  //库外
+  if(val.expertType == 2){
+    if(val.expertId){
+      state.formData.delOutData.push(val.id)
+    }
+    state.formData.saveOutData =  state.formData.saveOutData.filter(i => i.idCard != val.idCard)
+  }else{
+    //库内
+    if(val.expertId){
+      state.formData.delData.push(val.id)
+    }
   }
+
   fixedDataList.value = fixedDataList.value.filter(item => item.id != val.id)
 }
 
@@ -500,12 +648,12 @@
 }
 
 const random = async () => {
-  console.log('11',randomDataList.value)
-  randomDataList.value.forEach(item => {
-    if(item.expertId){
-      state.formData.delData.push(item.id)
-    }
-  })
+  console.log('first',firstRandomList.value)
+    firstRandomList.value.forEach(item => {
+      if(item.expertId && item.expertType == 1){
+        state.formData.delData.push(item.id)
+      }
+    })
   if(fixedDataList.value && fixedDataList.value.length <= 0){
     ElMessage.warning('请先选择专家组组长')
     return
@@ -527,12 +675,63 @@
   }
   const res = await expertRound(param)
   if(res.code == 200){
-    randomDataList.value = res.data
+    randomDataList.value = []
+    res.data = res.data.map(item => {
+      return{
+        ...item,
+        expertType: 1
+      }
+    })
+    const outLists = state.formData.saveOutData.filter(i => i.teamLeader == 0)
+    if(outLists && outLists.length >0){
+      randomDataList.value = outLists.concat(res.data)
+    }else {
+      randomDataList.value = res.data
+    }
+    state.randomNum = state.randomNum + 1
+    const obj = {
+      projectId: state.projectId,
+      randomNum: state.randomNum
+    }
+    saveObjectToLocalStorage('randomNum',obj)
+    if(state.randomNum == 3){
+      state.isAble = false
+    }
   }else{
     ElMessage.warning(res.message)
   }
   rLoading.value = false
 }
+const addOutExpertLeader = () => {
+  if(fixedDataList.value.length>0){
+    ElMessage.warning('仅允许选取1名专家组长')
+    return;
+  }
+  outRef.value.openDialog('leader')
+}
+const addOutExpertLists = () => {
+  outRef.value.openDialog('')
+}
+
+const getOutItem = (val) => {
+  console.log('val',val)
+  val.expertType = 2
+  if(val.teamLeader == 1){
+    fixedDataList.value.push(val)
+    const data = {
+      projectId :state.projectId,
+      fixedData: val
+    }
+    if(state.newProgress < 2){
+      saveObjectToLocalStorage('fixedDataList',data)
+    }
+  }else {
+    // choosedRandomList.value.push(val)
+    randomDataList.value.push(val)
+  }
+  state.formData.saveOutData.push(val)
+
+}
 
 defineExpose({
   riskOpen

--
Gitblit v1.9.2