吴羡
昨天 e3686634452289d43e750a44f30f72b0e7754866
src/views/CNAS/systemManagement/documentControl/components/ControlledFileApplication.vue
@@ -14,8 +14,9 @@
        </div>
      </div>
      <div style="line-height: 30px;">
        <el-button size="small" @click="$refs.importDialog.open()">导 入</el-button>
        <el-button size="small" type="primary" :icon="$icon('el-icon-plus')"
                   @click="addDialogVisible = true, addInfo = {}, file = null">文件受控申请</el-button>
                   @click="addDialogVisible = true, addInfo = {}, file = null, fileList = []">文件受控申请</el-button>
      </div>
    </div>
    <div class="table">
@@ -71,7 +72,9 @@
          <div class="search_thing">
            <div class="search_label">上传附件:</div>
            <div class="search_input"><el-upload style="margin: 8px 0 0px 50px;" action="#" :auto-upload="false"
                :multiple="false" accept='.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.wps,.et,.dps,.txt,.jpg,.jpeg,.png' :on-change="handleChangeUpload" v-if="addDialogVisible">
                :multiple="false" accept='.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.wps,.et,.dps,.txt,.jpg,.jpeg,.png'
                :file-list="fileList" :on-change="handleChangeUpload" :on-remove="handleRemoveUpload"
                :before-remove="beforeRemoveUpload" :on-preview="handlePreviewUpload" v-if="addDialogVisible">
                <el-button size="small" type="primary">上传附件</el-button>
              </el-upload></div>
          </div>
@@ -90,15 +93,25 @@
        </el-col>
        <el-col :span="12" style="margin-bottom: 16px;">
          <div class="search_thing">
            <div class="search_label">提交日期:</div>
            <div class="search_label">发布日期:</div>
            <div class="search_input">
              <el-date-picker v-model="addInfo.submitDate" type="date" size="small" placeholder="选择日期"
              <el-date-picker v-model="addInfo.publishDate" type="date" size="small" placeholder="选择日期"
                format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%;">
              </el-date-picker>
            </div>
          </div>
        </el-col>
        <el-col :span="12" style="margin-bottom: 16px;">
          <div class="search_thing">
            <div class="search_label">实施日期:</div>
            <div class="search_input">
              <el-date-picker v-model="addInfo.implementDate" type="date" size="small" placeholder="选择日期"
                format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%;">
              </el-date-picker>
            </div>
          </div>
        </el-col>
        <el-col :span="24" style="margin-bottom: 16px;">
          <div class="search_thing">
            <div class="search_label">说明:</div>
            <div class="search_input"><el-input size="small" placeholder="请输入" clearable v-model="addInfo.instructions"
@@ -116,7 +129,7 @@
        style="height: 90vh;overflow-y: auto;" />
    </el-dialog>
    <el-dialog title="审核" v-model="checkDialogVisible" width="1000px" top="5vh">
      <UpPdfStamp ref="UpPdfStamp" v-if="checkDialogVisible" @uploadPDF="uploadPDF" :isUpFile="false"></UpPdfStamp>
      <UpPdfStamp ref="UpPdfStamp" v-if="checkDialogVisible" @uploadPDF="uploadPDF" @uploadPDFErr="handlePdfError" :isUpFile="false"></UpPdfStamp>
      <template #footer><span  class="dialog-footer">
        <el-button @click="handleCheckSub('不通过')" :loading="noCheckLoading">不通过</el-button>
        <el-button type="primary" @click="handleCheckSub('通过')" :loading="checkLoading">通 过</el-button>
@@ -133,6 +146,16 @@
        <el-button type="primary" @click="handleCheck0(currentInfo)">确 定</el-button>
      </span></template>
    </el-dialog>
    <import-dialog
      ref="importDialog"
      title="导入文件受控申请"
      :action="importAction"
      accept=".xls,.xlsx"
      template-url="/import-templates/文件受控申请导入模板.xlsx?v=1"
      template-name="文件受控申请导入模板.xlsx"
      :tips="['表头必须与模板完全一致,不能增删列或修改列名', '发布日期、实施日期格式:YYYY-MM-DD', '导入后状态为草稿,申请人为空,可在页面上编辑']"
      @success="refreshTable"
    />
  </div>
</template>
@@ -140,6 +163,7 @@
import UpPdfStamp from '@/components/UpPdfStamp/index.vue'
import filePreview from '@/components/Preview/filePreview.vue'
import limsTable from "@/components/Table/lims-table.vue";
import ImportDialog from '@/components/ImportDialog/index.vue'
import {
  selectUserCondition,
} from "@/api/business/inspectionTask.js";
@@ -159,10 +183,14 @@
  components: {
    filePreview,
    UpPdfStamp,
    limsTable
    limsTable,
    ImportDialog
  },
  computed: {
    ...mapGetters(["nickName"]),
    importAction() {
      return this.javaApi + '/manageDocumentControlled/importManageDocumentControlled'
    }
  },
  data() {
    return {
@@ -177,6 +205,7 @@
      personList: [],
      fileType: [],
      file: null,
      fileList: [],
      currentInfo: {},
      checkLoading: false,
      noCheckLoading: false,
@@ -204,13 +233,16 @@
            }
          },
        },
        { label: "文件名称", prop: "name", minWidth: "160" },
        { label: "文件版本", prop: "version", width: "100px" },
        { label: "发布日期", prop: "publishDate", width: "110px" },
        { label: "实施日期", prop: "implementDate", width: "110px" },
        {
          label: "申请人",
          prop: "createUserName",
        },
        { label: "申请时间", prop: "createTime" },
        { label: "说明", prop: "instructions" },
        { label: "提交日期", prop: "submitDate" },
        { label: "责任人", prop: "dutyUserName" },
        {
          label: "申请状态", prop: "state", dataType: "tag",
@@ -247,8 +279,11 @@
                this.handleCheck(row);
              },
              disabled: (row) => {
                if (row.state == '通过') {
                  return true
                }
                if(row.dutyUserName != null && row.dutyUserName != "") {
                  return !row.dutyUserName.includes(this.nickName) || row.state == '通过'
                  return !row.dutyUserName.includes(this.nickName)
                }else {
                  return false
                }
@@ -350,76 +385,79 @@
      });
    },
    // 提交
    buildFormData() {
      const fd = new FormData()
      // 文件信息中 raw 才是真的文件
      if (this.file) {
        fd.append("file", this.file.raw)
      }
      const fields = ['id', 'documentCode', 'dutyUser', 'type', 'name', 'version', 'writer',
        'publishDate', 'implementDate', 'instructions']
      fields.forEach((key) => {
        const value = this.addInfo[key]
        // 空日期/空下拉不传,避免后端日期或数字字段解析失败
        if (value !== undefined && value !== null && value !== '') {
          fd.append(key, value)
        }
      })
      return fd
    },
    handleAdd() {
      if (!this.addInfo.documentCode) return this.$message({ type: 'error', message: "请输入编号" })
      if (!this.addInfo.id) {
        // 新增
        let fd = new FormData();
        //文件信息中raw才是真的文件
        if (this.file) {
          fd.append("file", this.file.raw);
      const isEdit = !!this.addInfo.id
      const request = isEdit ? doManageDocumentControlled : addManageDocumentControlled
      this.addLoading = true
      request(this.buildFormData()).then(res => {
        this.addLoading = false
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: isEdit ? '修改成功' : '添加成功'
          })
          this.refreshTable()
          this.addDialogVisible = false
        } else {
          this.$message({
            type: 'error',
            message: isEdit ? '修改失败' : '添加失败'
          })
        }
        for (let m in this.addInfo) {
          fd.append(m, this.addInfo[m])
        }
        this.addLoading = true
        addManageDocumentControlled(fd).then(res => {
          this.addLoading = false
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '添加成功'
            })
            this.refreshTable()
            this.addDialogVisible = false
          } else {
            this.$message({
              type: 'error',
              message: '添加失败'
            })
          }
        })
      } else {
        // 修改
        let { id, documentCode, dutyUser, type, name, version, writer, submitDate, instructions } = this.addInfo
        let fd = new FormData();
        //文件信息中raw才是真的文件
        if (this.file) {
          fd.append("file", this.file.raw);
        }
        fd.append("id", id);
        fd.append("documentCode", documentCode);
        fd.append("dutyUser", dutyUser);
        fd.append("type", type);
        fd.append("name", name);
        fd.append("version", version);
        fd.append("writer", writer);
        fd.append("submitDate", submitDate);
        fd.append("instructions", instructions);
        this.addLoading = true
        doManageDocumentControlled(fd).then(res => {
          this.addLoading = false
          if (res.code == 200) {
            this.refreshTable()
            this.addDialogVisible = false
          } else {
            this.$message({
              type: 'error',
              message: '添加失败'
            })
          }
        })
      }
      }).catch(() => {
        this.addLoading = false
      })
    },
    handleChangeUpload(file, fileLists) {
      this.file = file
      this.addInfo['name'] = file.name
    },
    // 移除新选的附件后不再上传;原有附件不允许在这里删除,只能选择新附件替换
    handleRemoveUpload() {
      this.file = null
    },
    beforeRemoveUpload(file) {
      if (file && !file.raw) {
        this.$message.warning('选择新附件保存后会自动替换原附件')
        return false
      }
      return true
    },
    handlePreviewUpload(file) {
      if (file && file.url) {
        this.$download.saveAs(file.url, file.name)
      }
    },
    fileNameFromUrl(url) {
      return (url || '').replace(/^[0-9a-fA-F-]{36}_/, '')
    },
    // 编辑
    handleUpdate(row) {
      this.title = '文件变更申请'
      this.addInfo = this.HaveJson(row)
      this.file = null
      // 回显已上传的附件,保存时未重新选择则保留原附件
      this.fileList = row.url
        ? [{ name: this.fileNameFromUrl(row.url), url: this.javaApi + '/word/' + row.url }]
        : []
      this.addDialogVisible = true
    },
    // 查看附件
@@ -492,9 +530,13 @@
      } else {
        this.noCheckLoading = true
      }
      this.addLoading = true
      this.$refs['UpPdfStamp'].generatePDF()
    },
    // 预览失败或没选文件时复位按钮,避免“通过”一直转圈
    handlePdfError() {
      this.checkLoading = false
      this.noCheckLoading = false
    },
    handleDelete(row) {
      this.$confirm("是否删除该条数据?", "提示", {
        confirmButtonText: "确定",