<template>
    <el-card style="width: 49.9%;">
        <template #header>
            <div class="card-header">
                <span>项目回款</span>
            </div>
        </template>
        <div style="height:40px">
            <el-date-picker v-model="year" @change='getCustom' value-format="YYYY" type="year" style="float:right"
                :placeholder="year" />
        </div>

        <div style="display: flex;justify-content: space-around;">
            <router-link :to="{
                path: item.url,
                query: item.query ? { year } : null
            }" v-for=" item in customList" :key="item" class="header-btn">
                <div>
                    <div>{{ item.value }}</div>
                    <div>{{ item.name }}</div>
                </div>
            </router-link>
        </div>
        <div id="ProjectPayment" class="chart" v-if="showChart"></div>
    </el-card>
</template>
<script setup>
import * as echarts from 'echarts';
import { apistatisticsprojectRefund } from '@/api/statistics'

const year = ref(new Date().getFullYear())
const showChart = ref(true)



const customList = reactive([
    {
        name: "年度开票金额",
        value: 0,
        url: "/construction/finance/Collection/InvoicingRequests"

    },
    {
        name: "年度回款金额",
        value: 0,
        url: "/construction/finance/Collection/RecordsPayment"

    },
    {
        name: "年度未回款金额",
        value: 0,
        url: "/construction/finance/Collection/refund"

    },
    {
        name: "年度回款计划金额",
        value: 0,
        url: "/construction/finance/Collection/Remittance"

    },


])

const labelOption = {
    show: true,
    rich: {
        name: {}
    }
};

const initChart = (id, opt) => {
    var chartDom = document.getElementById(id);
    var myChart = echarts.init(chartDom);
    myChart.setOption(opt);
}


const getCustom = async () => {
    showChart.value = false
    let res = await apistatisticsprojectRefund({ year: year.value })
    showChart.value = true
    await nextTick()
    var option4 = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        legend: {
            data: [res.invoice_series.name, res.refund_plan_series.name, res.refund_series
                .name, res.not_refund_series.name,]
        },
        toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',

        },
        xAxis: [
            {
                type: 'category',
                axisTick: { show: false },
                data: res.column
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: res.invoice_series.name,
                type: 'bar',
                barGap: 0,
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: res.invoice_series.data,
                itemStyle: {
                    normal: {
                        label: {
                        }
                    }
                }
            },
            {
                name: res.refund_plan_series.name,
                type: 'bar',
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: res.refund_plan_series.data,
                itemStyle: {
                    normal: {
                        label: {
                        }
                    }
                }
            },
            {
                name: res.refund_series.name,
                type: 'bar',
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: res.refund_series.data,
                itemStyle: {
                    normal: {
                        label: {
                        }
                    }
                }
            },
            {
                name: res.not_refund_series.name,
                type: 'bar',
                label: labelOption,
                emphasis: {
                    focus: 'series'
                },
                data: res.not_refund_series.data,
                itemStyle: {
                    normal: {
                        label: {
                        }
                    }
                }
            },
        ]
    };

    initChart("ProjectPayment", option4)
    customList[0].value = res.year_invoicing_amount
    customList[1].value = res.year_refund_amount
    customList[2].value = res.year_not_refund_amount
    customList[3].value = res.year_refund_plan_amount
}
getCustom()
</script>
<style lang="scss" scoped>
.chart {
    width: 100%;
    height: 300px;
}

.header-btn {
    text-align: center;
    cursor: pointer;
    padding: 0px 10px;

}

.header-btn:active {
    background-color: #EDEFFF;
}
</style>