zhouwx
2025-01-06 2aac44c550cdb242225a2a18f7238fb41c618779
src/views/safetyReview/projectManage/components/employNoticeRecord.vue
@@ -64,12 +64,31 @@
        </el-table-column>
      </el-table>
    </el-form>
    <el-upload
        style="margin-top: 25px;width: 250px"
        :disabled="projectType === 'view' || isEnd"
        accept=".pdf"
        :action="state.uploadUrl"
        :data="{moduleType: 12,projectId: props.projectId}"
        :headers="state.header"
        method="post"
        :limit="state.imgLimit"
        :before-upload="beforeUpload"
        :on-success="handleAvatarSuccess"
        v-model:file-list="state.fileList"
        :on-preview="handlePreview"
        :on-remove="handleRemove">
      <el-button type="primary">上传从业告知书pdf</el-button>
      <template #tip>
        <div class="el-upload__tip">只能上传pdf类型,最多上传1份</div>
      </template>
    </el-upload>
  </div>
</template>
<script setup>
import {defineEmits, defineProps, onMounted, reactive, ref, watchEffect} from "vue"
import {ElMessage} from "element-plus"
import {ElMessage, ElMessageBox} from "element-plus"
import {Search} from '@element-plus/icons-vue'
import {addWorkRecord, editWorkRecord, getWorkDetail} from "@/api/projectManage/employNoticeRcd"
import {getWorks, editWorks} from "@/api/projectManage/evaPlan"
@@ -77,6 +96,10 @@
const props = defineProps(['projectId'])
const emit = defineEmits(["getNextStatus"])
import { useRoute } from 'vue-router'
import {getToken} from "@/utils/auth";
import {getFiles} from "@/api/projectManage/siteCheckRcd";
import {delAccessoryFile} from "@/api/projectManage/project";
import axios from "axios";
const route = useRoute()
const state = reactive({
  formData: {
@@ -92,9 +115,16 @@
  rules: {
    timeRange: [{required: true, message: '请选择技术服务期限', trigger: 'blur'}],
    investigationPlanDate: [{required: true, message: '请选择计划现场勘验时间', trigger: 'blur'}]
  }
  },
  imgLimit: 1,
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/manage/accessory-file/uploadFile',
  header: {
    Authorization: getToken()
  },
  fileList: []
})
const isEnd = ref('')
const isAmin = ref(false)
const formRef = ref()
onMounted(() => {
@@ -104,7 +134,9 @@
  }
  if(props.projectId){
    getWorksList(props.projectId)
    getProcessFiles(props.projectId);
  }
  isEnd.value = Cookies.get('end')
});
@@ -113,12 +145,19 @@
  state.formData.projectId = val
  state.projectId = val
  projectType.value = route.query.type;
  isEnd.value = Cookies.get('end')
  // await getWorksList(val)
  if(type === 'detail' || type === 'edit' ){
    const res = await getWorkDetail({projectId: val})
    if(res.code == 200){
      state.formData = JSON.parse(JSON.stringify(res.data))
      state.formData.timeRange = [state.formData.serviceStartDate,state.formData.serviceEndDate]
      // state.fileList = res.data.accessoryFiles.map(item => {
      //   return {
      //     ...item,
      //     name: item.originName,
      //   }
      // })
    }else {
      ElMessage.warning(res.message)
    }
@@ -189,7 +228,90 @@
  }
  await getWorksList(props.projectId)
}
const beforeUpload = (file) => {
  let fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
  if (fileType === 'pdf') {
  } else {
    ElMessage.error("文件类型必须为pdf格式")
    return false
  }
}
const handleAvatarSuccess = (res) => {
  if(res.code === 200){
    getProcessFiles()
    ElMessage({
      type: 'success',
      message: '文件上传成功'
    })
  }else {
    state.fileList.splice(state.fileList.indexOf(uploadFile),1)
    ElMessage({
      type: 'warning',
      message: res.message
    })
  }
}
const handleRemove = async (file, uploadFiles) => {
  if (file && file.status === 'success') {
    ElMessageBox.confirm(
        '确定删除该附件?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(async () => {
          let accessoryFileId = "";
          if (file.id) {
            accessoryFileId = file.id
          } else {
            accessoryFileId = file.response.data.id
          }
          const res = await delAccessoryFile(accessoryFileId)
          if (res.code == 200) {
            ElMessage({
              type: 'success',
              message: '文件已删除'
            })
            await getProcessFiles()
          } else {
            ElMessage({
              type: 'warning',
              message: res.message
            })
          }
        })
        .catch(() => {
          getProcessFiles()
        })
  }
}
const getProcessFiles = async (id)=>{
  const res = await getFiles({projectId: id ? id : props.projectId ,moduleType: 12})
  if(res.code == 200){
    if(res.data && res.data.length>0){
      state.fileList = 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.fileList = []
    }
  }else {
    ElMessage.warning(res.message)
  }
}
const handlePreview = (file) => {
  const url = file.url
  window.open(url)
}
defineExpose({
  riskOpen
});