zhuo
2025-03-16 8fd9e43b8ae22e64c62afee56c24df682f8c47c9
src/views/CNAS/resourceDemand/facilitiesEnvironment/component/facilities-environmental-conditions/lightning-protection-detection.vue
@@ -120,11 +120,21 @@
<script>
import {
  getLightningProtectionDetection,
  addLightningProtectionDetection,
  deleteLightningProtectionDetection,
  exportOfLightningProtectionDetection
} from '@/api/cnas/resourceDemand/facilitiesEnvironment/facilitiesAndEnvironment'
import axios from 'axios';
import {deleteCNASFile} from "@/api/cnas/personal/personalList";
export default {
  data() {
    return {
      search: {
        size: 20,
        size: 10,
        current: 1,
        total: 0
      },
@@ -152,42 +162,20 @@
  methods: {
    // 导出
    downLoadPost() {
      this.$axios.get(this.$api.facilitiesAndEnvironment.exportOfLightningProtectionDetection,{responseType: "blob"}).then(res => {
      exportOfLightningProtectionDetection().then(res => {
        this.outLoading = false
        const blob = new Blob([res],{ type: 'application/msword' });
        //将Blob 对象转换成字符串
        let reader = new FileReader();
        reader.readAsText(blob, 'utf-8');
        reader.onload = () => {
          try {
            let result = JSON.parse(reader.result);
            if (result.message) {
              this.$message.error(result.message);
            } else {
              const url = URL.createObjectURL(blob);
              const link = document.createElement('a');
              link.href = url;
              link.download = '防雷检测导出' + '.xlsx';
              link.click();
              this.$message.success('导出成功')
            }
          } catch (err) {
            console.log(err);
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = '防雷检测导出' + '.xlsx';
            link.click();
            this.$message.success('导出成功')
          }
        }
        this.$download.saveAs(blob,'防雷检测导出.xlsx')
      })
    },
    initData() {
      this.$axios.get(this.$api.facilitiesAndEnvironment.getLightningProtectionDetection + '?size=' + this.search.size + '&current=' + this.search.current).then(res => {
        if (res.code === 201) return;
        this.tableData = res.data.records;
        this.search.total = res.data.total;
      getLightningProtectionDetection({...this.search}).then(res => {
        if (res.code === 200){
          this.tableData = res.data.records;
          this.search.total = res.data.total;
        }
      });
    },
    handleSizeChange(val) {
@@ -223,13 +211,11 @@
          if (this.form.fileData.length > 0) {
            params.append("file", this.form.fileData[0].file)
          }
          this.$axios.post(this.$api.facilitiesAndEnvironment.addLightningProtectionDetection, params, {
            headers: {'Content-Type': 'multipart/form-data;'},
            noQs: true
          }).then(res => {
            if (res.code === 201) return;
            this.dialogVisible = false
            this.initData()
          addLightningProtectionDetection(params).then(res => {
            if (res.code === 200){
              this.dialogVisible = false
              this.initData()
            }
          });
        }
      });
@@ -248,31 +234,27 @@
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete(this.$api.facilitiesAndEnvironment.deleteLightningProtectionDetection + '?lightningProtectionId=' + row.lightningProtectionId).then(res => {
        deleteLightningProtectionDetection({lightningProtectionId:row.lightningProtectionId}).then(res => {
          this.$message.success('删除成功!')
          this.initData()
        })
      })
    },
    handleRemove(file) {
      this.$axios.delete(this.$api.personnel.deleteCNASFile + "?fileName=" + file.name).then(res => {
        if (res.code === 201) return;
      deleteCNASFile({fileName: file.name}).then(res => {
        this.$message.success('删除成功!')
        let index = this.form.fileList.indexOf(fileName)
        if (index != -1) {
          this.successFileList.splice(index, 1)
        let index = this.form.fileList.indexOf(file.name)
        if (index !== -1) {
          this.form.fileList.splice(index, 1)
        }
      })
    },
    download(row) {
      let url = '';
      // fileDownload.downloadIamge(url, row.fileName)
      url = this.javaApi + 'img/' + row.systemFileName
      const link = document.createElement('a');
      link.href = url;
      link.download = row.fileName;
      link.click();
      if (!row.systemFileName) {
        this.$message.warning('暂无文件')
        return
      }
      this.$download.saveAs(row.systemFileName, row.fileName)
    }
  }
}