seatonwan9
2025-08-28 b877343496638d3c80b5e408a4af3a997182d311
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
     <el-tree-select
    ref="businessTypeIdRef"
    v-model="searchData.businessTypeIdCopy"
    :data="searchData.productBusinessCategory"
    node-key="id"
    placeholder="请选择产品业务类型"
    :props="businessTypeProps"
    clearable
    check-strictly
    :default-expand-all="true"
    :render-after-expand="false"
    style="width: 170px"
    @change="treeChange"
    />
</template>
<script setup lang="ts">
const emit = defineEmits(['treeChange'])
import productService from '@/api/zhongjian/productApi' // 接口文件
 
const searchData = reactive<any>({
  businessTypeFirstId:'',
  businessTypeId:'',
  businessTypeThirdId:'',
  businessTypeIdCopy:'',
  productBusinessCategory:[]
})
const businessTypeProps = ref({
  children: "children",
  label: "name",
  id: "id",
});
const businessTypeIdRef=ref()
const treeChange=()=>{
  searchData.businessTypeFirstId=''
  searchData.businessTypeId=''
  searchData.businessTypeThirdId=''
  if(searchData.businessTypeIdCopy){
    let businessTypeKey= businessTypeIdRef.value!.getCurrentNode()
    if(businessTypeKey){
      searchData.businessTypeFirstId=businessTypeKey.firstId
      searchData.businessTypeId=businessTypeKey.secondId
      searchData.businessTypeThirdId=businessTypeKey.thirdId
    }
  }
  emit('treeChange',{
    businessTypeFirstId: searchData.businessTypeFirstId,
    businessTypeId: searchData.businessTypeId,
    businessTypeThirdId: searchData.businessTypeThirdId,
  })
}
const getProductBusinessCategory=()=>{
    productService
    .getResourceCategory({
        parentCode: 'ProductBusinessType',
    })
    .then((res: any) => {
        res.data.forEach((item:any)=>{
           item.firstId=item.id
           item.firstName=item.name
           item.secondId=''
           item.secondName=''
           item.thirdId=''
           item.thirdName=''
           if(item.children&&item.children.length>0){
            item.children.forEach((sub:any)=>{
                sub.firstId=item.id
                sub.firstName=item.name
                sub.secondId=sub.id
                sub.secondName=sub.name
                sub.thirdId=''
                sub.thirdName=''
                if(sub.children&&sub.children.length>0){
                    sub.children.forEach((last:any)=>{
                        last.firstId=item.id
                        last.firstName=item.name
                        last.secondId=sub.id
                        last.secondName=sub.name
                        last.thirdId=last.id
                        last.thirdName=last.name
                    })
                }
            })
           }
        })
      searchData.productBusinessCategory = res.data
    })
}
const clearData=()=>{
    searchData.businessTypeFirstId=''
    searchData.businessTypeId=''
    searchData.businessTypeThirdId=''
    searchData.businessTypeIdCopy=''
}
defineExpose({
  clearData
})
onMounted(()=>{
    getProductBusinessCategory()
})
</script>