<template>
    <!-- <div class="layout-container-main" id="jcsb">
        <div class="item" id="box1">
            <div class="layout-container-main-top" style="display: flex;justify-content: space-between;">
                <div class="top-left">
                    <div class="line"></div>
                    <span>ECPM趋势</span>
                </div>
                <div class="main"></div>
            </div>
            <div class="main-echart" style="height: 55vh;" ref="chartRef">
                <Chart :option="options" />
            </div>
        </div>
    </div> -->
    <div class="layout-container-main" id="jcsb">

        <div class="item" id="box1">
            <div class="layout-container-main-top" style="display: flex;justify-content: space-between;">
                <div class="top-left">
                    <div class="line"></div>
                    <span>收益统计</span>
                </div>
                <div class="main"></div>
            </div>
            <div class="main-echart" ref="chartRef">
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column prop="platform" label="统计" align="center" />
                    <el-table-column prop="today" label="今日" align="center" />
                    <el-table-column prop="yesterday" label="昨日" align="center" />
                    <el-table-column prop="month" label="本月" align="center" />
                </el-table>
            </div>
        </div>
    </div>
</template>

<script setup>
import { defineComponent, reactive, ref, onMounted } from 'vue'
import Chart from '@/components/charts/index.vue'
//穿山甲、优量汇、快手、Sigmob、百度

const xAxisList = [
    '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00',
    '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00',
    '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'
];

const seriesData = [450, 200, 300, 520, 800, 760, 700, 680, 700, 650, 690, 710, 450, 200, 300, 520, 800, 760, 700, 680, 700, 650, 690, 710];
// 穿山甲数据（随机生成，保持原40-80范围）
const seriesData1 = [42, 25, 33, 55, 76, 68, 72, 63, 71, 65, 62, 69, 45, 22, 31, 53, 79, 73, 68, 64, 72, 61, 67, 70];

// 优量汇数据（模拟中型广告平台，范围200-500）
const seriesData2 = (() => {
    const base = [380, 210, 290, 470, 490, 420, 450, 430, 460, 410, 440, 480];
    return [...base, ...base.map(v => v * 0.9)]; // 下午数据略降
})();

// 快手数据（模拟短视频平台，高峰在晚间）
const seriesData3 = [
    320, 180, 220, 300, 350,
    420, 550, 680, 720, 650, // 早高峰
    600, 580, 320, 280, 350,
    480, 620, 750, 820, 880, // 晚高峰
    760, 680, 550, 450
];

// Sigmob数据（模拟国际广告平台，较平稳）
const seriesData4 = Array(24).fill(0).map(
    (_, i) => 350 + Math.sin(i / 4) * 100 + (i > 12 ? -20 : 0) + Math.random() * 30
).map(v => Math.round(v));

// 百度数据（模拟搜索广告，白天稳定）
const seriesData5 = xAxisList.map((_, i) =>
    i < 8 ? 280 + i * 20 :       // 清晨上升
        i < 18 ? 420 + (i % 3) * 15 :  // 白天稳定
            400 - (i - 18) * 25            // 夜间下降
);


const options = {
    /* title: {
        text: "单位：个",
        textStyle: {
            color: "#808080",
            fontSize: 12
        },
        left: "20",
        top: "20"
    }, */
    tooltip: {
        trigger: 'axis', // 触发类型为坐标轴
        axisPointer: {
            type: 'cross' // 指示器类型为十字准星
        },
        formatter: function (params) {
            // 自定义提示框内容
            let result = params[0].axisValue + '<br>'; // 显示时间点
            params.forEach(function (item) {
                // 为每个系列添加数据行
                result += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'
                    + item.color + '"></span>'
                    + item.seriesName + ': ' + item.value + '<br>';
            });
            return result;
        }
    },
    legend: {
        data: ['平均ecpm', '穿山甲', '优量汇', '快手', 'Sigmob', '百度'],
        top: 'top',
        textStyle: {
            color: '#808080'
        }
    },
    xAxis: {
        type: 'category',
        data: xAxisList,
        axisLabel: {
            color: "#808080",
            fontSize: 12
        },
        axisLine: {
            show: false,
        },
        axisTick: {
            show: false
        },
        splitLine: {
            show: false
        },
    },
    yAxis: {
        min: 0,
        nameTextStyle: {
            color: '#808080',
            fontSize: 12,
        },
        axisLabel: {
            color: "#808080",
            fontSize: 12
        },
        axisLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        splitLine: {
            show: true,
            lineStyle: {
                color: 'rgba(0,0,0,0.15)',
            }
        }
    },
    series: [
        {
            type: 'line',
            name: '平均ecpm',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#70e3cd'
            },
            lineStyle: {
                color: '#70e3cd',
                width: 2,
            },
            data: seriesData,
        },
        {
            type: 'line',
            name: '穿山甲',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#add7f6'
            },
            lineStyle: {
                color: '#add7f6',
                width: 2,
            },
            data: seriesData1,
        },
        {
            type: 'line',
            name: '优量汇',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#f7a8b8'
            },
            lineStyle: {
                color: '#f7a8b8',
                width: 2,
            },
            data: seriesData2,
        },
        {
            type: 'line',
            name: '快手',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#ffcc5c'
            },
            lineStyle: {
                color: '#ffcc5c',
                width: 2,
            },
            data: seriesData3,
        },
        {
            type: 'line',
            name: 'Sigmob',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#88d8b0'
            },
            lineStyle: {
                color: '#88d8b0',
                width: 2,
            },
            data: seriesData4,
        },
        {
            type: 'line',
            name: '百度',
            symbolSize: 6,
            z: 1,
            label: {
                show: false // Hide labels
            },
            itemStyle: {
                color: '#9966cc'
            },
            lineStyle: {
                color: '#9966cc',
                width: 2,
            },
            data: seriesData5,
        }
    ]
};




// 收益统计表格数据格式
const tableData = ref([
    {
        platform: '穿山甲',
        today: '0.00',
        yesterday: '0.00',
        month: '0.00'
    },
    {
        platform: '优量汇',
        today: '10',
        yesterday: '9.70',
        month: '53.43'
    },
    {
        platform: '快手',
        today: '18',
        yesterday: '16.43',
        month: '16.03'
    },
    {
        platform: 'Sigmob',
        today: '0.00',
        yesterday: '0.00',
        month: '0.00'
    },
    {
        platform: '百度',
        today: '0.00',
        yesterday: '0.00',
        month: '0.00'
    }
]);
</script>

<style lang="scss" scoped>
.layout-container-main {
    margin-top: 10px;
    display: flex;
    /* margin: 0 1.25rem; */
    flex-wrap: wrap;
    justify-content: space-between;

    .item {
        width: 100%;
        /* width: 40vw; */
        display: flex;
        flex-direction: column;
        padding: 1.13rem 1.31rem;
        margin-bottom: 1.25rem;
        /* height: 26.94rem; */
        border-radius: 0.5rem;
        background: #fff;
        box-shadow: 0 0 0.13rem #00000029;

        .layout-container-main-top {
            height: 6vh;

            .top-left {
                display: flex;

                .line {
                    width: 0.25rem;
                    height: 1.56rem;
                    border-radius: 0.13rem;
                    background: #fdb818;
                }

                span {
                    margin: 0 1rem;
                    font-family: "PingFang SC SNaNremibold";
                    font-weight: 600;
                    font-size: 1.13rem;

                    color: #333;
                }

                .text {
                    display: inline-block;
                    /* // margin: 0 0.63rem; */
                    width: 3.63rem;
                    font-weight: 400;
                    height: 1.88rem;
                    line-height: 1.88rem;
                    border-radius: 0.25rem;
                    background: transparent;
                    border: 0.03rem solid #999;
                    font-size: 0.88rem;
                    text-align: center;
                    color: #999;
                    cursor: pointer;
                }

                .active {
                    border-radius: 0.25rem;
                    background: #fdb818;
                    color: #fff;
                    border: 0.03rem solid #fff;
                }
            }
        }

        .main-echart {
            width: 100%;
            /* height: 55vh; */
            /* background-color: red; */
        }
    }
}


.stats-table {
    margin: 20px;
    width: 100vw;
}

:deep(.el-table__header th) {
    background-color: #f5f7fa;
    font-weight: bold;
}
</style>