zhang_12370
4 天以前 e986cee1c804ecdf6d03c080ce9a8bb187f724a4
src/views/production/components/ProductionDialog.vue
@@ -1,12 +1,12 @@
<template>
  <el-dialog
      v-model="dialogVisible"
      :title="dialogType === 'add' ? '新增生产加工' : '编辑生产加工'"
      :title="dialogType === 'add' ? '新增生产加工' : dialogType === 'viewRow' ? '查看生产加工' : '编辑生产加工'"
      width="1200px"
      :close-on-click-modal="false"
      @close="handleClose"
  >
    <el-row :gutter="10" style="margin-bottom: 10px">
    <el-row :gutter="10" style="margin-bottom: 10px" v-if="dialogType !== 'viewRow'">
      <el-col :span="3">
        <el-button type="primary" @click="handlData"
        >
@@ -40,20 +40,21 @@
    </el-row>
    <ETableModify
        :columns="columns"
        :showOperations="false"
        :showOperations="dialogType !== 'viewRow'"
        height="200"
        @cell-edit="handleCellEdit"
        :tableData="tableData"
        :showOverflowTooltip="false"
        @row-click="handleRowClick"
        :editableColumns="['usedQuantity']"
        :editableColumns="dialogType === 'viewRow' ? [] : ['usedQuantity']"
        :editableCells="dialogType !== 'viewRow'"
        @delete="handleRemoveItem"
    />
    <div class="empty-table">
      <h1>生产明细</h1>
      <el-row :gutter="10">
        <el-col :span="2">
          <el-button type="primary" @click="addNewRow">
          <el-button type="primary" @click="addNewRow" v-if="dialogType !== 'viewRow'">
            <el-icon>
              <Plus/>
            </el-icon>
@@ -72,10 +73,11 @@
      <ProductionDetailsTable
          v-model="detailsTableData"
          :border="false"
          :show-operations="true"
          :show-operations="dialogType !== 'viewRow'"
          :auto-calculate="true"
          @input-change="handleDetailsChange"
          @delete-row="handleDeleteRow"
          :dialogType="dialogType"
      />
    </div>
@@ -83,14 +85,17 @@
      <div class="dialog-footer">
        <el-button
            @click="handleClose"
            v-if="dialogType === 'add' || dialogType === 'edit'"
        >取 消
        >{{ dialogType === 'viewRow' ? '关 闭' : '取 消' }}
        </el-button
        >
        <!-- <el-button @click="handleReset" v-if="dialogType === 'edit'"
          >重 置</el-button
        > -->
        <el-button type="primary" :loading="loading" @click="handleSubmit"
        <el-button
            v-if="dialogType !== 'viewRow'"
            type="primary"
            :loading="loading"
            @click="handleSubmit"
        >确 定
        </el-button
        >
@@ -160,6 +165,7 @@
  getCoalInfoList,
  deleteProductionInventory,
} from "@/api/production/index.js";
import { getSupplyList } from "@/api/procureMent/index.js"
import {validateFormData, validateNumber, deepClone, createDefaultProductionRow} from "@/utils/production";
import {useCoalData} from "./useCoalData";
import useUserStore from "@/store/modules/user";
@@ -194,10 +200,10 @@
const currentRow = ref(null);
const copyForm = ref(null);
const coalList = ref([])
const supplierList = ref({});
const supplierList = ref([]);
// 表格列配置
const columns = [
  {prop: "coalId", label: "煤种", minwidth: 60,slot:false,
  {prop: "coalId", label: "煤种", minwidth: 60,
    formatter: (row) => {
      return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
    }
@@ -213,15 +219,8 @@
];
const formalDatabaseColumns = ref([
  {prop: "supplierName", label: "供应商名称", minwidth: 150
  // ,formatter: (row) => {
  //     console.log(row);
  //     return supplierList.value[row.supplierId] || "--";
  //   }
  },
  {prop: "coalId", label: "煤种", minwidth: 60,
    formatter: (row) => {
      // return coalList.value[row.coalId].coal || "--";
      return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
    }
  },
@@ -243,28 +242,51 @@
  currentRow.value = row;
};
// 获取基础数据(煤种和供应商)
const loadBasicData = async () => {
  try {
    const [coalResponse, supplierResponse] = await Promise.all([
      getCoalInfoList(),
      getSupplyList()
    ]);
    coalList.value = coalResponse.data || [];
    supplierList.value = supplierResponse.data || [];
  } catch (error) {
    ElMessage.error("获取基础数据失败");
  }
};
// 获取配置数据
const handlData = async () => {
  innerVisible.value = true;
  let getSupplier = await getOfficialAll();
  let getCoalName = await getCoalInfoList();
  coalList.value = getCoalName.data || [];
  supplierList.value = getSupplier.data || [];
  if (getSupplier.code === 200) {
    formalDatabaseData.value = getSupplier.data;
    const existingOfficialIds = tableData.value
        .map((item) => item.officialId)
        .filter((id) => id);
    selectedIds.value = existingOfficialIds;
    debugIdMatching();
    nextTick(() => {
      setTimeout(() => {
        if (etableRef.value && existingOfficialIds.length > 0) {
          etableRef.value.setDefaultSelection();
        }
      }, 100);
    });
  } else {
  // 确保基础数据已加载
  if (coalList.value.length === 0 || supplierList.value.length === 0) {
    await loadBasicData();
  }
  try {
    const OfficialAll = await getOfficialAll();
    if (OfficialAll.code === 200) {
      formalDatabaseData.value = OfficialAll.data;
      const existingOfficialIds = tableData.value
          .map((item) => item.officialId)
          .filter((id) => id);
      selectedIds.value = existingOfficialIds;
      debugIdMatching();
      nextTick(() => {
        setTimeout(() => {
          if (etableRef.value && existingOfficialIds.length > 0) {
            etableRef.value.setDefaultSelection();
          }
        }, 100);
      });
    } else {
      ElMessage.error("获取配置数据失败");
    }
  } catch (error) {
    ElMessage.error("获取配置数据失败");
  }
};
@@ -291,22 +313,28 @@
};
// 初始化和编辑初始化
const Initialization = () => {
const Initialization = async () => {
  tableData.value = [];
  detailsTableData.value = [];
  copyForm.value = null;
  dialogType.value = "add";
  // 加载基础数据
  await loadBasicData();
};
const editInitialization = (data) => {
const editInitialization = async (type, data) => {
  copyForm.value = deepClone(data);
  tableData.value = data.productionInventoryList || [];
  detailsTableData.value = data.productionList || [];
  dialogType.value = "edit";
  dialogType.value = type;
  const existingOfficialIds = tableData.value
      .map((item) => item.officialId)
      .filter((id) => id);
  selectedIds.value = existingOfficialIds;
  // 加载基础数据
  await loadBasicData();
};
// 监听对话框状态,在打开时设置选中状态
watch(innerVisible, (newVal) => {
@@ -396,7 +424,7 @@
  for (let i = 0; i < tableData.value.length; i++) {
    const element = tableData.value[i];
    if (element.usedQuantity == 0 || element.usedQuantity === null) {
      ElMessage.warning(`请填写使用数量: ${element.coal}`);
      ElMessage.warning(`请填写生产加工煤种的使用数量`);
      return;
    }
  }
@@ -452,12 +480,13 @@
  }
};
// 获取用户信息
// 获取用户信息并加载基础数据
onMounted(async () => {
  try {
    userInfo = await userStore.getInfo();
    await loadBasicData();
  } catch (error) {
    ElMessage.error("获取用户信息失败,请重试");
    ElMessage.error("初始化失败,请重试");
  }
});