From eee656c8d1aab0b5aa8935bf1630f782321fc7f4 Mon Sep 17 00:00:00 2001
From: zhouwenxuan <1175765986@qq.com>
Date: 星期三, 21 二月 2024 16:53:35 +0800
Subject: [PATCH] bug修改

---
 src/views/safetyReview/projectManage/components/siteCheckRcd.vue |  469 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 410 insertions(+), 59 deletions(-)

diff --git a/src/views/safetyReview/projectManage/components/siteCheckRcd.vue b/src/views/safetyReview/projectManage/components/siteCheckRcd.vue
index 1c0da84..9f7626f 100644
--- a/src/views/safetyReview/projectManage/components/siteCheckRcd.vue
+++ b/src/views/safetyReview/projectManage/components/siteCheckRcd.vue
@@ -1,12 +1,21 @@
 <template>
   <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-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">
         <el-col :span="6">
           <el-form-item prop="investigationDate" label="现场勘验时间">
             <el-date-picker
                 style="width: 100%"
-                v-model="state.formData.investigationPlanDate"
+                v-model="state.formData.investigationDate"
                 type="date"
                 value-format="YYYY-MM-DD 00:00:00"
                 placeholder="选择日期"
@@ -15,7 +24,7 @@
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item prop="investigationDate" label="现场勘验位置">
+          <el-form-item prop="location" label="现场勘验位置">
             <el-input
                 v-model="state.formData.location"
                 size="large"
@@ -29,61 +38,116 @@
         </el-col>
         <el-col :span="6">
           <el-form-item prop="isSafetyCheck" label="编制现场安全检查表">
-            <el-radio-group v-model="state.formData.isSafetyCheck" size="large">
-              <el-radio :label="true" size="large">是</el-radio>
-              <el-radio :label="false" size="large">否</el-radio>
+            <el-radio-group v-model="state.formData.isSafetyCheck" size="large" @change="changeRadio">
+              <el-radio :label="1" size="large">是</el-radio>
+              <el-radio :label="0" size="large">否</el-radio>
             </el-radio-group>
           </el-form-item>
         </el-col>
       </el-row>
-<!--      <el-row :gutter="30">-->
-<!--        <el-col :span="6">-->
-<!--          <el-form-item label="附件上传">-->
-<!--            <el-upload-->
-<!--                accept="image/*"-->
-<!--                :action="state.uploadUrl"-->
-<!--                :headers="state.header"-->
-<!--                method="post"-->
-<!--                :on-success="(response, file, fileList) => handleAvatarSuccess(response, file, fileList, 1)"-->
-<!--                :on-preview="handlePictureCardPreview"-->
-<!--                v-model:file-list="state.socialList"-->
-<!--                list-type="picture-card"-->
-<!--                :before-upload="picSize"-->
-<!--                :on-remove="(file, file_list)=>{handleRemove(file, file_list, 1)}"-->
-<!--            >-->
-<!--              <el-icon><Plus /></el-icon>-->
-<!--              <template #tip>-->
-<!--                <div class="el-upload__tip">上传jpg/png图片尺寸小于5M</div>-->
-<!--              </template>-->
-<!--            </el-upload>-->
-<!--          </el-form-item>-->
-<!--        </el-col>-->
-<!--      </el-row>-->
-      <el-form-item prop="recordData" label="现场勘验记录">
-        <el-input
-            v-model="state.formData.recordData"
-            :autosize="{ minRows: 6 }"
-            maxlength="200"
-            show-word-limit
-            type="textarea">
-        </el-input>
-      </el-form-item>
-      <el-form-item label="企业陪同照片">
-
-      </el-form-item>
+      <el-row :gutter="30">
+        <el-col :span="24" v-if="state.formData.isSafetyCheck == 1">
+          <el-form-item label="安全检查表上传" prop="assAccessoryFiles">
+            <el-upload accept="image/*,.pdf,.doc,.docx,.xlsx,.xls" :action="state.uploadUrl" :data="{moduleType: 5,projectId: props.projectId}" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile,5)" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='1' v-model:file-list="state.safetyList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles,5)">
+              <el-button type="primary">附件上传</el-button>
+              <template #tip>
+                <div class="el-upload__tip">上传文件尺寸小于5M,最多可上传1份</div>
+              </template>
+            </el-upload>
+          </el-form-item>
+        </el-col>
+        <el-col :span="24" v-if="state.formData.isSafetyCheck == 0">
+          <el-form-item prop="recordData" label="现场勘验记录">
+            <el-input
+                v-model="state.formData.recordData"
+                :autosize="{ minRows: 6 }"
+                maxlength="200"
+                show-word-limit
+                type="textarea">
+            </el-input>
+          </el-form-item>
+        </el-col>
+      </el-row>
+      <el-row style="border: 1px dashed #999;border-radius: 4px;padding: 10px;margin-top: 20px">
+        <el-col :span="24">
+          <el-form-item label="主要装置前合影照片" prop="deviceImages">
+            <el-upload accept="image/*" :action="state.uploadUrl" :data="{moduleType: 1,projectId: props.projectId}" list-type="picture-card" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile,1)" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='10' v-model:file-list="state.beforeDeviceList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles,1)" >
+              <el-icon><Plus /></el-icon>
+              <template #tip>
+                <div class="el-upload__tip">上传照片尺寸小于5M,最多可上传10张</div>
+              </template>
+            </el-upload>
+          </el-form-item>
+        </el-col>
+      </el-row>
+      <el-row style="border: 1px dashed #999;border-radius: 4px;padding: 10px;margin-top: 20px">
+        <el-col :span="24">
+          <el-form-item label="现场勘验照片" prop="investingationImages">
+            <el-upload accept="image/*" :action="state.uploadUrl" :data="{moduleType: 2,projectId: props.projectId}" list-type="picture-card" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile,2)" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='10' v-model:file-list="state.siteCheckList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles,2)" >
+              <el-icon><Plus /></el-icon>
+              <template #tip>
+                <div class="el-upload__tip">上传照片尺寸小于5M,最多可上传10张</div>
+              </template>
+            </el-upload>
+          </el-form-item>
+        </el-col>
+      </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-upload 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>
+                <div class="el-upload__tip">上传照片尺寸小于5M,最多可上传10张</div>
+              </template>
+            </el-upload>
+          </el-form-item>
+        </el-col>
+      </el-row>
     </el-form>
+    <el-dialog v-model="state.imgDialog">
+      <img style="width: 100%" :src="state.imgUrl" alt="Preview Image" />
+    </el-dialog>
     <map-location ref="mapLocationRef" @giveLatLng="achieveLatLng"></map-location>
   </div>
 </template>
 <script setup>
 
 import {defineEmits, onMounted, reactive, ref} from "vue"
-import {ElMessage} from "element-plus"
+import {ElMessage, ElMessageBox} from "element-plus"
 import {Search} from '@element-plus/icons-vue'
-import {addRisk, editRisk, getRiskDetail} from "@/api/projectManage/riskAnalysis"
+import {addSiteCheck,editSiteCheck,getSiteCheckDetail, delFile, getFiles} from "@/api/projectManage/siteCheckRcd";
+import { getToken } from "@/utils/auth";
 import Cookies from "js-cookie"
+const props = defineProps(['projectId'])
 const emit = defineEmits(["getNextStatus"])
 import MapLocation from "./mapLocation.vue"
+
+let checkSafetyFiles = (rule, value, callback)=>{
+  if(state.safetyList.length === 0){
+    callback(new Error('请上传现场安全检查表'))
+  }else{
+    callback()
+  }
+}
+
+let checkInvestFiles = (rule, value, callback)=>{
+  if(state.siteCheckList.length === 0){
+    callback(new Error('请上传现场勘验照片'))
+  }else{
+    callback()
+  }
+}
+
+let checkCompanyFiles = (rule, value, callback)=>{
+  if(state.companyList.length === 0){
+    callback(new Error('请上传企业陪同人员照片'))
+  }else{
+    callback()
+  }
+}
+
+
 
 const state = reactive({
   formData: {
@@ -92,12 +156,34 @@
     investigationDate: '',
     location: '',
     isSafetyCheck: null,
-    recordData: ''
+    recordData: '',
+    assAccessoryFiles: [],
+    deviceImages: [],
+    investingationImages: [],
+    ccompanyImages:[]
   },
+  projectId: null,
   planPersons: [],
   rules: {
-    recordData: [{required: true, message: '请填写现场勘验记录', trigger: 'blur'}]
-  }
+    investigationDate: [{required: true, message: '请选择现场勘验时间', trigger: 'blur'}],
+    location: [{required: true, message: '请选择现场勘验位置', trigger: 'blur'}],
+    isSafetyCheck: [{required: true, message: '请选择是否编制现场安全检查表', trigger: 'blur'}],
+    recordData: [{required: true, message: '请填写现场勘验记录', trigger: 'blur'}],
+    assAccessoryFiles: [{required: true, validator: checkSafetyFiles, trigger: 'blur'}],
+    // investingationImages: [{required: true, validator: checkInvestFiles, trigger: 'blur'}],
+    // ccompanyImages: [{required: true, validator: checkCompanyFiles, trigger: 'blur'}]
+  },
+  beforeDeviceList: [],
+  siteCheckList: [],
+  companyList: [],
+  safetyList: [],
+  imgLimit: 1,
+  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/manage/accessory-file/uploadFile',
+  header: {
+    Authorization: getToken()
+  },
+  imgDialog: false,
+  imgUrl: ''
 })
 
 const isAmin = ref(false)
@@ -108,19 +194,71 @@
   if(userInfo.identity === 0){
     isAmin.value = true;
   }
+  if(props.projectId){
+    getDetail(props.projectId)
+  }
+
 });
 
-const riskOpen = async (type,val) => {
-  console.log("type",type,val)
-  if(type === 'detail' || type === 'edit' ){
-    const res = await getRiskDetail({projectId: val});
-    if(res.code == 200){
+const getDetail = async (val) => {
+  const res = await getSiteCheckDetail({projectId: val});
+  if(res.code == 200){
+    if(res.data){
       state.formData = res.data;
-      state.formData.project.business = parseInt(res.data.project.business);
-      state.formData.project.area = [res.data.project.province,res.data.project.city];
-    }else {
-      ElMessage.warning(res.message)
+      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
+        }
+      })
     }
+
+  }else {
+    ElMessage.warning(res.message)
+  }
+}
+const changeRadio = () => {
+  if(state.formData.isSafetyCheck == 1){
+    getSafetyFiles()
+  }
+}
+
+
+const riskOpen = async (type,val) => {
+  state.formData.projectId = val
+  state.projectId = val
+  if(type === 'detail' || type === 'edit' ){
+    // await getDetail(val)
   }
   if(type === 'add' || type === 'clickEdit') {
     const valid = await formRef.value.validate();
@@ -130,21 +268,51 @@
         return;
       }
       if(type === 'add'){
-        const {projectId, ...data} = JSON.parse(JSON.stringify(state.formData))
-        const res = await addRisk(data);
+        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', res.data);
-
+          emit('getNextStatus', val);
         } else {
           ElMessage.warning(res.message)
         }
       }else if(type === 'clickEdit'){
+        if(state.formData.isSafetyCheck == 1){
+          state.formData.recordData = ''
+        }
         const { ...data} = JSON.parse(JSON.stringify(state.formData))
-        const res = await editRisk(data);
+        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 {
@@ -155,6 +323,90 @@
   }
 }
 
+const getBeforeFiles = async (id)=>{
+  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 1})
+  if(res.code == 200){
+    if(res.data && res.data.length>0){
+      state.beforeDeviceList = res.data.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
+        }
+      })
+    }else{
+      state.beforeDeviceList=[]
+    }
+  }else {
+    ElMessage.warning(res.message)
+  }
+}
+
+const getSiteCheckFiles = async (id)=>{
+  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 2})
+  if(res.code == 200){
+    if(res.data && res.data.length>0){
+      state.siteCheckList = res.data.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
+        }
+      })
+    }else{
+      state.siteCheckList = []
+    }
+  }else {
+    ElMessage.warning(res.message)
+  }
+}
+
+const getCompanyFiles = async (id)=>{
+  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 3})
+  if(res.code == 200){
+    if(res.data && res.data.length>0){
+      state.companyList = res.data.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
+        }
+      })
+    }else{
+      state.companyList=[]
+    }
+  }else {
+    ElMessage.warning(res.message)
+  }
+}
+
+const getSafetyFiles = async (id)=>{
+  const res = await getFiles({projectId: id ? id : props.projectId,moduleType: 5})
+  if(res.code == 200){
+    if(res.data && res.data.length>0){
+      state.safetyList = res.data.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
+        }
+      })
+    }else{
+      state.safetyList = []
+    }
+  }else {
+    ElMessage.warning(res.message)
+  }
+}
+
 const openLocation = ()=>{
   mapLocationRef.value.openMapLocation(state.formData.location.split(',')[0],state.formData.location.split(',')[1])
 }
@@ -163,6 +415,105 @@
   state.formData.location = lng + ',' + lat
 }
 
+// 图片上传
+const showTip =()=>{
+  ElMessage({
+    type: 'warning',
+    message: '超出文件上传数量'
+  });
+}
+
+const picSize = async (rawFile) => {
+  if(rawFile.size / 1024 / 1024 > 5){
+    ElMessage({
+      type: 'warning',
+      message: '文件大小不能超过5M'
+    });
+    return false
+  }
+};
+
+const handlePictureCardPreview = (uploadFile) => {
+  console.log(uploadFile,'file')
+  state.imgUrl = uploadFile.url
+  state.imgDialog = true
+};
+
+
+const handleAvatarSuccess = (res, uploadFile, type) => {
+  if(res.code == 200){
+    if(type == 1){
+      getBeforeFiles()
+    }
+    if(type == 2){
+      getSiteCheckFiles()
+    }
+    if(type == 3){
+      getCompanyFiles()
+    }
+    if(type == 5){
+      console.log(res,'res')
+      getSafetyFiles()
+    }
+  }else{
+    ElMessage({
+      type: 'warning',
+      message: '文件上传失败'
+    })
+  }
+}
+
+const handleRemove = async (file, uploadFiles,type) => {
+  ElMessageBox.confirm(
+      '确定删除该附件?',
+      '提示',
+      {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning',
+      })
+      .then( async() => {
+        const res = await delFile(file.id)
+        if(res.code == 200){
+          ElMessage({
+            type: 'success',
+            message: '文件已删除'
+          })
+          if(type == 1){
+            await getBeforeFiles()
+          }
+          if(type == 2){
+            await getSiteCheckFiles()
+          }
+          if(type == 3){
+            await getCompanyFiles()
+          }
+          if(type == 5){
+            await getSafetyFiles()
+          }
+        }else{
+          ElMessage({
+            type: 'warning',
+            message: res.message
+          })
+        }
+      })
+      .catch(()=>{
+        if(type == 1){
+          getBeforeFiles()
+        }
+        if(type == 2){
+          getSiteCheckFiles()
+        }
+        if(type == 3){
+          getCompanyFiles()
+        }
+        if(type == 5){
+          getSafetyFiles()
+        }
+      })
+}
+
 defineExpose({
   riskOpen
 });

--
Gitblit v1.9.2