gaoluyang
3 天以前 ecb800b7af57ecf5d14c41a6cf54a16c3be61094
src/views/production/components/ProductionDetailsTable.vue
@@ -4,11 +4,11 @@
      <template #default="{ row, $index }">
        <el-select 
          clearable 
          :model-value="getCoalNameById(row.coal) || row.coal"
          :model-value="getCoalNameById(row.coalId) || row.coalId"
          placeholder="请选择煤种"
          @change="(value) => handleCoalSelectChange(row, value)"
          filterable
          :key="`coal-select-${$index}-${weekList.length}`"
          :key="`coalId-select-${$index}-${weekList.length}`"
        >
          <el-option
            v-for="(item, index) of weekList"
@@ -149,6 +149,7 @@
import { ref, computed, watch, onMounted, nextTick } from "vue";
import { Delete } from "@element-plus/icons-vue";
import { getCoalFieldList } from "@/api/basicInformation/coalQualityMaintenance";
import { getCoalInfoList } from "@/api/production";
import { userListAll } from "@/api/publicApi";
const props = defineProps({
  modelValue: {
@@ -233,16 +234,16 @@
  // 根据选择的名称找到对应的ID
  const coalItem = weekList.value.find(item => item.value === selectedName);
  if (coalItem) {
    row.coal = coalItem.key; // 设置为ID
    row.coalId = coalItem.key; // 设置为ID
  } else {
    row.coal = ''; // 如果没找到,清空
    row.coalId = ''; // 如果没找到,清空
  }
};
// 根据ID获取煤种名称(用于显示)
const getCoalNameById = (id) => {
  const coal = weekList.value.find(item => item.key == id);
  return coal ? coal.value : id;
  const coalId = weekList.value.find(item => item.key == id);
  return coalId ? coalId.value : id;
};
const weekList = ref([]);
@@ -268,10 +269,11 @@
}, { deep: true });
onMounted(async()=>{
  let res = await getCoalFieldList()
  let res = await getCoalInfoList()
  console.log(res);
  res.data.forEach(item => {
    let obj = {};
    obj.value = item.fieldName;
    obj.value = item.coal;
    obj.key = item.id;
    weekList.value.push(obj); 
  });
@@ -292,7 +294,7 @@
  let res = await getCoalFieldList();
  if (res.code === 200) {
    dropdownList.value = res.data.map((item) => ({
      value: item.fieldName,
      value: item.coal,
      key: item.id,
    }));
  } else {
@@ -348,11 +350,12 @@
defineExpose({
  calculateTotalCost,
  getDropdownData,
  getUserList,
  getCoalNameById, // 暴露获取煤种名称的方法
  weekList, // 暴露weekList让父组件可以访问
  addRow: (rowData = {}) => {
    const defaultRow = {
      coal: "",
      coalId: "",
      calorificValue: "",
      productionQuantity: "",
      laborCost: "",