马宇豪
2025-03-04 1b9fea7d4af68d8f933b2dc42bf6084b9646f64c
src/views/newSpecialWorkSystem/workTicket/wdsq/components/spaceDialog.vue
@@ -1,12 +1,12 @@
<template>
   <div class="home-container">
    <el-dialog v-model="showDialog" title="修改申报" @close="clearFile()" width="80%" :close-on-click-modal="false">
      <el-form :model="form" label-width="180px" :rules="applyRules" ref="ruleFormRef">
<!--   <div class="home-container">-->
    <el-dialog v-model="showDialog" :title="title" @close="clearFile()" width="80%" :close-on-click-modal="false">
      <el-form :model="form" label-width="180px" :disabled="isDisabled" :rules="applyRules" ref="ruleFormRef">
         <div class="homeCard">
      <el-row>
        <el-col :span="12">
          <el-form-item label="作业申请单位" prop="applyDepId">
            <el-cascader style="width: 100%" v-model="form.applyDepId" :options="lists.departList2" :props="props1" :show-all-levels="false" placeholder="明确到具体车间" @change="findParent" clearable/>
            <el-cascader style="width: 100%" v-model="form.applyDepId" :options="lists.departList" :props="props1" :show-all-levels="false" placeholder="明确到具体车间" @change="findParent" clearable/>
          </el-form-item>
        </el-col>
      </el-row>
@@ -77,15 +77,15 @@
        </el-col>
        <el-col :span="12">
          <el-form-item label="作业人" prop="operatorUids">
            <el-select v-model="form.operatorUids" filterable multiple clearable>
              <el-option
                  v-for="item in zyList"
                  :key="item.uid"
                  :label="item.realName"
                  :value="item.uid"
              />
            </el-select>
            <!--            <el-cascader style="width: 100%" v-model="form.operatorUids" :options="lists.spList.opList" :props="cas2Props" @change="singleSelect($event,'作业人')" filterable :show-all-levels="false"/>-->
<!--            <el-select v-model="form.operatorUids" filterable multiple clearable>-->
<!--              <el-option-->
<!--                  v-for="item in zyList"-->
<!--                  :key="item.uid"-->
<!--                  :label="item.realName"-->
<!--                  :value="item.uid"-->
<!--              />-->
<!--            </el-select>-->
            <el-cascader style="width: 100%" v-model="form.operatorUids" :options="zyList?zyList:lists.spList.opList" :props="cas2Props" @change="singleSelect($event,'作业人')" filterable :show-all-levels="false"/>
          </el-form-item>
        </el-col>
         </el-row>
@@ -251,8 +251,8 @@
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="完工验收" prop="acceptUid">
              <el-select v-model="form.acceptUid" filterable clearable>
            <el-form-item label="完工验收" prop="acceptUids">
              <el-select v-model="form.acceptUids" filterable multiple clearable>
                <el-option
                    v-for="item in lists.workerList"
                    :key="item.uid"
@@ -277,29 +277,29 @@
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="最终审批人" prop="lastApprover">
              <el-select v-model="form.lastApprover" filterable clearable>
                <el-option
                    v-for="item in lists.workerList"
                    :key="item.uid"
                    :label="item.username"
                    :value="item.uid"
                />
              </el-select>
<!--              <el-cascader style="width: 100%" v-model="form.lastApprover" :options="lists.workerList" :props="cas4Props" filterable :show-all-levels="false"/>-->
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="最终审批人" prop="lastApprover">-->
<!--              <el-select v-model="form.lastApprover" filterable clearable>-->
<!--                <el-option-->
<!--                    v-for="item in lists.workerList"-->
<!--                    :key="item.uid"-->
<!--                    :label="item.username"-->
<!--                    :value="item.uid"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
         </div>
      </el-form>
      <div class="applyBtn">
         <el-button type="primary" size="large" plain @click="submitForm(ruleFormRef)" v-throttle>提交申报</el-button>
      <el-button v-if="title == '修改'" type="primary" size="large" plain v-throttle @click="submitForm(ruleFormRef)">提交修改</el-button>
      <el-button v-if="title == '续票'" type="primary" size="large" plain v-throttle @click="submitForm(ruleFormRef)">一键续票</el-button>
      </div>
    <work-select ref="workSelectRef" @refreshWorks="getSelected()"></work-select>
    </el-dialog>
   </div>
<!--   </div>-->
</template>
<script lang="ts">
@@ -316,10 +316,13 @@
import {userApi} from "/@/api/systemManage/user";
   interface stateType {
      form: Object,
    isDisabled: boolean
    title: string
      equipmentDialog: boolean,
    showDialog: boolean
    props1:{},
    depProps:{},
    cas2Props: {}
    safetyMeasureBasicList: []
    zyList: []
    tabLoading: boolean
@@ -337,6 +340,8 @@
            equipmentDialog: false,
        safetyMeasureBasicList: [],
        zyList: [],
        isDisabled: false,
        title: '修改',
            form: {
          id: null,
          workType: 2,
@@ -356,7 +361,7 @@
          involveOtherWork: [],
          safetyMeasureUids: [],
          approvalDepBasicList: [],
          acceptUid: null,
          acceptUids: [],
          lastApprover: null,
          startOrEndUids: [],
          cameraIds: [],
@@ -379,7 +384,14 @@
          multiple: true,
          checkStrictly: true,
          emitPath: false
        }
        },
        cas2Props: {
          value: 'uid',
          label: 'realName',
          multiple: true,
          checkStrictly: true,
          children: 'certList'
        },
         });
         const ruleFormRef = ref<FormInstance>()
         const applyRules = reactive<FormRules>({
@@ -397,7 +409,7 @@
        expStartTime: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        expEndTime: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        safetyMeasureUids: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        acceptUid: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        acceptUids: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        lastApprover: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
        startOrEndUids: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            "workDetail.csName": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
@@ -413,18 +425,49 @@
        workSelectRef.value.openDialog(state.form.involveOtherWork)
      }
      const getWorkerList = ()=>{
        const filteredList = props.lists.spList.opList.filter(i => state.form.workDepIds.includes(i.depId));
        let idList:Array<any> = []
        for(let i of state.form.workDepIds){
          idList = idList.concat(getListFromDep(getIdListsFormDepId(props.lists.departList,i)))
        }
        const depLists = [...new Set(idList)]
        const filteredList = props.lists.spList.opList.filter(i => depLists.includes(i.depId));
        if(filteredList && filteredList.length>0){
          state.zyList = filteredList
        }else{
          state.zyList = props.lists.spList.opList
        }
      }
      const getListFromDep = (dep) =>{
        let depIds = []
        depIds.push(dep.depId)
        if (Array.isArray(dep.children)) {
          for (let child of dep.children) {
            depIds = depIds.concat(getListFromDep(child));
          }
        }
        return depIds;
      }
      const getIdListsFormDepId=(DepList:Array<any>,id:number)=>{
        for(const i of DepList){
          if(i.depId === id){
            return i
          }
          if(Array.isArray(i.children)){
            const node:any = getIdListsFormDepId(i.children,id)
            if(node){
              return node
            }
          }
        }
        return null
      }
      const getSelected = ()=>{
        state.form.involveOtherWork = workSelectRef.value.selected
      }
      const openDialog = (row)=>{
      const openDialog = (row,type)=>{
        clearFile()
        state.zyList = props.lists.spList.opList
        getBasicData()
@@ -433,7 +476,13 @@
            state.form[key] = JSON.parse(JSON.stringify(row))[key];
          }
        })
        state.form.operatorUids = row.operatorList.map(i=>i.userId)
        state.form.operatorUids = row.operatorList.map(i=>{
          if(i.certExpiredAt && i.certExpiredAt !==''){
            return [i.userId,i.certificate + ',' + i.certExpiredAt]
          }else{
            return [i.userId]
          }
        })
        state.form.headUids = row.headList.map(i=>i.userId)
        state.form.analystUids = row.analystList.map(i=>i.userId)
        state.form.guardianUids = row.guardianList.map(i=>i.userId)
@@ -447,14 +496,23 @@
          approvalUids: item.approvalPersonList.filter(j=>j.type == 5).map(i=>i.userId),
          approvalType: item.approvalType
        }))
        console.log(state.form.approvalDepBasicList,777)
        state.form.acceptUid = row.acceptUser.userId
        state.form.acceptUids = row.acceptUserList.map(i=>i.userId)
        state.form.startOrEndUids = row.startOrEndList.map(i=>i.userId)
        state.form.lastApprover = row.lastApprover.userId
        // state.form.lastApprover = row.lastApprover.userId
        if(row.workDepList && row.workDepList.length>0){
          state.form.workDepIds = row.workDepList.map(i=>i.workDepId)
        }else{
          state.form.workDepIds.push(row.workDepId)
        }
        if(type == 'edit'){
          state.isDisabled = false
          state.title = '修改'
        }else{
          if(!state.form.id){
            state.form.id = row.workApplyId
          }
          state.isDisabled = true
          state.title = '续票'
        }
        getWorkerList()
        state.showDialog = true
@@ -480,7 +538,7 @@
          involveOtherWork: [],
          safetyMeasureUids: [],
          approvalDepBasicList: [],
          acceptUid: null,
          acceptUids: [],
          lastApprover: null,
          startOrEndUids: [],
          cameraIds: [],
@@ -494,7 +552,7 @@
      }
      const findParent = ()=>{
        state.form.seDepId = findTopLevelId(props.lists.departList2,state.form.applyDepId)
        state.form.seDepId = findTopLevelId(props.lists.departList,state.form.applyDepId)
      }
      function findTopLevelId(tree, targetId) {
@@ -556,6 +614,37 @@
        return index === 0;
      }
      const singleSelect=(value,type)=>{
        let selected = value
        if(selected.length>1){
          const temp = []
          for(let i of selected){
            const index = temp.findIndex(item => item[0] === i[0]);
            if (index !== -1) {
              temp[index] = i
            }else{
              temp.push(i)
            }
          }
          if(type == '作业人'){state.form.operatorUids = JSON.parse(JSON.stringify(temp))}
          // if(type == '分析人'){state.form.analystUids = temp}
          if(type == '监护人'){state.form.guardianUids = temp}
          if(type == '确认人'){state.form.safetyMeasureUids = temp}
          if(type == '结束人'){state.form.startOrEndUids = temp}
        }
      }
      const transformArr = (arr: Array<any>)=>{
        return arr.map((i)=>{
          return {
            uid: i[0],
            certificate: i[1]?i[1].split(',')[0]:'',
            certExpiredAt: i[1]?i[1].split(',')[1]:'',
            certTypeName: ''
          }
        })
      }
      const transform2Arr = (arr: Array<any>)=>{
        return arr.map((i)=>{
          return {
@@ -594,33 +683,56 @@
            // }
            state.form.riskIdentification = state.form.riskIdentification.join(',')
            const {...data} = state.form
            data.operatorUids = transform2Arr(data.operatorUids)
            data.operatorUids = transformArr(data.operatorUids)
            data.headUids = transform2Arr(data.headUids)
            // data.analystUids = transformArr(data.analystUids)
            data.guardianUids = transform2Arr(data.guardianUids)
            data.safetyMeasureUids = transform2Arr(data.safetyMeasureUids)
            data.startOrEndUids = transform2Arr(data.startOrEndUids)
            data.acceptUid = transform2Obj(data.acceptUid)
            data.acceptUids = transform2Arr(data.acceptUids)
            data.lastApprover = transform2Obj(data.lastApprover)
            const res = await workApplyApi().modSpaceApply(data)
            if (res.data.code === '200') {
              ElMessage({
                type: 'success',
                message: '提交成功!'
              });
              formEl.resetFields()
              state.form.guardianUids = []
              state.form.involveOtherWork = []
              getBasicData()
              clearFile()
              context.emit('refresh')
            } else {
              ElMessage({
                type: 'warning',
                message: res.data.msg
              });
              // state.form.involveOtherWork = state.form.involveOtherWork.split(',')
              state.form.riskIdentification = state.form.riskIdentification.split(',')
            if(state.title == '修改'){
              const res = await workApplyApi().modSpaceApply(data)
              if (res.data.code === '200') {
                ElMessage({
                  type: 'success',
                  message: '提交成功!'
                });
                formEl.resetFields()
                state.form.guardianUids = []
                state.form.involveOtherWork = []
                getBasicData()
                clearFile()
                context.emit('refresh')
              } else {
                ElMessage({
                  type: 'warning',
                  message: res.data.msg
                });
                // state.form.involveOtherWork = state.form.involveOtherWork.split(',')
                state.form.riskIdentification = state.form.riskIdentification.split(',')
              }
            }else{
              const res = await workApplyApi().renewalConfinedspace(data)
              if (res.data.code === '200') {
                ElMessage({
                  type: 'success',
                  message: '续票成功!'
                });
                formEl.resetFields()
                state.form.guardianUids = []
                state.form.involveOtherWork = []
                getBasicData()
                clearFile()
                context.emit('refresh')
              } else {
                ElMessage({
                  type: 'warning',
                  message: res.data.msg
                });
                // state.form.involveOtherWork = state.form.involveOtherWork.split(',')
                state.form.riskIdentification = state.form.riskIdentification.split(',')
              }
            }
          } else {
            console.log('error submit!', fields)
@@ -639,6 +751,7 @@
            await initBackEndControlRoutes();
         };
         return {
        singleSelect,
            renderMenu,
        getBasicData,
        getWorkerList,