祖安之光
2025-11-13 2405410a2df3178ebacdc241522fa9aaf28f4a34
src/views/work/assetMng/toolsMonitorMeasure/annualVerificationPlan/components/editDialog.vue
@@ -9,7 +9,7 @@
        :close-on-click-modal="false"
    >
      <el-form :model="state.form" size="default" ref="superRef" :rules="state.formRules" label-width="150px" >
        <el-form-item v-if="state.isAdmin && state.title !== '上传'" label="企业:" prop="companyId">
        <el-form-item v-if="state.isAdmin && state.title !== '上传'" label="单位:" prop="companyId">
          <el-select v-model="state.form.companyId" placeholder="请选择" :disabled="state.title =='查看'" clearable @change="getDeptList">
            <el-option
                v-for="item in state.companyList"
@@ -150,7 +150,7 @@
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="使用人" prop="useUser" align="center">
          <el-table-column label="使用单位" prop="useUser" align="center">
            <template #default="scope">
              <el-input
                  v-model.trim="scope.row.useUser"
@@ -163,29 +163,50 @@
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="证书编号" prop="certificateName" align="center">
            <template #default="scope">
              <el-input
                  v-model.trim="scope.row.certificateName"
                  style="width: 100%;"
                  clearable
                  :readonly="state.title == '查看'"
              >
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="证书上传" prop="certificateName" align="center">
            <template #default="scope">
              <el-upload accept=".pdf,image/*" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile,scope.$index)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList[scope.$index]" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles, scope.$index)" >
                <el-button type="primary">点击上传</el-button>
                <template #tip>
                  <div class="el-upload__tip">支持上传pdf、图片格式,尺寸小于5M,最多可上传1份</div>
                </template>
              </el-upload>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="70" v-if="state.title == '新增'||state.title == '编辑' ">
            <template #default="scope">
              <el-button link type="danger" @click="handleDelete(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-form-item label="证书名称:" prop="certificateName" v-if="state.title == '上传'">
          <el-input
              v-model.trim="state.form.certificateName"
              style="width: 100%;"
              clearable
              :readonly="state.title == '查看'"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="检定证书:" prop="certificate" v-if="state.title == '上传'">
          <el-upload accept=".pdf,image/*" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" >
            <el-button type="primary">点击上传</el-button>
            <template #tip>
              <div class="el-upload__tip">支持上传pdf、图片格式,尺寸小于5M,最多可上传1份</div>
            </template>
          </el-upload>
        </el-form-item>
<!--        <el-form-item label="证书编号:" prop="certificateName" v-if="state.title == '上传'">-->
<!--          <el-input-->
<!--              v-model.trim="state.form.certificateName"-->
<!--              style="width: 100%;"-->
<!--              clearable-->
<!--              :readonly="state.title == '查看'"-->
<!--          >-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="检定证书:" prop="certificate" v-if="state.title == '上传'">-->
<!--          <el-upload accept=".pdf,image/*" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" >-->
<!--            <el-button type="primary">点击上传</el-button>-->
<!--            <template #tip>-->
<!--              <div class="el-upload__tip">支持上传pdf、图片格式,尺寸小于5M,最多可上传1份</div>-->
<!--            </template>-->
<!--          </el-upload>-->
<!--        </el-form-item>-->
        <el-row v-if="state.title !== '上传'">
          <el-col :span="12">
            <el-form-item label="编制:" prop="establishmentId">
@@ -261,6 +282,7 @@
import {listUser} from "@/api/system/user";
import {getAnnualVerificationPlanDetail, saveAnnualVerificationPlan} from "@/api/assetManage/assetMng";
import {delPic} from "@/api/onlineEducation/banner";
import {getEmployeeRecords} from "@/api/onlineEducation/user";
const emit = defineEmits(["getList"]);
const dialogVisible = ref(false)
@@ -293,9 +315,7 @@
    establishmentTime: '',
    processId: null,
    processName: '',
    processTime: '',
    certificateName: '',
    certificate: '',
    processTime: ''
  },
  oldDeviceList: [],
  formRules:{
@@ -307,9 +327,7 @@
    establishmentTime: [{ required: true, message: '请选择编制时间', trigger: 'blur' }],
    processId: [{ required: true, message: '请选择审核人', trigger: 'blur' }],
    processTime: [{ required: true, message: '请选择审核时间', trigger: 'blur' }],
    approvalId: [{ required: true, message: '请选择批准人', trigger: 'blur' }],
    certificateName: [{ required: true, message: '请填写证书名称', trigger: 'blur' }],
    certificate: [{ required: true, validator: checkFileList, trigger: 'blur' }]
    approvalId: [{ required: true, message: '请选择批准人', trigger: 'blur' }]
  },
  isAdmin: false,
  companyList: [],
@@ -335,6 +353,7 @@
  await getUserList(companyId)
  state.title = type === 'add' ? '新增' : type ==='edit' ? '编辑' : type ==='upload' ? '上传' : '查看'
  state.form.companyId = companyId
  state.form.year = new Date().getFullYear().toString()
  if(state.title == '编辑'||state.title == '查看' ||state.title == '上传'){
    await getInfo(value.id)
  }
@@ -353,13 +372,17 @@
    actCalibrationTime: '',
    calibrationUser: '',
    status: '',
    useUser: ''
    useUser: '',
    certificateName: '',
    certificate: ''
  }
  state.form.annualVerificationDevices.push(obj);
}
const handleDelete = (i) =>{
  console.log(i,state.fileList,'list')
  state.form.annualVerificationDevices = state.form.annualVerificationDevices.filter((item,index) => index != i)
  state.fileList = state.fileList.filter((item,index) => index != i)
}
const onSubmit = async () => {
@@ -414,16 +437,27 @@
        actCalibrationTime: item.actCalibrationTime,
        calibrationUser: item.calibrationUser,
        useUser: item.useUser,
        status: item.status
        status: item.status,
        certificateName: item.certificateName,
        certificate: item.certificate
      }
    })
    state.oldDeviceList = state.form.annualVerificationDevices
    if(state.form.certificate) {
      const obj = {
        url: state.form.certificate,
        name: state.form.certificateName
    // if(state.form.certificate) {
    //   const obj = {
    //     url: state.form.certificate,
    //     name: state.form.certificateName
    //   }
    //   state.fileList = [obj]
    // }
    for(let i in state.form.annualVerificationDevices){
      if(state.form.annualVerificationDevices[i].certificate && state.form.annualVerificationDevices[i].certificate !== ''){
          const obj = {
            url: state.form.annualVerificationDevices[i].certificate,
            name: state.form.annualVerificationDevices[i].certificateName
          }
          state.fileList[i] = [obj]
      }
      state.fileList = [obj]
    }
  }else{
    ElMessage.warning(res.message)
@@ -437,26 +471,19 @@
}
const getUserList = async (companyId)=> {
  const res = await listUser({pageIndex: 1,pageSize: 999,companyId: companyId})
  const res = await getEmployeeRecords({companyId: companyId})
  if(res.code == 200){
    state.userList = res.data.list?res.data.list.map(item=>{
      const user = item.id
      const {id, ...data} = item
      return {
        ...data,
        userId: user
      }
    }):[]
    state.userList = res.data.list?res.data.list:[]
  }else{
    ElMessage.warning(res.message)
  }
}
const handleAvatarSuccess = (res, uploadFile) => {
const handleAvatarSuccess = (res, uploadFile, index) => {
  if(res.code == 200){
    state.form.certificate = res.data.path
    state.form.annualVerificationDevices[index].certificate = res.data.path
  }else{
    state.fileList = []
    state.fileList[index] = []
    ElMessage({
      type: 'warning',
      message: '文件上传失败'
@@ -479,15 +506,16 @@
    return false
  }
};
const handleRemove = async (file, uploadFiles) => {
  let path = state.form.filePath;
const handleRemove = async (file, uploadFiles, index) => {
  let path = state.form.annualVerificationDevices[index].certificate
  await delPic({path: path}).then(res => {
    if(res.code == 200){
      // ElMessage({
      //   type: 'success',
      //   message: '文件已删除'
      // })
      state.form.certificate = ''
      state.form.annualVerificationDevices[index].certificate = ''
      state.form.annualVerificationDevices[index].certificateName = ''
    }else{
      ElMessage({
        type: 'warning',
@@ -495,7 +523,8 @@
      })
    }
  }).catch(() => {
    state.form.certificate = ''
    state.form.annualVerificationDevices[index].certificate = ''
    state.form.annualVerificationDevices[index].certificateName = ''
  });
}
@@ -512,9 +541,7 @@
    establishmentTime: '',
    processId: null,
    processName: '',
    processTime: '',
    certificateName: '',
    certificate: '',
    processTime: ''
  }
  state.fileList = []
  superRef.value.clearValidate();