maven
10 小时以前 7ffa19f1fe3b37519e83ed1f86715154b13c00f3
src/views/production/components/ProductionDetailsTable.vue
@@ -1,5 +1,24 @@
<template>
  <el-table :data="tableData" :border="border" style="width: 100%">
    <el-table-column label="煤料类型" min-width="120">
      <template #default="{ row, $index }">
        <el-select
            clearable
            v-model="row.type"
            placeholder="请选择煤料类型"
            filterable
            :key="`coalId-select-${$index}-${typeList.length}`"
            :disabled="isViewMode"
        >
          <el-option
              v-for="(item, index) of typeList"
              :key="`option-${index}-${item.value}`"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </template>
    </el-table-column>
    <el-table-column label="煤种" min-width="120">
      <template #default="{ row, $index }">
        <el-select
@@ -9,6 +28,7 @@
            @change="(value) => handleCoalSelectChange(row, value)"
            filterable
            :key="`coalId-select-${$index}-${weekList.length}`"
            :disabled="isViewMode"
        >
          <el-option
              v-for="(item, index) of weekList"
@@ -26,6 +46,7 @@
            placeholder="请输入生产数量"
            type="number"
            @input="handleInput('productionQuantity', $index, $event)"
            :disabled="isViewMode"
        />
      </template>
    </el-table-column>
@@ -37,6 +58,7 @@
            placeholder="请输入人工成本"
            type="number"
            @input="handleInput('laborCost', $index, $event)"
            :disabled="isViewMode"
        >
          <template #suffix>
            <i style="font-style: normal">元</i>
@@ -47,11 +69,15 @@
    <el-table-column label="能耗成本" min-width="120">
      <template #default="{ row, $index }">
        <!-- 不能为负数 -->
        <el-input
            v-model="row.energyConsumptionCost"
            placeholder="请输入能耗成本"
            type="number"
            min="0"
            step="0.01"
            @input="handleInput('energyConsumptionCost', $index, $event)"
            :disabled="isViewMode"
        >
          <template #suffix>
            <i style="font-style: normal">元</i>
@@ -67,6 +93,7 @@
            placeholder="请输入设备折旧"
            type="number"
            @input="handleInput('equipmentDepreciation', $index, $event)"
            :disabled="isViewMode"
        >
          <template #suffix>
            <i style="font-style: normal">元</i>
@@ -82,6 +109,7 @@
            placeholder="请输入采购单价"
            type="number"
            @input="handleInput('purchasePrice', $index, $event)"
            :disabled="isViewMode"
        >
          <template #suffix>
            <i style="font-style: normal">元</i>
@@ -99,6 +127,7 @@
            type="number"
            :readonly="autoCalculate"
            @input="handleInput('totalCost', $index, $event)"
        >
          <template #suffix>
            <i style="font-style: normal">元</i>
@@ -115,6 +144,7 @@
            @change="(value) => handleUserSelectChange(row, value)"
            filterable
            :key="`producer-select-${$index}-${userList.length}`"
            :disabled="isViewMode"
        >
          <el-option
              v-for="(item, index) of userList"
@@ -126,10 +156,10 @@
      </template>
    </el-table-column>
    <el-table-column
        v-if="showOperations"
        label="操作"
        width="120"
        fixed="right"
        v-if="dialogType !== 'viewRow'"
    >
      <template #default="{ $index }">
        <el-button
@@ -148,10 +178,21 @@
<script setup name="ProductionDetailsTable">
import {ref, computed, watch, onMounted, nextTick} from "vue";
import {Delete} from "@element-plus/icons-vue";
import {ElMessage} from "element-plus";
import {getCoalFieldList} from "@/api/basicInformation/coalQualityMaintenance";
import {getCoalInfoList} from "@/api/production";
import {userListAll} from "@/api/publicApi";
const typeList = [
  {
    label: "成品",
    value: 1,
  },
  {
    label: "原料",
    value: 2,
  }
  ]
const props = defineProps({
  modelValue: {
    type: Array,
@@ -169,8 +210,12 @@
    type: Boolean,
    default: true,
  },
  dialogType:{
    type: String,
    default:'add'
  }
});
const isViewMode = computed(() => props.dialogType === "viewRow");
const emit = defineEmits(["update:modelValue", "input-change", "delete-row"]);
// 使用 v-model 进行双向绑定
@@ -185,6 +230,11 @@
// 处理输入变化
const handleInput = (field, index, value) => {
  // 确保输入值是数字或空字符串而且非负数
  if (!/^\d*\.?\d*$/.test(value) && value !== "") {
    ElMessage.error("请输入有效的数字");
    return;
  }
  const newData = [...tableData.value];
  newData[index][field] = value;
@@ -208,7 +258,7 @@
// 计算总成本
const calculateTotalCost = (row) => {
  const laborCost = parseFloat(row.laborCost) || 0;
  const energyCost = parseFloat(row.energyCost) || 0;
  const energyCost = parseFloat(row.energyConsumptionCost) || 0;
  const equipmentDepreciation = parseFloat(row.equipmentDepreciation) || 0;
  const purchasePrice = parseFloat(row.purchasePrice) || 0;
@@ -366,6 +416,7 @@
      purchasePrice: "",
      totalCost: "",
      producerId: "",
      type: 1,
      ...rowData,
    };
    tableData.value = [...tableData.value, defaultRow];