| | |
| | | * 提供煤种数据的获取、缓存、转换等功能 |
| | | */ |
| | | import { ref, computed, watch } from 'vue'; |
| | | import { getCoalFieldList } from '@/api/basicInformation/coalQualityMaintenance'; |
| | | import { getCoalInfoList } from "@/api/production"; |
| | | import { ElMessage } from 'element-plus'; |
| | | |
| | | // 全局煤种数据缓存 |
| | |
| | | |
| | | isLoading.value = true; |
| | | try { |
| | | const res = await getCoalFieldList(); |
| | | const res = await getCoalInfoList(); |
| | | if (res.code === 200) { |
| | | coalData.value = res.data; |
| | | isLoaded.value = true; |
| | |
| | | const getCoalNameById = (id) => { |
| | | if (!id || coalData.value.length === 0) return id; |
| | | const coal = coalData.value.find(item => item.id == id); |
| | | return coal ? coal.fieldName : id; |
| | | return coal ? coal.coal : id; |
| | | }; |
| | | |
| | | // 根据名称获取煤种ID |
| | | const getCoalIdByName = (name) => { |
| | | if (!name || coalData.value.length === 0) return ''; |
| | | const coal = coalData.value.find(item => item.fieldName === name); |
| | | const coal = coalData.value.find(item => item.coal === name); |
| | | return coal ? coal.id : ''; |
| | | }; |
| | | |
| | | // 生成下拉选项 |
| | | const coalOptions = computed(() => { |
| | | return coalData.value.map(item => ({ |
| | | label: item.fieldName, |
| | | value: item.fieldName, |
| | | label: item.coal, |
| | | value: item.coal, |
| | | key: item.id |
| | | })); |
| | | }); |
| | |
| | | const coalMap = computed(() => { |
| | | const map = {}; |
| | | coalData.value.forEach(item => { |
| | | map[item.id] = item.fieldName; |
| | | map[item.id] = item.coal; |
| | | }); |
| | | return map; |
| | | }); |