<template>
    <div class='app-container'>
        <div ref="echartsRef" id="main" style="width: 100%;height:400px;"></div>
    </div>
</template>

<script setup lang='ts'>
import { onMounted } from 'vue'
import { statGoods } from '@/services/api/statistics/index'
import * as echarts from 'echarts';

onMounted(() => {
    let myChart = echarts.init(document.getElementById('main') as any);
    var option: any;
    var xData: any = []
    var yData: any = []
    var yData1: any = []
    var yData2: any = []
    statGoods().then((res: any) => {
        if (res.code === 200) {
            res.data.rows.forEach((item: any) => {
                xData.push(item.day)
                yData.push(item.amount)
                yData1.push(item.orders)
                yData2.push(item.products)
            })
            console.log(xData, yData);
        }
    })
    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        xAxis: {
            type: 'category',
            data: xData
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                data: yData,
                type: 'line',
                name: '下单货品总额',
                label: {
                    show: true,
                    position: 'inside'
                },
            },
            {
                data: yData1,
                type: 'line',
                name: '订单量',
                label: {
                    show: true,
                    position: 'inside'
                },
                show: false
            },
            {
                data: yData2,
                type: 'line',
                name: '下单货品总额',
                label: {
                    show: true,
                    position: 'inside'
                },
                show: false
            }
        ],
        legend: {
            show: true
        }
    };

    setTimeout(() => {
        option && myChart.setOption(option);
    }, 50)
})

</script>
 
<style lang = "scss" scoped>
</style>