diff --git a/src/components/inventory/StockListTable.vue b/src/components/inventory/StockListTable.vue index c515cd99..a68fd1ae 100644 --- a/src/components/inventory/StockListTable.vue +++ b/src/components/inventory/StockListTable.vue @@ -14,7 +14,7 @@ @@ -40,7 +40,7 @@ import { ref, onMounted, watch } from 'vue'; import { InventoryApi } from '../../api/inventory'; import { ElMessage } from 'element-plus'; import { formatRFC3339, formatWeight } from '../../utils/format'; -import { StockLogSourceType } from '../../enums'; // 导入 StockLogSourceType +import { getStockLogSourceTypeLabel } from '../../enums'; // 导入 getStockLogSourceTypeLabel export default { name: 'StockListTable', @@ -130,7 +130,7 @@ export default { formatRFC3339, formatWeight, handleAdjust, - StockLogSourceType, // 暴露 StockLogSourceType 给模板 + getStockLogSourceTypeLabel, // 暴露辅助函数给模板 }; }, }; diff --git a/src/enums.js b/src/enums.js index 947a9600..2bc7b1ea 100644 --- a/src/enums.js +++ b/src/enums.js @@ -79,6 +79,31 @@ export const StockLogSourceType = { FERMENT_END: '发酵入库', // 发酵料产出,作为新原料计入库存 }; +/** + * 根据库存变动来源的键或值获取其对应的中文标签。 + * @param {string} sourceTypeKeyOrValue - 库存变动来源的键 (如 "PURCHASE") 或值 (如 "采购入库")。 + * @returns {string} 对应的中文标签,如果未找到则返回 '--'。 + */ +export function getStockLogSourceTypeLabel(sourceTypeKeyOrValue) { + if (!sourceTypeKeyOrValue) { + return '--'; + } + + // 尝试直接通过键查找 + if (StockLogSourceType[sourceTypeKeyOrValue]) { + return StockLogSourceType[sourceTypeKeyOrValue]; + } + + // 尝试通过值反向查找 + for (const key in StockLogSourceType) { + if (StockLogSourceType[key] === sourceTypeKeyOrValue) { + return StockLogSourceType[key]; + } + } + + return '--'; +} + /** * 用药原因 * @enum {string}