gaoluyang
5 小时以前 07f9f8657d057a38792c3822acc9b08d83478967
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!-- 在你的主页面中 -->
<template>
  <div class="app-container">
    <div v-loading="loading" element-loading-text="加载中..." style="min-height: 80vh;">
    <el-tabs v-model="activeTab" @tab-change="handleTabChange" v-if="!loading">
      <el-tab-pane v-for="tab in tabs"
                   :label="tab.productName"
                   :name="tab.id"
                   :key="tab.id">
        <Record v-bind="{ type: tab.type, topParentProductId: activeTab }" v-if="tab.id === activeTab" />
      </el-tab-pane>
    </el-tabs>
    </div>
  </div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue';
import { productTreeList } from "@/api/basicData/product.js";
import Record from "@/views/inventoryManagement/dispatchLog/Record.vue";
const activeTab = ref(null)
const tabs = ref([])
const loading = ref(false)
 
const resolveTypeByName = (name) => {
  return String(name || "").includes("不合格") ? "1" : "0";
};
 
const handleTabChange = (tabName) => {
  activeTab.value = tabName;
}
 
const fetchProducts = async () => {
  loading.value = true;
  try {
    const res = await productTreeList();
    tabs.value = res
      .filter((item) => item.parentId === null)
      .map(({ id, productName }) => ({
        id,
        productName,
        type: resolveTypeByName(productName),
      }));
    if (tabs.value.length > 0) {
      activeTab.value = tabs.value[0].id;
    }
  } finally {
    loading.value = false;
  }
}
 
onMounted(() => {
  fetchProducts();
})
</script>