<template>
    <card icon="shuju_icon_xiangmu" title="项目数量">
        <div class="chart" ref="chart"></div>
    </card>
</template>

<script>
import card from '../card.vue';
import * as echarts from 'echarts';
import chartOptions from '../../mixins/chartOptions';

export default {
    name: 'CompanyAmount',
    components: { card },
    mixins: [chartOptions],
    mounted() {
        this.$nextTick(() => {
            this.myChart = echarts.init(this.$refs.chart, 'jmrh');
            this.initChat(this.myChart);
            this.getData();
        });
    },
    methods: {
        getData() {
            this.$http.get('/statDataCenter/cityProjectNum').then((res) => {
                this.myChart.setOption({
                    tooltip: {
                        formatter: () => {
                            return '';
                        },
                    },
                    grid: {
                        bottom: 35,
                    },
                    color: ['#5CFFAC'],
                    xAxis: {
                        data: res.labels,
                        axisLabel: {
                            rotate: -60,
                            margin: 5,
                            formatter: (value) => {
                                return value.replace(/市/, '');
                            },
                        },
                    },
                    series: [
                        {
                            name: '项目数量',
                            data: res.data,
                            type: 'line',
                            areaStyle: {
                                color: {
                                    type: 'linear',
                                    x: 0,
                                    y: 0,
                                    x2: 0,
                                    y2: 1,
                                    colorStops: [
                                        {
                                            offset: 0,
                                            color: '#5CFFAC',
                                        },
                                        {
                                            offset: 1,
                                            color: 'rgba(92, 255, 172, 0)',
                                        },
                                    ],
                                    global: false,
                                },
                            },
                            label: {
                                show: false,
                                formatter: '{b}\r\n{c}',
                                backgroundColor: '#34D281',
                                color: '#fff',
                                padding: [3, 5],
                                borderRadius: 4,
                                position: 'top',
                                textStyle: {
                                    lineHeight: 16,
                                },
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                },
                            },
                            labelLayout: this.labelLayout,
                        },
                    ],
                });
            });
        },
    },
};
</script>

<style lang="less" scoped>
.chart {
    width: 100%;
    height: 100%;
    flex-grow: 1;
}
</style>
