zhouwenxuan
2024-04-10 4bc0d3e1611da659c853a3589d84cf41d91f13d2
src/views/safetyReview/projectManage/components/siteCheckRcd.vue
@@ -2,13 +2,26 @@
  <div class="riskBox">
    <el-form ref="formRef" :model="state.formData" :rules="state.rules" class="register-form" label-position="top">
      <el-row :gutter="30" style="margin-bottom: 20px">
        <el-col :span="18">
        <el-col :span="28">
          <el-alert title="说明:现场勘验记录由项目组成员通过APP端进行信息填报,组长完成现场勘验并在APP端提交后,电脑可对资料信息完善并进行下一步操作。" type="warning" />
        </el-col>
<!--        <el-col :span="6" style="display:flex;justify-content: right">-->
<!--          <el-button type="primary">全部查看</el-button>-->
<!--          <el-button type="primary">全部下载</el-button>-->
<!--        </el-col>-->
      </el-row>
      <el-row :gutter="30" style="margin-bottom: 30px" v-if="state.data.length>0">
        <el-col :span="28">
          <div style="display: flex;align-items: center">
            <span style="font-size: 22px;font-weight: 600">记录编号:{{ chooseItem.index }}(提交时间:{{chooseItem.createTime}})</span>
            <div style="display: flex;align-items: center;flex-wrap: wrap">
              <div v-for="(item,index) in state.data">
                <el-check-tag style="margin-left: 20px;margin-top:10px;cursor: pointer" :checked="chooseItem.id === item.id" type="primary" @click="chooseRecord(item,index)">记录编号{{ index+1 }}</el-check-tag>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="6">
@@ -94,7 +107,7 @@
      </el-row>
      <el-row style="border: 1px dashed #999;border-radius: 4px;padding: 10px;margin-top: 20px;margin-bottom: 20px">
        <el-col :span="24">
          <el-form-item label="企业陪同人员照片" prop="ccompanyImages">
          <el-form-item label="企业陪同人员照片" prop="companyImages">
            <el-upload :disabled="projectType === 'view' || isEnd" accept="image/*" :action="state.uploadUrl" :data="{moduleType: 3,projectId: props.projectId}" list-type="picture-card" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile,3)" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='10' v-model:file-list="state.companyList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles,3)" >
              <el-icon><Plus /></el-icon>
              <template #tip>
@@ -116,7 +129,14 @@
import {defineEmits, onMounted, reactive, ref} from "vue"
import {ElMessage, ElMessageBox} from "element-plus"
import {Search} from '@element-plus/icons-vue'
import {addSiteCheck,editSiteCheck,getSiteCheckDetail, delFile, getFiles} from "@/api/projectManage/siteCheckRcd";
import {
  addSiteCheck,
  editSiteCheck,
  getSiteCheckDetail,
  delFile,
  getFiles,
  getDetailById, doSiteCheck
} from "@/api/projectManage/siteCheckRcd";
import { getToken } from "@/utils/auth";
import Cookies from "js-cookie"
import { useRoute } from 'vue-router'
@@ -124,7 +144,9 @@
const props = defineProps(['projectId'])
const emit = defineEmits(["getNextStatus"])
import MapLocation from "./mapLocation.vue"
const direction = ref('rtl');
const size = ref('400px')
const showDrawer = ref(false);
let checkSafetyFiles = (rule, value, callback)=>{
  if(state.safetyList.length === 0){
    callback(new Error('请上传现场安全检查表'))
@@ -152,6 +174,7 @@
const state = reactive({
  data: [],
  formData: {
    id: null,
    projectId: null,
@@ -162,7 +185,7 @@
    assAccessoryFiles: [],
    deviceImages: [],
    investingationImages: [],
    ccompanyImages:[]
    companyImages:[]
  },
  projectId: null,
  planPersons: [],
@@ -199,56 +222,95 @@
  if(props.projectId){
    getDetail(props.projectId)
  }
  isEnd.value = Cookies.get('end')
  projectType.value = route.query.type;
});
const chooseRecord = async (item, index) => {
  state.formData = item;
  state.data.forEach((i,index) => {
    if(i.id === item.id){
      chooseItem.value = i;
      chooseItem.value.index = index+1;
    }
  })
  await getPicDetail(item.id);
  showDrawer.value = false;
}
const chooseItem = ref();
const getDetail = async (val) => {
  const res = await getSiteCheckDetail({projectId: val});
  if(res.code == 200){
    if(res.data){
      state.formData = res.data;
      state.beforeDeviceList = res.data.deviceImages.map(i=>{
        return {
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.siteCheckList = res.data.investingationImages.map(i=>{
        return {
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.companyList = res.data.ccompanyImages.map(i=>{
        return {
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.safetyList = res.data.assAccessoryFiles.map(i=>{
        return {
          name: i.originName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
    if(res.data && res.data.length > 0){
      Cookies.set('btn','变更')
      state.data = res.data;
      state.formData = res.data[0];
      chooseItem.value = state.formData;
      chooseItem.value.index = 1;
      await getPicDetail(state.formData.id)
    }else {
      Cookies.set('btn','保存')
    }
  }else {
    ElMessage.warning(res.message)
  }
}
const getPicDetail = async (val) => {
  const res = await getDetailById(val);
  if(res.code == 200){
    if(res.data){
      state.formData = res.data;
      doPic(res.data)
    }
  }else {
    ElMessage.warning(res.message)
  }
}
const doPic = (val) => {
  state.beforeDeviceList = val.deviceImages?.map(i=>{
    return {
      name: i.fileName,
      url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
      id: i.id,
      projectId: i.projectId,
      moduleType: i.moduleType
    }
  })
  state.siteCheckList = val.investingationImages?.map(i=>{
    return {
      name: i.fileName,
      url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
      id: i.id,
      projectId: i.projectId,
      moduleType: i.moduleType
    }
  })
  state.companyList = val.companyImages?.map(i=>{
    return {
      name: i.fileName,
      url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
      id: i.id,
      projectId: i.projectId,
      moduleType: i.moduleType
    }
  })
  state.safetyList = val.assAccessoryFiles?.map(i=>{
    return {
      name: i.originName,
      url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
      id: i.id,
      projectId: i.projectId,
      moduleType: i.moduleType
    }
  })
}
const changeRadio = () => {
  if(state.formData.isSafetyCheck == 1){
    getSafetyFiles()
@@ -262,6 +324,14 @@
  isEnd.value = Cookies.get('end')
  state.projectId = val
  projectType.value = route.query.type;
  if(type === 'sixEnd') {
    const res = await doSiteCheck({projectId: val});
    if(res.code == 200) {
      emit('getNextStatus', val);
      }else {
        ElMessage.warning(res.message)
      }
  }
  if(type === 'detail' || type === 'edit' ){
    // await getDetail(val)
  }
@@ -273,63 +343,87 @@
        return;
      }
      if(type === 'add'){
        if(state.formData.isSafetyCheck == 1){
          state.formData.recordData = ''
        }
        const {id, ...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await addSiteCheck(data);
        if (res.code == 200) {
          ElMessage.success('保存成功')
          if(state.formData.isSafetyCheck == 0){
            if(state.safetyList && state.safetyList.length >0){
              const res = await delFile(state.safetyList[0].id)
              if(res.code == 200){
                console.log('删除原有附件')
                await getSafetyFiles()
              }else{
                ElMessage({
                  type: 'warning',
                  message: res.message
                })
              }
            }
          }
          formRef.value.clearValidate();
          emit('getNextStatus', val);
        } else {
          ElMessage.warning(res.message)
        if(!state.data.length >0){
         await saveData(val);
        }else {
          await editData();
        }
      }else if(type === 'clickEdit'){
        if(state.formData.isSafetyCheck == 1){
          state.formData.recordData = ''
        }
        const { ...data} = JSON.parse(JSON.stringify(state.formData))
        const res = await editSiteCheck(data);
        if (res.code == 200) {
          ElMessage.success('变更成功')
          if(state.formData.isSafetyCheck == 0){
            const res = await delFile(state.safetyList[0].id)
            if(res.code == 200){
              await getSafetyFiles()
            }else{
              ElMessage({
                type: 'warning',
                message: res.message
              })
            }
          }
          formRef.value.clearValidate();
          // emit('getNextStatus', data.project.id);
        } else {
          ElMessage.warning(res.message)
        }
          await editData();
      }
    }
  }
}
const saveData = async (val) => {
  if(state.formData.isSafetyCheck == 1){
    state.formData.recordData = ''
  }
  const {id, ...data} = JSON.parse(JSON.stringify(state.formData))
  const res = await addSiteCheck(data);
  if (res.code == 200) {
    ElMessage.success('保存成功')
    // const res = await doSiteCheck({projectId: val});
    // if(res.code == 200) {
    if(state.formData.isSafetyCheck == 0){
      if(state.safetyList && state.safetyList.length >0){
        console.log('删除原有附件',state.safetyList[0])
        let id = state.safetyList[0].response.data.id
        const res = await delFile(id)
        if(res.code == 200){
          console.log('删除原有附件')
          await getSafetyFiles()
        }else{
          ElMessage({
            type: 'warning',
            message: res.message
          })
        }
      }
    }
    await getDetail(val)
    formRef.value.clearValidate();
    // emit('getNextStatus', val);
    // }else {
    //   ElMessage.warning(res.message)
    // }
  } else {
    ElMessage.warning(res.message)
  }
}
const editData = async () => {
  if(state.formData.isSafetyCheck == 1){
    state.formData.recordData = ''
  }
  const { ...data} = JSON.parse(JSON.stringify(state.formData))
  const res = await editSiteCheck(data);
  if (res.code == 200) {
    ElMessage.success('变更成功')
    if(state.formData.isSafetyCheck == 0 && state.safetyList.length>0){
      const res = await delFile(state.safetyList[0].id)
      if(res.code == 200){
        await getSafetyFiles()
      }else{
        ElMessage({
          type: 'warning',
          message: res.message
        })
      }
    }
    await getPicDetail(chooseItem.value.id)
    formRef.value.clearValidate();
    // emit('getNextStatus', data.project.id);
  } else {
    ElMessage.warning(res.message)
  }
}
const getBeforeFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 1})
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 1,processId:chooseItem.value.id })
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.beforeDeviceList = res.data.map(i=>{
@@ -337,10 +431,12 @@
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          processId: state.formData.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
     state.formData.deviceImages = state.beforeDeviceList;
    }else{
      state.beforeDeviceList=[]
    }
@@ -350,7 +446,7 @@
}
const getSiteCheckFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 2})
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 2,processId:chooseItem.value.id})
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.siteCheckList = res.data.map(i=>{
@@ -358,10 +454,12 @@
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          processId: state.formData.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.formData.investingationImages = state.siteCheckList;
    }else{
      state.siteCheckList = []
    }
@@ -371,7 +469,7 @@
}
const getCompanyFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 3})
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 3,processId:chooseItem.value.id})
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.companyList = res.data.map(i=>{
@@ -379,10 +477,12 @@
          name: i.fileName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          processId: state.formData.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.formData.companyImages = state.companyList;
    }else{
      state.companyList=[]
    }
@@ -392,7 +492,7 @@
}
const getSafetyFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 5})
  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 5,processId: chooseItem.value? chooseItem.value.id:''})
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.safetyList = res.data.map(i=>{
@@ -400,10 +500,12 @@
          name: i.originName,
          url: import.meta.env.VITE_APP_BASE_API + '/' + i.path,
          id: i.id,
          processId: state.formData.id,
          projectId: i.projectId,
          moduleType: i.moduleType
        }
      })
      state.formData.assAccessoryFiles = state.safetyList
    }else{
      state.safetyList = []
    }
@@ -448,22 +550,58 @@
const handleAvatarSuccess = (res, uploadFile, type) => {
  if(res.code == 200){
    if(type == 1){
      getBeforeFiles()
      let obj = {
        name: res.data.fileName,
        url: import.meta.env.VITE_APP_BASE_API + '/' + res.data.path,
        id: res.data.id,
        processId: state.formData.id,
        projectId: res.data.projectId,
        moduleType: res.data.moduleType
      }
      state.formData.deviceImages.push(obj);
      // getBeforeFiles()
    }
    if(type == 2){
      getSiteCheckFiles()
      let obj = {
        name: res.data.fileName,
        url: import.meta.env.VITE_APP_BASE_API + '/' + res.data.path,
        id: res.data.id,
        processId: state.formData.id,
        projectId: res.data.projectId,
        moduleType: res.data.moduleType
      }
      state.formData.investingationImages.push(obj);
      // getSiteCheckFiles()
    }
    if(type == 3){
      getCompanyFiles()
      let obj = {
        name: res.data.fileName,
        url: import.meta.env.VITE_APP_BASE_API + '/' + res.data.path,
        id: res.data.id,
        processId: state.formData.id,
        projectId: res.data.projectId,
        moduleType: res.data.moduleType
      }
      state.formData.companyImages.push(obj);
      // getCompanyFiles()
    }
    if(type == 5){
      let obj = {
        name: res.data.fileName,
        url: import.meta.env.VITE_APP_BASE_API + '/' + res.data.path,
        id: res.data.id,
        processId: state.formData.id,
        projectId: res.data.projectId,
        moduleType: res.data.moduleType
      }
      state.formData.assAccessoryFiles.push(obj);
      console.log(res,'res')
      getSafetyFiles()
      // getSafetyFiles()
    }
  }else{
    ElMessage({
      type: 'warning',
      message: '文件上传失败'
      message: res.message
    })
  }
}
@@ -486,16 +624,22 @@
              message: '文件已删除'
            })
            if(type == 1){
              await getBeforeFiles()
              const index = state.formData.deviceImages.findIndex(v => v.id === file.id)
              state.formData.deviceImages.splice(index,1);
            }
            if(type == 2){
              await getSiteCheckFiles()
              const index = state.formData.investingationImages.findIndex(v => v.id === file.id)
              state.formData.investingationImages.splice(index,1);
            }
            if(type == 3){
              await getCompanyFiles()
              const index = state.formData.companyImages.findIndex(v => v.id === file.id)
              state.formData.companyImages.splice(index,1);
            }
            if(type == 5){
              await getSafetyFiles()
              const index = state.formData.assAccessoryFiles.findIndex(v => v.id === file.id)
              state.formData.assAccessoryFiles.splice(index,1);
            }
          }else{
            ElMessage({
@@ -505,18 +649,18 @@
          }
        })
        .catch(()=>{
          if(type == 1){
            getBeforeFiles()
          }
          if(type == 2){
            getSiteCheckFiles()
          }
          if(type == 3){
            getCompanyFiles()
          }
          if(type == 5){
            getSafetyFiles()
          }
          // if(type == 1){
          //   getBeforeFiles()
          // }
          // if(type == 2){
          //   getSiteCheckFiles()
          // }
          // if(type == 3){
          //   getCompanyFiles()
          // }
          // if(type == 5){
          //   getSafetyFiles()
          // }
        })
}
@@ -533,6 +677,9 @@
    font-size: 15px;
  }
}
.textColor{
  color: #3b82f6;
}
</style>