<script setup>
//数据来源详情
import {ref,watch} from 'vue'
import apiChart from '@/api/chart'
const props = defineProps({
    show:{
        type:Boolean,
        default:false
    },
    EdbInfoId:{
        type:Number,
        default:0
    },
    UniqueCode: {
        type:Number,
        default: ''
    }
})

watch(()=>props.show,()=>{
    if(props.show){
        getEdbInfo()
    }
},{immediate:true})

const edbSourceData = ref([])
async function getEdbInfo(){
    const res = await apiChart.getEdbCreateHistory({
        UniqueCode:props.UniqueCode
    })
    if(res.Ret!==200) return 
    edbSourceData.value = flatTreeData([res.Data]||[]).reverse()
}
function flatTreeData(tree){
    let arr = []
    let concatData=[]
    for(const item of tree){
        const {EdbName,RuleTitle} = item
        concatData.push({EdbName:EdbName||'',RuleTitle:RuleTitle||''})
        if(item.Child&&item.Child.length){
            arr = arr.concat(flatTreeData(item.Child))
        }
    }
    arr.push(concatData)
    return arr
}
</script>

<template>
    <div class="source-detail-wrap">
        <div class="top-box">
            <span class="title"> 数据来源</span>
        </div>
        <div class="source-arr-wrap">
            <div class="source-item" v-for="(arr,index) in edbSourceData">
                <template v-for="item in arr">
                    <span class="title">{{item.EdbName}}</span>
                    <span class="text">{{item.RuleTitle}}</span>
                </template>
                
                <div class="line" v-if="index!==edbSourceData.length-1"></div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.source-detail-wrap{
    .top-box{
        padding: 32px $page-padding;
        border-bottom: 1px solid $border-color;
        .title{
            font-size: 32px;
            font-weight: 600;
        }
    }

    .source-arr-wrap{
        display: flex;
        flex-direction: column;
        padding:40px 80px;
        gap:40px;
        max-height: 600px;
        overflow-y:scroll;
        .source-item{
            position: relative;
            .text{
                display: block;
                margin: 8px 0;
                font-size: 12px;
                color: #00000066;;
            }
            .line{
                position:absolute;
                left:-33px;
                top:36px;
                width:1px;
                height:100%;
                background-color: $theme-color;
            }
            &::after{
                content:'';
                position:absolute;
                top:0;
                left:-40px;
                background-color: $theme-color;
                width:16px;
                height:16px;
                border-radius: 50%;
                top:8px;
            }
        }
    }
    @media screen and (min-width:$media-width){
        .top-box{
            padding: 16px;
            .title{
                font-size: 18px;
            }
        }

        .source-arr-wrap{
            padding:20px 40px;
            gap:20px;
            max-height: 300px;
            .source-item{
                .text{
                    margin: 8px 0;
                    font-size: 12px;
                }
                .line{
                    position:absolute;
                    left:-17px;
                    top:18px;
                    width:1px;
                    height:100%;
                    background-color: $theme-color;
                }
                &::after{
                    left: -20px;
                    width: 8px;
                    height: 8px;
                    top:4px;
                }
            }
        }
    }
}
</style>
