diff --git a/src/views/erp/stock/record/index.vue b/src/views/erp/stock/record/index.vue index 0c5728a0..870711f1 100644 --- a/src/views/erp/stock/record/index.vue +++ b/src/views/erp/stock/record/index.vue @@ -104,12 +104,7 @@ - - - - - - + ([]) // 产品列表 const warehouseList = ref([]) // 仓库列表 +const categoryTabs = ref([]) /** 查询列表 */ const getList = async () => { @@ -282,7 +279,7 @@ onActivated(() => { }) onMounted(async () => { - queryParams.categoryId = 2 + await loadCategoryTabs() await getList() // 加载产品、仓库列表 productList.value = await ProductApi.getProductSimpleList() @@ -290,9 +287,24 @@ onMounted(async () => { }) /** tab 切换 */ -let activeName = '2' +const activeName = ref('') const handleTabClick = (tab: TabsPaneContext) => { - queryParams.categoryId = tab.paneName + queryParams.categoryId = tab.paneName ? Number(tab.paneName) : undefined handleQuery() } + +const loadCategoryTabs = async () => { + try { + const data = await ProductCategoryApi.getProductCategoryList({}) + const roots = (data || []).filter((item: any) => item && (item.parentId === 0 || item.parentId === null || item.parentId === undefined)) + categoryTabs.value = roots.sort((a: any, b: any) => Number(a?.sort ?? 0) - Number(b?.sort ?? 0)) + const defaultId = categoryTabs.value.find((v) => String(v.id) === '2')?.id ?? categoryTabs.value[0]?.id + queryParams.categoryId = defaultId + activeName.value = defaultId !== undefined && defaultId !== null ? String(defaultId) : '' + } catch { + categoryTabs.value = [] + queryParams.categoryId = undefined + activeName.value = '' + } +}