<template>
    <sanctions-situation :enterprise-info="enterpriseInfo" :line-data="lineData"></sanctions-situation>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';

import { getNetProfitList, getPersonnelList, getRevenueList } from '@/api/companyPages';
import SanctionsSituation, { LineDataItem } from './SanctionsSituation.vue';
import { l } from 'vite/dist/node/types.d-aGj9QkWt';


// 定义组件属性
const props = defineProps({
    enterpriseInfo: {
        type: Object,
        default: {}
    }
});

const lineData = ref<LineDataItem[]>([])

onMounted(async () => {
    await intData()
})
async function intData() {
    let { data: revenue } = await getRevenueList(props.enterpriseInfo.id)
    revenue = revenue?.map(item => ({
        time: new Date(item.year, 1, 1),
        value: item.value,
        type: '营收',
        unit: item.unit ?? '亿元'
    })) ?? []
    let { data: netProfit } = await getNetProfitList(props.enterpriseInfo.id)
    netProfit = netProfit?.map(item => ({
        time: new Date(item.year, 1, 1),
        value: item.value,
        type: '净利润',
        unit: item.unit ?? '亿元'
    })) ?? []
    let { data: personnel } = await getPersonnelList(props.enterpriseInfo.id)
    personnel = personnel?.map(item => ({
        time: new Date(item.year, 1, 1),
        value: item.value,
        type: '人员',
        unit: item.unit ?? '亿元'
    })) ?? []

    lineData.value = [...revenue, ...netProfit, ...personnel]
}
</script>