| | |
| | | <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" |
| | |
| | | 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: { |
| | |
| | | // 根据选择的名称找到对应的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([]); |
| | |
| | | }, { 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); |
| | | }); |
| | |
| | | let res = await getCoalFieldList(); |
| | | if (res.code === 200) { |
| | | dropdownList.value = res.data.map((item) => ({ |
| | | value: item.fieldName, |
| | | value: item.coal, |
| | | key: item.id, |
| | | })); |
| | | } else { |
| | |
| | | defineExpose({ |
| | | calculateTotalCost, |
| | | getDropdownData, |
| | | getUserList, |
| | | getCoalNameById, // 暴露获取煤种名称的方法 |
| | | weekList, // 暴露weekList让父组件可以访问 |
| | | addRow: (rowData = {}) => { |
| | | const defaultRow = { |
| | | coal: "", |
| | | coalId: "", |
| | | calorificValue: "", |
| | | productionQuantity: "", |
| | | laborCost: "", |