<!--
 * @Author: PoJun
 * @Date: 2023-12-19 14:57:48
 * @LastEditors: PoJun
 * @LastEditTime: 2024-01-04 17:34:18
 * @Message: 柱形图
-->
<template>
    <view class="data-charts">
        <view class="uv-font-md uv-weight-700 uv-m-25">产品-供应商数量</view>
        <qiun-data-charts type="column" :opts="opts" :chartData="chartData" />
    </view>
</template>

<script>
export default {
    data() {
        return {
            chartData: {},
            opts: {
                padding: [15, 15, 5, 15],
                fontSize: 12,
                touchMoveLimit: 24,
                enableScroll: false,
                xAxis: {
                    disableGrid: true,
                    scrollShow: true,
                    itemCount: 4,
                },
                yAxis: {
                    data: [
                        {
                            min: 0,
                        },
                    ],
                },
                extra: {
                    column: {
                        type: "group",
                        activeBgColor: "#000000",
                        activeBgOpacity: 0.08,
                        width: 20,
                    },
                },
            },
        };
    },
    methods: {
        getServerData() {
            //模拟从服务器获取数据时的延时
            setTimeout(() => {
                //模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
                let res = {
                    categories: ["原材料", "工程材料", "资产"],
                    series: [
                        {
                            name: "产品",
                            data: [3, 8, 11],
                        },
                        {
                            name: "供应商",
                            data: [12, 11, 21],
                        },
                    ],
                };
                this.chartData = JSON.parse(JSON.stringify(res));
            }, 500);
        },
    },
    mounted() {
        this.$nextTick(() => {
            this.getServerData();
        });
    },
};
</script>

<style lang="scss" scoped>
.data-charts {
    width: 100%;
    height: 300px;
}
</style>
