yyb
83 分钟以前 a567edf28abb00581c93b27405ed9657b63a8bd7
src/views/equipmentManagement/measurementEquipment/index.vue
@@ -1,6 +1,6 @@
<template>
   <div class="app-container">
      <div class="search_form">
      <div class="search_form mb20">
         <div>
            <span class="search_title">录入日期:</span>
            <el-date-picker
@@ -23,6 +23,7 @@
            <el-button type="primary" @click="handleQuery" style="margin-left: 10px"
            >搜索</el-button
            >
            <el-button @click="handleReset" style="margin-left: 10px">重置</el-button>
         </div>
         <div>
            <el-button type="primary" @click="openForm('add')">新增计量器具</el-button>
@@ -40,23 +41,29 @@
            @selection-change="handleSelectionChange"
            :tableLoading="tableLoading"
            @pagination="pagination"
        :dbRowClick="dbRowClick"
        :rowClassName="rowClassName"
         ></PIMTable>
      </div>
      <form-dia ref="formDia" @close="handleQuery"></form-dia>
      <calibration-dia ref="calibrationDia" @close="handleQuery"></calibration-dia>
    <files-dia ref="filesDia"></files-dia>
    <rowClickDataForm ref="rowClickData"></rowClickDataForm>
   </div>
</template>
<script setup>
import {onMounted, ref} from "vue";
import {onMounted, ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
import FormDia from "@/views/equipmentManagement/measurementEquipment/components/formDia.vue";
import {ElMessageBox} from "element-plus";
import useUserStore from "@/store/modules/user.js";
import CalibrationDia from "@/views/equipmentManagement/measurementEquipment/components/calibrationDia.vue";
import {
   measuringInstrumentDelete,
   measuringInstrumentListPage
  measuringInstrumentDelete,
  measuringInstrumentListPage,
} from "@/api/equipmentManagement/measurementEquipment.js";
import FilesDia from "./filesDia.vue";
import rowClickDataForm from "./components/rowClickData.vue"
const { proxy } = getCurrentInstance();
const userStore = useUserStore()
@@ -71,67 +78,68 @@
const tableColumn = ref([
   {
      label: "状态",
      prop: "status",
      dataType: "tag",
      formatData: (params) => {
         if (params == 1) {
            return "有效";
         } else if (params == 2) {
            return "逾期";
         } else {
            return null;
         }
      },
      formatType: (params) => {
         if (params == 1) {
            return "success";
         } else if (params == 2) {
            return "danger";
         } else {
            return null;
         }
      },
      label: "出厂编号",
      prop: "code",
    minWidth:150,
    align:"center"
   },
  {
    label: "计量器具名称",
    prop: "name",
    width: '160px',
    align: "center",
  },
   {
      label: "检定单位",
      prop: "unit",
      width: 200,
    align:"center"
   },
   {
      label: "最近一次检定日期",
      label: "证书编号",
      prop: "model",
      width:200,
    align:"center"
   },
   {
      label: "最新鉴定日期",
      prop: "mostDate",
      width: 130,
   },
   {
      label: "计量器具编号",
      prop: "code",
      width: 150,
   },
   {
      label: "计量器具名称",
      prop: "name",
      width: 200,
   },
   {
      label: "规格型号",
      prop: "model",
      width:200
   },
   {
      label: "有效期",
      prop: "valid",
      width: 130,
   },
   {
      label: "预计下次检定日期",
      prop: "nextDate",
      width: 130,
    align:"center"
   },
   {
      label: "录入人",
      prop: "userName",
      width: 130,
    align:"center"
   },
   {
      label: "录入日期",
      prop: "recordDate",
      width: 130,
    align:"center",
    minWidth: 130
   },
   {
      label: "有效日期",
      prop: "valid",
      width: 130,
    align:"center"
   },
  {
    label: "状态",
    prop: "status",
    width: 130,
    align: "center",
    formatData: (params) => {
      if (params === 1) {
        return "有效";
      } else if (params === 2) {
        return "逾期";
      } else {
        return null;
      }
    }
  },
   {
      dataType: "action",
      label: "操作",
@@ -139,18 +147,18 @@
      width: '130',
      fixed: 'right',
      operation: [
      {
         name: "附件",
         type: "text",
         clickFun: (row) => {
          openFilesFormDia(row);
         },
      },
         {
            name: "检定校准",
            name: "查看",
            type: "text",
            clickFun: (row) => {
               openCalibrationDia("verifying", row);
            },
         },
         {
            name: "附件",
            type: "text",
            clickFun: (row) => {
               openCalibrationDia("add", row);
            },
         },
      ],
@@ -158,12 +166,48 @@
]);
const tableData = ref([]);
const tableLoading = ref(false);
const rowClickData = ref([])
const filesDia = ref()
const page = reactive({
   current: 1,
   size: 100,
   total: 0,
});
const selectedRows = ref([]);
// 打开附件弹框
const openFilesFormDia = (row) => {
    filesDia.value?.openDialog(row,'计量器具台账')
};
const dbRowClick = (row)=>{
  rowClickData.value?.openDialog(row)
}
// 行样式:快到期(7天内)或逾期标红
const rowClassName = ({ row }) => {
  console.log('rowClassName called:', row);
  // valid 是有效天数,mostDate 是最新检定日期
  if (row.valid && row.mostDate) {
    const mostDate = new Date(row.mostDate);
    // 计算到期日期 = 检定日期 + 有效天数
    const validDays = parseInt(row.valid) || 0;
    const expireDate = new Date(mostDate);
    expireDate.setDate(expireDate.getDate() + validDays);
    const now = new Date();
    const diffDays = Math.ceil((expireDate - now) / (1000 * 60 * 60 * 24));
    console.log('row:', row.code, 'validDays:', validDays, 'expireDate:', expireDate, 'diffDays:', diffDays);
    // 7天内到期或已逾期都标红
    if (diffDays <= 7) {
      console.log('return warning-row');
      return 'warning-row';
    }
  } else {
    console.log('row missing valid or mostDate:', row.valid, row.mostDate);
  }
  return '';
}
// 表格选择数据
const handleSelectionChange = (selection) => {
@@ -175,6 +219,15 @@
// 查询列表
/** 搜索按钮操作 */
const handleQuery = () => {
   page.current = 1;
   getList();
};
// 重置搜索条件
const handleReset = () => {
   searchForm.value.recordDate = "";
   searchForm.value.code = "";
   searchForm.value.status = "";
   page.current = 1;
   getList();
};
@@ -210,12 +263,6 @@
const handleDelete = () => {
   let ids = [];
   if (selectedRows.value.length > 0) {
      // 检查是否有他人维护的数据
      const unauthorizedData = selectedRows.value.filter(item => item.userId !== userStore.id);
      if (unauthorizedData.length > 0) {
         proxy.$modal.msgWarning("不可删除他人维护的数据");
         return;
      }
      ids = selectedRows.value.map((item) => item.id);
   } else {
      proxy.$modal.msgWarning("请选择数据");
@@ -261,5 +308,13 @@
</script>
<style scoped>
:deep(.el-table .warning-row) {
  background-color: #fef0f0 !important;
}
:deep(.el-table .warning-row:hover > td) {
  background-color: #f9d5d5 !important;
}
:deep(.el-table .el-table__body tr.warning-row td) {
  background-color: #fef0f0 !important;
}
</style>