吴羡
10 小时以前 c6e96cdb8b1cfb51e9a45bf86c38d1353e983127
src/views/CNAS/resourceDemand/device/component/files.vue
@@ -15,12 +15,16 @@
      <el-row :gutter="20">
        <el-col :span="6">
          <!-- 加时间戳避免浏览器缓存问题 -->
          <el-image :src="`${javaApi}/img/${Mdata.imageUpload}`" fit="fill" :key="'personalPicture' + timeStamp"
          <el-image v-if="Mdata.imageUpload" :src="`${javaApi}/img/${Mdata.imageUpload}`" fit="fill" :key="'personalPicture' + timeStamp"
            style="width: 200px;height: 300px;border: 1px solid #000;border-radius: 10px;margin-left: 30px;margin-top: 20px;">
            <template #error><div  class="image-slot">
              <lims-icon name="el-icon-picture-outline" style="font-size: 40px;"></lims-icon>
            </div></template>
          </el-image>
          <div v-else class="image-slot"
            style="width: 198px;height: 298px;border: 1px solid #000;border-radius: 10px;margin-left: 30px;margin-top: 20px;display: flex;align-items: center;justify-content: center;">
            <lims-icon name="el-icon-picture-outline" style="font-size: 40px;"></lims-icon>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="form-item">
@@ -52,10 +56,6 @@
          </div>
          <div class="form-item">
            <label>出厂日期</label>
            <p>{{ formaterDateTime(Mdata.acquisitionDate) }}</p>
          </div>
          <div class="form-item">
            <label>校准有效期</label>
            <p>{{ formaterDateTime(Mdata.activationDate) }}</p>
          </div>
@@ -65,19 +65,11 @@
          </div>
          <div class="form-item">
            <label>报废时间</label>
            <p>{{ handleData() }}</p>
          </div>
          <div class="form-item">
            <label>准确度量值</label>
            <el-tooltip class="item" :content="Mdata.technicalIndicators">
              <span class="text-ellipsis">{{ Mdata.technicalIndicators }}</span>
            </el-tooltip>
            <!-- <p>{{ Mdata.technicalIndicators }}</p> -->
          </div>
          <div class="form-item">
            <label>维修记录</label>
            <p>{{ handleData() }}</p>
          </div>
          <div class="form-item">
            <label>被授权人</label>
@@ -136,15 +128,11 @@
          </div>
          <div class="form-item">
            <label>采购费用(元)</label>
            <p>{{ Mdata.unitPrice }}</p>
            <p>{{ formatPurchasePrice(Mdata.unitPrice) }}</p>
          </div>
          <div class="form-item">
            <label>设备负责人</label>
            <p>{{ Mdata.equipmentManagerName }}</p>
          </div>
          <div class="form-item">
            <label>验收记录</label>
            <p>{{ handleData() }}</p>
          </div>
          <div class="form-item">
            <label>核准证书</label>
@@ -166,7 +154,7 @@
        <el-table-column prop="quantity" label="份数" min-width="80" />
        <el-table-column prop="pageCount" label="页码" min-width="80" />
        <el-table-column prop="provider" label="提供者" min-width="150" />
        <el-table-column prop="provideDate" label="归档日期" min-width="170" />
        <el-table-column prop="provideDate" label="归档日期" min-width="170" :formatter="formatDateCell" />
        <el-table-column prop="comments" label="备注" min-width="150" />
        <el-table-column fixed="right" label="操作" min-width="180" align="center">
          <template #default="scope">
@@ -185,7 +173,7 @@
      <el-row>
        <el-col :span="7" style="padding-right: 20px;">
          <!-- 图片 -->
          <el-image class="img" style="width:100%;height: 320px;"
          <el-image v-if="editData.imageUpload" class="img" style="width:100%;height: 320px;"
            :src="javaApi + '/img/' + editData.imageUpload">
            <template #error><div  class="image-error" style="width: calc(100% - 2px);
            height: 318px;
@@ -197,11 +185,15 @@
              <lims-icon name="el-icon-picture-outline" style="font-size:60px;color:var(--lims-text-2);"></lims-icon>
            </div></template>
          </el-image>
          <div v-else class="image-error"
            style="width: calc(100% - 2px);height: 320px;border-radius: 16px;display: flex;align-items: center;justify-content: center;border: 1px solid var(--lims-divider);">
            <lims-icon name="el-icon-picture-outline" style="font-size:60px;color:var(--lims-text-2);"></lims-icon>
          </div>
          <!-- 图片上传 -->
          <div style="margin-top: 12px;text-align: center;">
            <div v-show="editData.imageName" class="picName">{{ editData.imageName }}</div>
            <el-upload :action="action" :on-success="handleSuccessUpImg2" :show-file-list="false"
              accept='image/jpg,image/jpeg,image/png' :headers="uploadHeader" :on-change="beforeUpload"
              accept='image/jpg,image/jpeg,image/png' :headers="uploadHeader" :before-upload="beforeUpload"
              :on-error="onError" ref='upload' class="avatar-uploader">
              <img v-if="editData.imageUpload" :src="javaApi + '/img/' + editData.imageUpload" class="avatar">
              <lims-icon name="el-icon-plus" v-else class="avatar-uploader-icon"></lims-icon>
@@ -276,7 +268,7 @@
              placeholder="请选择" size="small" style="width:100%;" :collapse-tags="true" separator="," filterable
              clearable></el-cascader>
          </el-form-item>
          <el-form-item label="设备类型:">
          <el-form-item label="设备/计量器具:">
            <el-select v-model="editData.largeCategory" placeholder="请选择" size="small" style="width:100%">
              <el-option v-for="item in equipmentList" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
@@ -319,17 +311,17 @@
        <div class="cycle-row">
          <span class="cycle-title">校准信息</span>
          <el-form-item label="最近校准日期:" class="cycle-item">
            <el-date-picker style="width:100%" v-model="editData.lastCalibrationDate" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD HH:mm:ss" type="date" size="small" placeholder="选择日期">
            <el-date-picker style="width:100%" v-model="editData.lastCalibrationDate" @change="calcNextDate(editData)"
              format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss" type="date" size="small" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="下次校准日期:" class="cycle-item">
            <el-date-picker style="width:100%" v-model="editData.nextCalibrationDate" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD HH:mm:ss" type="date" size="small" placeholder="选择日期">
            <el-date-picker :disabled="true" style="width:100%" v-model="editData.nextCalibrationDate"
              format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss" type="date" size="small" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="校准周期(月):" prop="calibrationDate" class="cycle-item">
            <el-input v-model="editData.calibrationDate" size="small"></el-input>
            <el-input v-model="editData.calibrationDate" size="small" @change="calcNextDate(editData)"></el-input>
          </el-form-item>
        </div>
        <div class="cycle-row">
@@ -504,6 +496,8 @@
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/business/inspectionTask";
import { selectQualifiedSupplierManagementPage } from '@/api/cnas/externalService/supplierManage/supplierManage'
import { formatListDate } from './dateFormat'
import { saveBlobOrShowError } from '@/utils/saveBlob'
export default {
  props: {
    clickNodeVal: {
@@ -544,7 +538,6 @@
      // },
      fileList: [], // 添加附件上传文件列表
      timeStamp: '', // 给图片添加key,在每次加载页面的时候新建时间戳
      equipmentManager: [],
      formLabelWidth: '100px',
      dialogVisible1: false,
      recordNumber: '',
@@ -555,7 +548,7 @@
      num: 1,
      //添加附件数据收集
      addFile: {
        documentType: '', // 维护类型
        documentType: 0, // 维护类型
        provideDate: null, // 归档日期
        name: '', // 档案名称
        number: '', // 库号/资产编号
@@ -577,7 +570,11 @@
      responsiblePersonList: [],
      inspectorList: [],
      options: [],
      equipmentList: [],
      // 设备类型:与左侧树“设备/计量器具”分类保持一致
      equipmentList: [
        { label: '设备', value: '设备' },
        { label: '计量器具', value: '计量器具' }
      ],
      deviceStatusList: [],
      props: { multiple: true, emitPath: false, value: 'id', label: 'name' },
      // 收集设备档案数据
@@ -612,6 +609,9 @@
    this.obtainQualifiedSupplierList()
  },
  methods: {
    formatDateCell(row, column, cellValue) {
      return formatListDate(cellValue)
    },
    // 拉取合格供应商列表(校准服务机构下拉选项)
    obtainQualifiedSupplierList() {
      selectQualifiedSupplierManagementPage({ current: 1, size: 999 }).then(res => {
@@ -662,12 +662,14 @@
    },
    //附件和相关文档事件
    handleAttachmentClick(row) {
      console.log(row)
      if (row.fileName) {
        this.$download.saveAs(row.fileName)
      } else {
      if (!row.systemFileName) {
        this.$message.warning('未上传文件!')
        return
      }
      // 图片存 /img/,其他文档存 /word/
      const isImage = /\.(jpg|jpeg|png|gif|bmp|webp)$/i.test(row.systemFileName)
      const url = this.javaApi + (isImage ? '/img/' : '/word/') + row.systemFileName
      this.$download.saveAs(url, row.fileName || row.systemFileName)
    },
    handleViewClick(row) {
      this.isAddFileUpdate = true
@@ -701,11 +703,23 @@
      })
    },
    saveRecord() {
      if (!this.addFile.name) {
        this.$message.warning('请输入档案名称')
        return
      }
      if (this.addFile.documentType !== 0 && this.addFile.documentType !== '0' &&
        this.addFile.documentType !== 1 && this.addFile.documentType !== '1') {
        this.$message.warning('请选择维护类型')
        return
      }
      //转换数据
      this.addFile.deviceId = this.clickNodeVal.value
      // 新上传时 systemFileName 是 {name: 原始文件名, url: 存储文件名};编辑旧记录时已是字符串
      let obj = this.addFile.systemFileName
      this.addFile.systemFileName = obj.name
      this.addFile.fileName = obj.url
      if (obj && typeof obj === 'object') {
        this.addFile.systemFileName = obj.url
        this.addFile.fileName = obj.name
      }
      // 更新
      if (this.isAddFileUpdate) {
@@ -737,11 +751,17 @@
      }
    },
    handleRemove(file, fileList) {
      this.deleteFile(this.addFile.systemFileName)
      const obj = this.addFile.systemFileName
      const fileName = obj && typeof obj === 'object' ? obj.url : obj
      if (fileName) this.deleteFile(fileName)
      this.addFile.systemFileName = ''
      this.addFile.fileName = ''
    },
    deleteFile(fileName) {
      deleteCNASFile({ fileName }).then(res => {
        this.$message.success('删除成功!')
        if (res.code == 200) {
          this.$message.success('删除成功!')
        }
      })
    },
    handleExceed(files, fileList) {
@@ -784,7 +804,9 @@
        // 将分类列表的信息存起来
        if (res.code == 200) {
          this.Mdata = res.data;
          this.Mdata.insProductIds = this.Mdata.insProductIds.split(',')
          this.Mdata.insProductIds = this.Mdata.insProductIds
              ? String(this.Mdata.insProductIds).split(',')
              : []
          this.Mdata.authorizedPerson = this.normalizeAuthorizedPerson(this.Mdata.authorizedPerson)
        }
      });
@@ -802,6 +824,11 @@
    //打开修订档案弹框
    openEditForm() {
      this.editData = JSON.parse(JSON.stringify(this.Mdata))
      // 设备类型为空时,默认取左侧树当前所在分类
      const treeCategory = this.clickNodeVal && this.clickNodeVal.parent ? this.clickNodeVal.parent.label : ''
      if (!this.editData.largeCategory && (treeCategory === '设备' || treeCategory === '计量器具')) {
        this.editData.largeCategory = treeCategory
      }
      this.$nextTick(() => {
        this.dialogVisible = true
      })
@@ -832,55 +859,39 @@
    },
    //修订档案
    submitForm() {
      let flag = true
      this.$refs['rules1'].validate((valid) => {
        if (!valid) {
          flag = false;
          return false;
      // validate() 返回 Promise,统一等四个表单全部校验完再判断
      const formRefs = ['rules1', 'rules2', 'ruleForm', 'cycleForm']
      Promise.all(formRefs.map(ref => this.$refs[ref].validate().catch(() => false))).then(results => {
        if (results.some(valid => !valid)) {
          return
        }
      });
      this.$refs['rules2'].validate((valid) => {
        if (!valid) {
          flag = false;
          return false;
        }
      });
      this.$refs['ruleForm'].validate((valid) => {
        if (!valid) {
          flag = false;
          return false;
        }
      });
      this.$refs['cycleForm'].validate((valid) => {
        if (!valid) {
          flag = false;
          return false;
        }
      });
      if (!flag) {
        return;
      }
      delete this.editData.createTime
      delete this.editData.updateTime
      delete this.editData.createUser
      delete this.editData.updateUser
      delete this.editData.orderBy
      const formData = this.HaveJson(this.editData)
      formData.userAllow = this.equipmentManager.toString();
      formData.insProductIds = Array.isArray(formData.insProductIds) ? formData.insProductIds.join(',') : '';
      formData.authorizedPerson = Array.isArray(formData.authorizedPerson) && formData.authorizedPerson.length
        ? JSON.stringify(formData.authorizedPerson)
        : ''
      this.upLoad = true;
      upDeviceParameter(formData).then(res => {
        this.$message.success('修改成功')
        this.upLoad = false
        this.getList(this.clickNodeVal.value)
        this.dialogVisible = false
      }).catch(e => {
        this.$message.error('修改失败')
        this.dialogVisible = false
        this.upLoad = false
        delete this.editData.createTime
        delete this.editData.updateTime
        delete this.editData.createUser
        delete this.editData.updateUser
        delete this.editData.orderBy
        const formData = this.HaveJson(this.editData)
        formData.insProductIds = Array.isArray(formData.insProductIds) ? formData.insProductIds.join(',') : '';
        formData.authorizedPerson = Array.isArray(formData.authorizedPerson) && formData.authorizedPerson.length
          ? JSON.stringify(formData.authorizedPerson)
          : ''
        this.upLoad = true;
        upDeviceParameter(formData).then(res => {
          this.upLoad = false
          if (res.code == 200) {
            this.$message.success('修改成功')
            this.getList(this.clickNodeVal.value)
            // 类型可能变更,刷新左侧树让设备归到新的分类下
            this.$emit('refresh-tree')
            this.dialogVisible = false
          } else {
            this.$message.error(res.message || res.msg || '修改失败')
          }
        }).catch(e => {
          // 失败保留弹窗,避免已编辑内容丢失
          this.$message.error('修改失败')
          this.upLoad = false
        })
      })
    },
    // 导出
@@ -888,9 +899,18 @@
      this.outLoading = true
      exportDeviceFile({ deviceId: this.clickNodeVal.value }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/octet-stream' });
        this.$download.saveAs(blob, '设备档案卡.doc')
        saveBlobOrShowError(res, '设备档案卡.doc', 'application/msword')
      }).catch(() => {
        this.outLoading = false
      })
    },
    // 修订弹窗按万元录入,档案详情按元展示
    formatPurchasePrice(val) {
      if (val === null || val === undefined || val === '') {
        return '-'
      }
      const num = Number(val)
      return isNaN(num) ? val : num * 10000
    },
    handleSuccessUpImg2(response) {
      if (response.code == 200) {
@@ -960,10 +980,6 @@
            a.value = parseInt(a.value)
          }
        })
      });
      // 设备分类
      this.getDicts("device_type").then((response) => {
        this.equipmentList = this.dictToValue(response.data);
      });
    },
  },