zhang_12370
2025-07-23 ba07ace535232e5ea77cf0a89cd1c079895e1441
src/views/equipment/management/index.vue
@@ -52,7 +52,7 @@
          >删除</el-button
        >
      </el-row>
      <!-- 表格组件 -->
       <!-- 表格组件 -->
      <div>
        <data-table
          :showOverflowTooltip="false"
@@ -65,32 +65,11 @@
          @edit="handleEdit"
          @viewRow="handleView"
          @selection-change="handleSelectionChange"
          :operations="['edit', 'viewRow']"
          :operationsWidth="200"
          @custom-click="handleCustomButtonClick"
          :operations="getTableOperations()"
          :operationsWidth="getOperationsWidth()"
          :customButtons="getCustomButtons()"
        >
          <!-- 字段名称列的自定义插槽 - 显示为标签 -->
          <template
            v-if="activeTab === 'coalQualityMaintenance'"
            #fieldIds="{ row }"
          >
            <template
              v-if="
                typeof row.fieldIds === 'string' && row.fieldIds.includes(',')
              "
            >
              <el-tag
                v-for="(field, index) in row.fieldIds.split(',')"
                :key="index"
                size="small"
                style="margin-right: 4px; margin-bottom: 2px"
                type="primary"
              >
              </el-tag>
            </template>
            <template v-else>
              <el-tag size="small" type="primary"> </el-tag>
            </template>
          </template>
        </data-table>
      </div>
      <pagination
@@ -126,6 +105,15 @@
        :form="form"
        @submit="getList"
      /> -->
      <!-- 查看详情弹窗 -->
      <DilogTable
        v-model="dialogTableVisible"
        :title="dialogTableTitle"
        :table-data="dialogTableData"
        :columns="dialogTableColumns"
        width="60%"
      />
    </el-card>
  </div>
</template>
@@ -140,7 +128,7 @@
import Pagination from "@/components/Pagination";
import managementDialog from "./mould/managementDialog.vue";
import EquipmentRequisition from "./mould/equipmentRequisitionDialog.vue";
import UsageRecord from "./mould/usageRecord.vue";
import DilogTable from "@/components/dialog/DilogTable.vue";
// API 服务导入
import { useDelete } from "@/hooks/useDelete.js";
@@ -148,30 +136,60 @@
  getManagementList,
  delEquipment,
} from "@/api/equipment/management/index.js";
import { getUsageRecordList } from "@/api/equipment/requisition/index.js";
import { getUsageRecordList, getUsageDetailList } from "@/api/equipment/requisition/index.js";
// 响应式状态管理
const form = ref({});
const title = ref("");
const copyForm = ref({});
const addOrEdit = ref("add");
const manaDialog = ref(false);
const equipmentRequisitionDialog = ref(false);
const usageRecordDialog = ref(false);
const loading = ref(false);
const activeTab = ref("management");
const selectedRows = ref([]);
const tableData = ref([]);
// 响应式状态管理 - 使用解构和默认值
const initFormState = () => ({ consumables: false });
// 分页状态
const pageNum = ref(1);
const pageSizes = ref(10);
const total = ref(0);
// 查询参数
const queryParams = reactive({
  searchAll: "",
const state = reactive({
  form: initFormState(),
  title: "",
  copyForm: {},
  addOrEdit: "add",
  loading: false,
  activeTab: "management",
  selectedRows: [],
  tableData: [],
  // 弹窗状态
  dialogs: {
    management: false,
    equipmentRequisition: false,
    usageRecord: false,
    detailTable: false,
  },
  // 详情表格状态
  detailTable: {
    data: [],
    columns: [],
    title: "",
  },
  // 分页状态
  pagination: {
    pageNum: 1,
    pageSize: 10,
    total: 0,
  },
  // 查询参数
  queryParams: {
    searchAll: "",
  },
});
// 使用解构简化访问
const {
  form,
  title,
  copyForm,
  addOrEdit,
  loading,
  activeTab,
  selectedRows,
  tableData,
  dialogs,
  detailTable,
  pagination,
  queryParams,
} = toRefs(state);
// 标签页配置 - 便于后续扩展
const tabsConfig = {
@@ -204,12 +222,16 @@
      { prop: "equipmentNo", label: "设备编号", minWidth: 100 },
      { prop: "equipmentName", label: "设备名称", minWidth: 100 },
      { prop: "usageQuantity", label: "领用数量", minWidth: 100 },
      {prop: "returnQuantity" , label: "归还数量", minWidth: 100,
        formatter: (row) => row.returnQuantity || 0
      },
      {
        prop: "equipmentStatus",
        label: "使用状态",
        minWidth: 100,
        formatter: (row) => (row.equipmentStatus == 1 ? "使用中" : "已归还"),
      },
      { prop: "usageStartTime", label: "使用开始时间", minWidth: 100 },
      { prop: "usageEndTime", label: "使用结束时间", minWidth: 100 },
      { prop: "remarks", label: "备注", minWidth: 100 },
@@ -261,6 +283,61 @@
const columns = computed(() => currentTabConfig.value?.columns || []);
const selectedCount = computed(() => selectedRows.value.length);
// 动态获取表格操作配置
const getTableOperations = () => {
  if (activeTab.value === 'equipmentRequisition') {
    return [ 'viewRow']; // 设备领用页面只显示编辑和查看
  }
  return ['edit', 'viewRow']; // 默认操作
};
// 动态获取操作列宽度
const getOperationsWidth = () => {
  if (activeTab.value === 'equipmentRequisition') {
    return 250; // 为归还按钮预留更多空间
  }
  return 200; // 默认宽度
};
// 动态获取自定义按钮配置
const getCustomButtons = () => {
  const buttons = [];
  // 在设备领用页面添加归还按钮
  if (activeTab.value === 'equipmentRequisition') {
    buttons.push({
      name: 'return',
      label: '归还',
      type: 'success',
      size: 'small',
      link: true,
      show: (row) => row.equipmentStatus == 1 || row.equipmentStatus == 2, // 只有使用中的设备才显示归还按钮
      disabled: (row) => false,
    });
  }
  return buttons;
};
// 处理自定义按钮点击事件
const handleCustomButtonClick = ({ buttonName, row }) => {
  switch (buttonName) {
    case 'return':
      handleReturn(row);
      break;
    // 可以在这里添加更多自定义按钮的处理逻辑
    default:
      console.warn(`未处理的自定义按钮: ${buttonName}`);
  }
};
const handleReturn = (row) => {
  form.value = { ...row };
  addOrEdit.value = "return"; // 设置为归还模式
  title.value = `归还设备`;
  copyForm.value = { ...row };
  equipmentRequisitionDialog.value = true;
  console.log("归还设备:", row);
};
// 事件处理函数
const handleTabClick = (tab) => {
  activeTab.value = tab.props.name;
@@ -323,14 +400,74 @@
  }
};
const handleView = (row) => {
const handleView = async (row) => {
  // 针对设备管理页面:直接打开编辑弹窗查看
  if (activeTab.value === 'management') {
    form.value = { ...row };
    addOrEdit.value = "viewRow";
    title.value = `查看${currentTabConfig.value.label}`;
    copyForm.value = { ...row };
    manaDialog.value = true;
    return;
  }
  // 针对设备领用页面:打开详情记录表格
  if (activeTab.value === 'equipmentRequisition') {
    try {
      dialogTableTitle.value = `${row.equipmentName || '设备'} - 操作记录详情`;
      // 显示加载状态
      dialogTableVisible.value = true;
      dialogTableData.value = [];
      // 调用详情接口获取数据
      const { data, code } = await getUsageDetailList(row.id);
      if (code === 200 && data) {
        console.log('设备操作记录:', data);
        // 处理数组数据,直接显示操作记录列表
        if (Array.isArray(data.records)) {
          dialogTableData.value = data.records;
          dialogTableColumns.value = [
            { prop: 'equipmentNo', label: '设备编号', minWidth: 100 },
            { prop: 'equipmentName', label: '设备名称', minWidth: 120 },
            { prop: 'specification', label: '规格型号', minWidth: 100 },
            {
              prop: 'operationType',
              label: '操作类型',
              minWidth: 80,
              formatter: (row) => row.operationType === 1 ? '领用' : '归还'
            },
            { prop: 'quantity', label: '操作数量', minWidth: 80 },
            { prop: 'operator', label: '操作人', minWidth: 80 },
            { prop: 'remark', label: '备注', minWidth: 150, showOverflowTooltip: true },
            { prop: 'createTime', label: '操作时间', minWidth: 150 }
          ];
        } else {
          ElMessage.warning('暂无操作记录');
          dialogTableVisible.value = false;
        }
      } else {
        ElMessage.error('获取详情数据失败');
        dialogTableVisible.value = false;
      }
    } catch (error) {
      console.error('获取详情失败:', error);
      ElMessage.error('获取详情数据失败');
      dialogTableVisible.value = false;
    }
    return;
  }
  // 其他页面的默认处理
  form.value = { ...row };
  addOrEdit.value = "viewRow";
  title.value = `查看${currentTabConfig.value.label}`;
  copyForm.value = { ...row };
  if (activeTab.value === "equipmentRequisition") {
    equipmentRequisitionDialog.value = true;
  } else if (activeTab.value === "usageRecord") {
  if (activeTab.value === "usageRecord") {
    usageRecordDialog.value = true;
  } else {
    manaDialog.value = true;
@@ -371,8 +508,7 @@
// 设备领用弹窗提交处理
const onEquipmentRequisitionSubmit = (formData) => {
  console.log("设备领用提交数据:", formData);
  if (formData.equipmentStatus == 1) {
  if (formData.equipmentStatus == 2) {
    ElMessage.success("设备归还成功");
  } else {
    ElMessage.success("设备领用成功");