<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>
|