<template>
    <div class="revenueTrends">
        <canvas class="trends" canvas-id="trends" id="trends"/>
    </div>
</template>

<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
    name: "revenueTrends",
    data() {
        return {
        }
    },
    props: {
        data: {
            type: Object,
            default: () => {}
        }
    },
    watch: {
        data: {
            handler(value) {
                console.log('carDatawatch', value)
                this.handleCarData(value)
            }
        }
    },
    methods: {
        // 处理传入的数据
        handleCarData(value) {
            let res = value
            this.drawCharts('trends', res)
        },
        drawCharts(id, data) {
            const ctx = uni.createCanvasContext(id, this);
            let _this = this
            let phoneInfo = uni.getStorageSync('phoneInfo')
            this.width = phoneInfo.screenWidth - 16
            uChartsInstance[id] = new uCharts({
                type: "area",
                context: ctx,
                width: _this.width ,
                height: 198,
                categories: data.categories,
                series: data.series,
                animation: true,
                rotate: false,
                rotateLock: false,
                background: "#FFFFFF",
                color: ["#1E80FF"],
                padding: [15, 15, 5, 5],
                dataLabel: false,
                enableScroll: false,
                legend: {
                    show: false,
                    position: "bottom",
                    lineHeight: 25,
                    float: 'center'

                },
                xAxis: {
                    disableGrid: true
                },
                yAxis: {
                    splitNumber:4,
                    showTitle:true,
                    data:[
                        {
                            min:0,
                            max:12,
                            title:'单位: 千万',
                            titleOffsetY:-5
                        }
                    ]
                },
                extra: {
                    area: {
                        type: "curve",
                        opacity: 0.8,
                        addLine: true,
                        width: 2,
                        gradient: true,
                        activeType: "hollow"
                    }
                }
            });
        },
    }
}
</script>

<style scoped lang="scss">
.revenueTrends{
    width: 100%;
    .trends{
        width: calc(100vw - 32px);
        height: 208px;
    }
}
</style>