吴羡
6 小时以前 a1faa94fbf85553f22da934a1abc745d89dd8667
src/views/CNAS/resourceDemand/device/component/equipmentVerificationPlan.vue
@@ -1,137 +1,97 @@
<template>
  <!--  设备核查计划-->
  <div>
    <div>
      <div style="margin: 10px 0;display: flex;align-items: center;justify-content: space-between;">
        <div class="title">
          <span style="font-weight: bold">年度计划表</span>
    <div style="margin: 10px 0 14px;">
      <div class="plan-top">
        <div class="plan-top-left">
          <span class="title" style="margin-bottom: 0;">{{ planInfo.planName || (planYear + '年度设备核查计划') }}</span>
          <el-select v-model="planYear" size="small" style="width: 110px; margin-left: 16px;" @change="handleYearChange">
            <el-option v-for="y in yearOptions" :key="y" :label="y" :value="y"></el-option>
          </el-select>
        </div>
        <div style="display: flex;align-items: center;">
          <el-button size="small" type="primary" @click="getYearTableData">刷新</el-button>
          <el-button size="small" type="primary" @click="addYearPlan('add')">新增</el-button>
          <!--          <el-upload ref="upload" :action="action"-->
          <!--                     :before-upload="beforeUpload" :headers="uploadHeader" :on-error="onError"-->
          <!--                     :on-success="handleSuccessUp" :show-file-list="false" accept='.xls,.xlsx'>-->
          <!--            <el-button :loading="upLoading" size="small" type="primary">导入</el-button>-->
          <!--          </el-upload>-->
        <div>
          <el-button size="small" type="primary" @click="loadPlan">刷新</el-button>
          <el-button size="small" type="primary" @click="downLoadPost">导出</el-button>
        </div>
      </div>
      <div class="plan-info-bar">
        <span>编制人:{{ planInfo.writeName || '—' }}</span>
        <span>编制日期:{{ planInfo.writeTimeStr || '—' }}</span>
        <span v-if="planInfo.ratifyStatus === 1">批准状态:<el-tag type="success">批准</el-tag></span>
        <span v-else-if="planInfo.ratifyStatus === 0">批准状态:<el-tag type="danger">不批准</el-tag></span>
        <span v-if="planInfo.ratifyRemark">批准内容:{{ planInfo.ratifyRemark }}</span>
        <span v-if="isRatified && planInfo.ratifyName">批准人:{{ planInfo.ratifyName }}</span>
        <span v-if="isRatified && planInfo.ratifyTimeStr">批准时间:{{ planInfo.ratifyTimeStr }}</span>
      </div>
    </div>
    <div class="search">
      <div>
        <el-table ref="yearTable" v-loading="yearTableDataLoading" :data="yearTableData"
                  height="calc(60vh - 16em)"
 border
                  highlight-current-row @current-change="currentChange">
          <!-- 表格列 -->
          <el-table-column align="center" header-align="center" label="序号" prop="prop" type="index"
            width="70"></el-table-column>
          <el-table-column label="年份" min-width="80" prop="planYear"></el-table-column>
          <el-table-column label="计划名称" min-width="180" prop="planName" show-overflow-tooltip></el-table-column>
          <el-table-column label="编制人" min-width="100" prop="writeName"></el-table-column>
          <el-table-column label="编制日期" min-width="160" prop="writeTime"></el-table-column>
          <el-table-column label="批准状态" min-width="100" prop="ratifyStatus">
            <template #default="scope">
              <el-tag v-if="scope.row.ratifyStatus === 1" type="success">批准</el-tag>
              <el-tag v-if="scope.row.ratifyStatus === 0" type="danger">不批准</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="批准内容" min-width="150" prop="ratifyRemark"></el-table-column>
          <el-table-column label="批准人" min-width="100" prop="ratifyName"></el-table-column>
          <el-table-column label="批准时间" min-width="150" prop="ratifyTime"></el-table-column>
          <!-- 操作按钮 -->
          <el-table-column align="center" fixed="right" label="操作" min-width="240">
            <template #default="scope">
              <el-button :disabled="scope.row.ratifyStatus === 1" size="small" link type="primary"
                @click="addYearPlan('edit', scope.row)">编辑</el-button>
              <el-button :disabled="scope.row.ratifyStatus === 1" size="small" link type="primary"
                @click="tellApprove(scope.row.planId)">批准通知</el-button>
              <el-button :disabled="scope.row.ratifyStatus === 1 || userId != scope.row.ratifyUserId" size="small"
                link type="primary" @click="handleApprove(scope.row.planId)">批准</el-button>
              <el-button size="small" link type="primary" @click="downLoadPost(scope.row.planId)">导出</el-button>
              <el-button :disabled="scope.row.ratifyStatus === 1" size="small" link type="danger"
                @click="deleteFun(scope.row.planId)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page="1" :page-size="pagination.size" :page-sizes="[10, 20, 30, 50, 100]"
                       background :total="pagination.total" layout="->,total, sizes, prev, pager, next, jumper"
                       @size-change="handleSizeChange" @current-change="handleCurrentChange">
        </el-pagination>
        <el-form :model="searchForm" ref="searchForm" size="small" :inline="true">
          <el-form-item label="设备编号" prop="deviceNumber">
            <el-input v-model="searchForm.deviceNumber" clearable size="small"
              @keyup.enter="handleQuery"></el-input>
          </el-form-item>
          <el-form-item label="设备名称" prop="deviceName">
            <el-input v-model="searchForm.deviceName" clearable size="small"
              @keyup.enter="handleQuery"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="handleQuery">查询</el-button>
            <el-button size="small" @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div>
      <div class="title">
        <span style="font-weight: bold">年度计划明细表</span>
      </div>
      <div class="search">
        <div>
          <el-form :model="searchForm" ref="searchForm" size="small" :inline="true">
            <el-form-item label="设备编号" prop="deviceNumber">
              <el-input v-model="searchForm.deviceNumber" clearable size="small"
                        @keyup.enter="getYearTableDetailData(currentRow)"></el-input>
            </el-form-item>
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="searchForm.deviceName" clearable size="small"
                        @keyup.enter="getYearTableDetailData(currentRow)"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="small" @click="getYearTableDetailData(currentRow)">查询</el-button>
              <el-button size="small" @click="reset">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-button size="small" type="primary" @click="handleForm('add')">新增</el-button>
        </div>
      </div>
      <div>
        <el-table ref="yearTableDetailData" v-loading="yearTableDetailDataLoading" :data="yearTableDetailData"
 border
                  :height="'calc(100vh - 34em)'" style="width: 100% ;">
          <!-- 表格列 -->
          <el-table-column align="center" header-align="center" label="序号" prop="prop" type="index"
            width="70"></el-table-column>
          <el-table-column label="设备编号" min-width="180" prop="deviceNumber"></el-table-column>
          <el-table-column label="设备名称" min-width="180" prop="deviceName" show-overflow-tooltip></el-table-column>
          <el-table-column label="核查时间" min-width="150" prop="checkTime"></el-table-column>
          <el-table-column label="核查指标" min-width="150" prop="checkIndex"> </el-table-column>
          <el-table-column label="核查方法" min-width="150" prop="checkMethod"></el-table-column>
          <el-table-column label="结果如何判定" min-width="150" prop="howResults"></el-table-column>
          <el-table-column label="核查负责人" min-width="150" prop="checkChargerUser"></el-table-column>
          <el-table-column label="记录状态" min-width="100" prop="recordStatus">
            <template #default="scope">
              <el-tag type="" v-if="scope.row.recordStatus === 0" disable-transitions>未开始</el-tag>
              <el-tag type="warning" v-if="scope.row.recordStatus === 1" disable-transitions>待批准</el-tag>
              <el-tag type="success" v-if="scope.row.recordStatus === 2" disable-transitions>通过</el-tag>
              <el-tag type="danger" v-if="scope.row.recordStatus === 3" disable-transitions>不通过</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="对比状态" min-width="100" prop="recordContrastStatus">
            <template #default="scope">
              <el-tag type="" v-if="scope.row.recordContrastStatus === 0" disable-transitions>未开始</el-tag>
              <el-tag type="warning" v-if="scope.row.recordContrastStatus === 1" disable-transitions>待批准</el-tag>
              <el-tag type="success" v-if="scope.row.recordContrastStatus === 2" disable-transitions>通过</el-tag>
              <el-tag type="danger" v-if="scope.row.recordContrastStatus === 3" disable-transitions>不通过</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="150" prop="remark"></el-table-column>
          <!-- 操作按钮 -->
          <el-table-column align="center" fixed="right" label="操作" min-width="260">
            <template #default="scope">
              <el-button size="small" link type="primary" @click="handleForm('edit', scope.row)">编辑</el-button>
              <el-button size="small" link type="primary" @click="handleForm('view', scope.row)">查看</el-button>
              <el-button size="small" link type="primary" @click="handleRecord(scope.row)">记录</el-button>
              <el-button size="small" link type="primary" @click="handleCheck(scope.row)">对比</el-button>
              <el-button size="small" link type="primary" @click="handleDown(scope.row)">导出</el-button>
              <el-button size="small" link type="danger"
                @click="deleteFun1(scope.row.planDetailsId)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page="1" :page-size="pagination1.size" :page-sizes="[10, 20, 30, 50, 100]"
          :total="pagination1.total" layout="->,total, sizes, prev, pager, next, jumper" background
          @size-change="handleSizeChange1" @current-change="handleCurrentChange1">
        </el-pagination>
      </div>
      <el-table ref="yearTableDetailData" v-loading="yearTableDetailDataLoading" :data="yearTableDetailData" border
        :row-class-name="tableRowClassName" :height="'calc(100vh - 29em)'" style="width: 100%;">
        <!-- 表格列 -->
        <el-table-column align="center" header-align="center" label="序号" prop="prop" type="index"
          width="70"></el-table-column>
        <el-table-column label="设备编号" min-width="170" prop="deviceNumber"></el-table-column>
        <el-table-column label="设备名称" min-width="180" prop="deviceName" show-overflow-tooltip></el-table-column>
        <el-table-column label="核查时间" min-width="120" prop="checkTime"
          :formatter="formatCheckMonth"></el-table-column>
        <el-table-column label="核查指标" min-width="140" prop="checkIndex"> </el-table-column>
        <el-table-column label="核查方法" min-width="140" prop="checkMethod" show-overflow-tooltip></el-table-column>
        <el-table-column label="结果如何判定" min-width="140" prop="howResults" show-overflow-tooltip></el-table-column>
        <el-table-column label="核查负责人" min-width="120" prop="checkChargerUser"></el-table-column>
        <el-table-column label="记录状态" min-width="100" prop="recordStatus">
          <template #default="scope">
            <el-tag type="" v-if="scope.row.recordStatus === 0" disable-transitions>未开始</el-tag>
            <el-tag type="warning" v-if="scope.row.recordStatus === 1" disable-transitions>待批准</el-tag>
            <el-tag type="success" v-if="scope.row.recordStatus === 2" disable-transitions>通过</el-tag>
            <el-tag type="danger" v-if="scope.row.recordStatus === 3" disable-transitions>不通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="对比状态" min-width="100" prop="recordContrastStatus">
          <template #default="scope">
            <el-tag type="" v-if="scope.row.recordContrastStatus === 0" disable-transitions>未开始</el-tag>
            <el-tag type="warning" v-if="scope.row.recordContrastStatus === 1" disable-transitions>待批准</el-tag>
            <el-tag type="success" v-if="scope.row.recordContrastStatus === 2" disable-transitions>通过</el-tag>
            <el-tag type="danger" v-if="scope.row.recordContrastStatus === 3" disable-transitions>不通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="130" prop="remark"></el-table-column>
        <!-- 操作按钮 -->
        <el-table-column align="center" fixed="right" label="操作" min-width="260">
          <template #default="scope">
            <el-button size="small" link type="primary"
              @click="handleForm('edit', scope.row)">编辑</el-button>
            <el-button size="small" link type="primary" @click="handleForm('view', scope.row)">查看</el-button>
            <el-button size="small" link type="primary" @click="handleRecord(scope.row)">记录</el-button>
            <el-button size="small" link type="primary" @click="handleCheck(scope.row)">对比</el-button>
            <el-button size="small" link type="primary" @click="handleDown(scope.row)">导出</el-button>
            <el-button size="small" link type="danger"
              @click="deleteFun1(scope.row.planDetailsId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="pagination1.current" :page-size="pagination1.size"
        :page-sizes="[10, 20, 30, 50, 100]" :total="pagination1.total"
        layout="->,total, sizes, prev, pager, next, jumper" background
        @size-change="handleSizeChange1" @current-change="handleCurrentChange1">
      </el-pagination>
    </div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="dialogVisible" title="设备核查计划"
      width="80%" @close="resetForm">
@@ -175,7 +135,7 @@
          <el-form-item label="核查责任人:" prop="checkChargerUserId">
            <el-select v-model="form.checkChargerUserId" @change="setCheckChargerUser"
              :disabled="operationType === 'view'" placeholder="请选择" size="small" style="width: 100%">
              <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              <el-option v-for="item in chargerOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
@@ -185,74 +145,49 @@
          </el-form-item>
        </el-col>
      </el-form>
      <template #footer><span  class="dialog-footer">
      <template #footer><span class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button :loading="submitFormLoading" type="primary" @click="submitForm" v-if="operationType !== 'view'">确
          认</el-button>
      </span></template>
    </el-dialog>
    <el-dialog v-model="approvalDialog" title="批准" width="30%" @close="approvalDialog = false">
      <span>
        批准备注:
        <el-input v-model="ratifyRemark" type="textarea"></el-input>
      </span>
      <template #footer><span  class="dialog-footer">
        <el-button :loading="approvalLoading" @click="handleApproval(0)">不批准</el-button>
        <el-button :loading="approvalLoading" type="primary" @click="handleApproval(1)">批 准</el-button>
        <el-button :loading="submitFormLoading" type="primary" @click="submitForm"
          v-if="operationType !== 'view'">确 认</el-button>
      </span></template>
    </el-dialog>
    <el-dialog v-model="downloadDialog" title="导出" width="600px">
      <span>
        <el-button :loading="outLoading" type="primary" :disabled="!downRow.recordStatus" @click="controlDown">核查记录</el-button>
        <el-button :loading="outLoading" type="primary" :disabled="!downRow.recordContrastStatus" @click="processingDown">核查比对记录</el-button>
        <el-button :loading="outLoading" type="primary" :disabled="!downRow.recordStatus"
          @click="controlDown">核查记录</el-button>
        <el-button :loading="outLoading" type="primary" :disabled="!downRow.recordContrastStatus"
          @click="processingDown">核查比对记录</el-button>
      </span>
      <template #footer><span  class="dialog-footer">
      <template #footer><span class="dialog-footer">
        <el-button @click="downloadDialog = false">取 消</el-button>
      </span></template>
    </el-dialog>
    <el-dialog v-model="notificationDia" title="提交批准" width="30%" @close="closeNotificationDia">
      <span style="margin-top: 10px;display: inline-block">
        请选择批准人:
        <el-select v-model="ratifyUserId" clearable filterable size="small" style="width: 90%;">
          <el-option v-for="item in responsibleOptions" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </span>
      <template #footer><span  class="dialog-footer">
        <el-button :loading="notificationLoading" @click="closeNotificationDia">取 消</el-button>
        <el-button :loading="notificationLoading" type="primary" @click="notification">提 交</el-button>
      </span></template>
    </el-dialog>
    <equipment-check v-if="equipmentCheck" ref="equipmentCheck" @closeDialog="closeDialog"></equipment-check>
    <check-record v-if="checkRecord" ref="checkRecord" @closeDialog1="closeDialog1"></check-record>
    <add-verification-year-plan-dia v-if="addYearPlanDia" ref="addYearPlanDia"
      @closeDia="closeDia"></add-verification-year-plan-dia>
  </div>
</template>
<script>
import EquipmentCheck from "./equipmentCheck.vue";
import CheckRecord from "./checkRecord.vue";
import AddVerificationYearPlanDia from "./addVerificationYearPlanDia.vue";
import {
  pageDeviceExaminePlan,
  submitRatifyDeviceExaminePlan,
  getExaminePlanByYear,
  exportDeviceExaminePlanDetail,
  delDeviceExaminePlan,
  delDeviceExaminePlanDetail,
  pageDeviceExaminePlanDetail,
  addDeviceExaminePlanDetail,
  updateDeviceExaminePlanDetail,
  ratifyDeviceExaminePlan,
  exportReviewExamineRecordDetail,
  exportReviewExamineRecordContrast,
} from '@/api/cnas/resourceDemand/device.js'
import { selectUserCondition } from "@/api/performance/class";
import { mapGetters } from "@/utils/store-compat";
import draftSave from '@/mixins/draftSave'
import { formatListDate } from './dateFormat'
export default {
  name: "equipment-verification-plan",
  // import 引入的组件需要注入到对象中才能使用
  components: { AddVerificationYearPlanDia, CheckRecord, EquipmentCheck },
  components: { CheckRecord, EquipmentCheck },
  mixins: [draftSave],
  props: {
    clickNodeVal: {
      type: Object,
@@ -264,19 +199,15 @@
  data() {
    // 这里存放数据
    return {
      upLoading: false,
      planYear: '',
      yearOptions: [],
      planInfo: {},
      dialogVisible: false,
      searchForm: {
        deviceName: '',
        deviceNumber: '',
      },
      yearTableData: [],
      yearTableDetailData: [],
      pagination: {
        size: 10,
        current: 1,
        total: 0,
      },
      pagination1: {
        size: 10,
        current: 1,
@@ -300,163 +231,74 @@
        deviceNumber: [{ required: true, message: '请填写设备编号', trigger: 'blur' }],
        checkMethod: [{ required: true, message: '请填写核查方法', trigger: 'blur' }],
      },
      yearTableDataLoading: false,
      yearTableDetailDataLoading: false,
      currentRow: {},
      approvalDialog: false,
      approvalLoading: false,
      submitFormLoading: false,
      ratifyRemark: '',
      currentRowId: '',
      userList: [],
      equipmentCheck: false,
      checkRecord: false,
      addYearPlanDia: false,
      downloadDialog: false,
      outLoading: false,
      downRow: {},
      responsibleOptions: [],
      notificationDia: false,
      notificationLoading: false,
      ratifyUserId: '',
      planId: ''
    }
  },
  mounted() {
    this.getYearTableData()
    this.loadYearOptions()
  },
  // 方法集合
  methods: {
    // 查询年度计划表
    getYearTableData() {
      this.yearTableDataLoading = true
    // 年份下拉选项:已有计划年份 + 当前年份
    loadYearOptions() {
      pageDeviceExaminePlan({
        current: 1,
        size: 99,
      }).then(res => {
        let years = []
        if (res.code == 200) {
          this.yearTableData = res.data.records
          this.pagination.total = res.data.total
          if (this.yearTableData.length > 0) {
            this.currentRow = this.yearTableData[0]
            this.$refs.yearTable.setCurrentRow(this.currentRow)
          }
          years = (res.data.records || []).map(r => r.planYear).filter(Boolean)
        }
        this.yearTableDataLoading = false
      }).catch(err => {
        this.yearTableDataLoading = false
        const currentYear = String(new Date().getFullYear())
        if (years.indexOf(currentYear) === -1) {
          years.push(currentYear)
        }
        this.yearOptions = [...new Set(years)].sort((a, b) => b.localeCompare(a))
        this.planYear = currentYear
        this.loadPlan()
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pagination.size = val
      this.getYearTableData()
    // 切换年份
    handleYearChange() {
      this.pagination1.current = 1
      this.loadPlan()
    },
    // 分页
    handleCurrentChange(val) {
      this.pagination.current = val
      this.getYearTableData()
    },
    // 打开新增弹框
    addYearPlan(type, row) {
      this.addYearPlanDia = true
      this.$nextTick(() => {
        this.$refs.addYearPlanDia.openDialog(type, row)
    // 查询年份计划(不存在自动创建并补全到点明细),随后刷新明细
    loadPlan() {
      getExaminePlanByYear({ planYear: this.planYear }).then(res => {
        if (res.code == 200) {
          this.planInfo = res.data || {}
        }
        this.getYearTableDetailData()
      }).catch(() => {
        this.planInfo = {}
        this.yearTableDetailData = []
        this.pagination1.total = 0
        this.yearTableDetailDataLoading = false
      })
    },
    closeDia() {
      this.addYearPlanDia = false
      this.getYearTableData()
    // 查询条件变化后从第一页开始查
    handleQuery() {
      this.pagination1.current = 1
      this.getYearTableDetailData()
    },
    // 打开提交批准弹框
    tellApprove(planId) {
      this.getUserList1()
      this.notificationDia = true
      this.planId = planId
    },
    // 关闭提交批准弹框
    closeNotificationDia() {
      this.notificationDia = false
      this.ratifyUserId = ''
    },
    // 提交批准通知
    notification() {
      if (!this.ratifyUserId) {
        this.$message.warning('请选择批准人')
    // 明细-查询
    getYearTableDetailData() {
      if (!this.planInfo.planId) {
        return
      }
      this.notificationLoading = true
      submitRatifyDeviceExaminePlan({
        ratifyUserId: this.ratifyUserId,
        planId: this.planId,
      }).then(res => {
        this.notificationLoading = false
        if (res.code == 200) {
          this.closeNotificationDia()
          this.getYearTableData()
        }
      }).catch(err => {
        this.notificationLoading = false
      })
    },
    // 年度计划表-批准
    handleApprove(id) {
      this.currentRowId = id
      this.approvalDialog = true
    },
    // 年度计划表-导出
    downLoadPost(planId) {
      exportDeviceExaminePlanDetail({ planId }).then(res => {
        const blob = new Blob([res], { type: 'application/msword' });
        this.$download.saveAs(blob, '仪器设备期间核查计划表.docx')
      })
    },
    // 年度计划表-删除
    deleteFun(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delDeviceExaminePlan({ planId: id }).then(res => {
          this.$message.success('删除成功!');
          this.getYearTableData();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 年度计划详情表-删除
    deleteFun1(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delDeviceExaminePlanDetail({ planDetailsId: id }).then(res => {
          this.$message.success('删除成功!');
          this.getYearTableDetailData(this.currentRow)
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    currentChange(row) {
      this.currentRow = row
      this.getYearTableDetailData(this.currentRow)
    },
    getYearTableDetailData(row) {
      this.yearTableDetailDataLoading = true
      pageDeviceExaminePlanDetail({
        current: this.pagination1.current,
        size: this.pagination1.size,
        planId: row.planId,
        planId: this.planInfo.planId,
        deviceName: this.searchForm.deviceName,
        deviceNumber: this.searchForm.deviceNumber,
      }).then(res => {
@@ -469,101 +311,100 @@
        this.yearTableDetailDataLoading = false
      })
    },
    // 到点需核查的行标红
    // 核查时间按月份显示(兼容历史数据中的完整日期)
    formatCheckMonth(row, column, cellValue) {
      if (cellValue === null || cellValue === undefined || cellValue === '') {
        return cellValue
      }
      const str = String(cellValue).trim().replace(/[./]/g, '-')
      const matched = str.match(/^(\d{4})-(\d{1,2})/)
      if (matched) {
        return `${matched[1]}-${matched[2].padStart(2, '0')}`
      }
      const formatted = formatListDate(str)
      const fallback = String(formatted).match(/^(\d{4})-(\d{1,2})/)
      return fallback ? `${fallback[1]}-${fallback[2].padStart(2, '0')}` : cellValue
    },
    tableRowClassName({ row }) {
      return row.redFlag === 1 ? 'red-row' : ''
    },
    reset() {
      this.searchForm = {
        deviceName: '',
        deviceNumber: '',
      }
      this.getYearTableDetailData(this.currentRow)
      this.pagination1.current = 1
      this.getYearTableDetailData()
    },
    // 分页
    handleSizeChange1(val) {
      this.pagination1.size = val
      this.getYearTableDetailData(this.currentRow)
      this.getYearTableDetailData()
    },
    // 分页
    handleCurrentChange1(val) {
      this.pagination1.current = val
      this.getYearTableDetailData(this.currentRow)
      this.getYearTableDetailData()
    },
    // 打开弹框
    // 打开明细弹框
    handleForm(type, row) {
      this.getUserList()
      this.operationType = type
      this.dialogVisible = true
      this.form.planId = this.currentRow.planId
      if (this.operationType !== 'add') {
        this.$nextTick(() => {
          this.form = this.HaveJson(row)
        })
      } else {
        this.form = {
          deviceNumber: '',
          deviceName: '',
          checkTime: '',
          checkIndex: '',
          checkMethod: '',
          howResults: '',
          checkChargerUserId: '',
          checkChargerUser: '',
          remark: '',
          planId: this.currentRow.planId,
          planDetailsId: '',
      this.form.planId = this.planInfo.planId
      this.$nextTick(() => {
        this.form = this.HaveJson(row)
        if (this.operationType !== 'view') {
          this.draftRestore('equipmentVerificationPlan', 'form', this.form.planDetailsId, 'dialogVisible')
        }
      }
      })
    },
    // 提交表单
    submitForm() {
      this.$refs.modelForm.validate(valid => {
        if (valid) {
          if (this.operationType === 'add') {
            this.submitFormLoading = true
            addDeviceExaminePlanDetail(this.form).then(res => {
              if (res.code == 200) {
                this.$message.success('新增成功')
                this.dialogVisible = false
                this.getYearTableData()
              }
              this.submitFormLoading = false
            }).catch(err => {
              this.submitFormLoading = false
            })
          } else {
            this.submitFormLoading = true
            updateDeviceExaminePlanDetail(this.form).then(res => {
              if (res.code == 200) {
                this.$message.success('新增成功')
                this.dialogVisible = false
                this.getYearTableData()
              }
              this.submitFormLoading = false
            }).catch(err => {
              this.submitFormLoading = false
            })
          }
          this.submitFormLoading = true
          updateDeviceExaminePlanDetail(this.form).then(res => {
            if (res.code == 200) {
              this.$message.success('修改成功')
              this.draftClear('equipmentVerificationPlan')
              this.dialogVisible = false
              this.getYearTableDetailData()
            }
            this.submitFormLoading = false
          }).catch(err => {
            this.submitFormLoading = false
          })
        }
      })
    },
    // 提交批准
    handleApproval(status) {
      const personTrainingUpdateDto = {
        planId: this.currentRowId,
        ratifyRemark: this.ratifyRemark,
        ratifyStatus: status
      }
      this.approvalLoading = true
      ratifyDeviceExaminePlan(personTrainingUpdateDto).then(res => {
        if (res.code === 200) {
          this.$message.success('提交成功!');
          this.approvalDialog = false
          this.getYearTableData();
        }
        this.approvalLoading = false
    // 明细-删除
    deleteFun1(id) {
      this.$confirm('此操作将永久删除该条明细, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delDeviceExaminePlanDetail({ planDetailsId: id }).then(res => {
          this.$message.success('删除成功!');
          this.getYearTableDetailData()
        });
      }).catch(() => {
        this.approvalLoading = false
      })
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 导出年度计划表
    downLoadPost() {
      exportDeviceExaminePlanDetail({ planId: this.planInfo.planId }).then(res => {
        this.saveDocx(res, '仪器设备期间核查计划表.docx')
      }).catch(() => { })
    },
    resetForm() {
      this.draftStop('equipmentVerificationPlan')
      this.$refs.modelForm.resetFields();
      this.dialogVisible = false
    },
@@ -577,7 +418,7 @@
    // 关闭对比弹框
    closeDialog() {
      this.equipmentCheck = false
      this.getYearTableDetailData(this.currentRow)
      this.getYearTableDetailData()
    },
    // 打开记录弹框
    handleRecord(row) {
@@ -589,7 +430,7 @@
    // 关闭记录弹框
    closeDialog1() {
      this.checkRecord = false
      this.getYearTableDetailData(this.currentRow)
      this.getYearTableDetailData()
    },
    // 打开导出弹框
    handleDown(row) {
@@ -604,7 +445,7 @@
        const text = (reader.result || '').trim();
        if (text.startsWith('{') || text.startsWith('[')) {
          let msg = '导出失败';
          try { msg = JSON.parse(text).msg || msg; } catch (e) {}
          try { msg = JSON.parse(text).msg || msg; } catch (e) { }
          this.$message.error(msg);
        } else {
          this.$download.saveAs(new Blob([res], { type: 'application/msword' }), filename);
@@ -634,30 +475,6 @@
        this.outLoading = false
      })
    },
    // 导入流程
    beforeUpload(file) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        this.upLoading = true;
        return true;
      }
    },
    onError(err, file, fileList) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
    handleSuccessUp(response) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.getYearTableData()
      } else {
        this.$message.error(response.message)
      }
    },
    getUserList() {
      selectUserCondition().then(res => {
        this.userList = res.data
@@ -668,32 +485,33 @@
      if (index > -1) {
        this.form.checkChargerUser = this.userList[index].name
      }
    },
    // 获取负责人信息接口
    getUserList1() {
      selectUserCondition().then(res => {
        if (res.code == 200) {
          this.responsibleOptions = res.data
        }
      });
    }
  },
  // 用于上传文件的信息
  computed: {
    action() {
      return this.javaApi + '/deviceExaminePlan/importDeviceExaminePlan'
    // 是否已完成审批(批准/不批准)
    isRatified() {
      return this.planInfo.ratifyStatus === 0 || this.planInfo.ratifyStatus === 1;
    },
    ...mapGetters(["userId"]),
    // 责任人下拉:已保存的责任人不在候选列表时补一条,避免回显成用户ID
    chargerOptions() {
      const list = this.userList || []
      const id = this.form.checkChargerUserId
      if (id && !list.some(item => String(item.id) === String(id))) {
        return [...list, { id, name: this.form.checkChargerUser || String(id) }]
      }
      return list
    },
  },
}
</script>
<style scoped>
.search {
  height: 46px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}
.title {
  position: relative;
  font-size: 16px;
@@ -713,4 +531,33 @@
  background-color: var(--el-color-primary);
  border-radius: 2px;
}
.plan-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.plan-top-left {
  display: flex;
  align-items: center;
}
.plan-info-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 32px;
  background: #f5f7fa;
  border-radius: 4px;
  padding: 10px 16px;
  margin-top: 14px;
  font-size: 14px;
  color: #606266;
}
:deep(.red-row td) {
  background: #ffcccc !important;
}
</style>