<template>
    <div class="DPcomputer28Box">
        <!-- 卸货点卸货量统计 -->
        <div class="dataAnalysisScrView_rightView_title">卸货点卸货量统计</div>
        <div class="dataAnalysisScrView_rightView_content" style="position: relative;">
            <div id="echarts7View"></div>
        </div>
    </div>
</template>

<script>
import { Tools, HttpReq, CAMap} from '@/assets/js/common.js';
import * as echarts from 'echarts';


export default {
    data(){
        return {
            DPcomputer28BoxTimer:null,
            //时间
            currentTime:{
                month:'',
            },
            //卸货点卸货量统计
            echarts7Data:{
                xiedianName:[],
                outputNum:[],
            },
        }
    },
    mounted(){
        this.loadData();
    },
    methods:{
        loadData(){
            this.monthCurrentTimeFn();
            //卸货点卸货量统计
            HttpReq.truckDispatching.xiequAreaQueryMonth({createTime:this.currentTime.month}).then((res) => {
                if(res.code == 200){
                    let xiedianName = [];
                    let outputNum = [];
                    res.data.forEach((item,index)=>{
                        xiedianName.push(item.name);
                        outputNum.push(item.total);
                    })
                    this.echarts7Data.xiedianName = xiedianName;
                    this.echarts7Data.outputNum = outputNum;
                    this.echarts7Fn();
                }
            })

            this.DPcomputer28BoxTimer = setInterval(() => {
                //卸货点卸货量统计
                HttpReq.truckDispatching.xiequAreaQueryMonth({createTime:this.currentTime.month}).then((res) => {
                    if(res.code == 200){
                        let xiedianName = [];
                        let outputNum = [];
                        res.data.forEach((item,index)=>{
                            xiedianName.push(item.name);
                            outputNum.push(item.total);
                        })
                        this.echarts7Data.xiedianName = xiedianName;
                        this.echarts7Data.outputNum = outputNum;
                        this.echarts7Fn();
                    }
                })
            },20000)
        },
        //卸货点卸货量统计
        echarts7Fn(){
            echarts.init(document.getElementById('echarts7View')).dispose();
            var myChart = echarts.init(document.getElementById('echarts7View'));
            var option = {
                tooltip: {
                    trigger: 'axis',
                },
                grid: {
                    left: '3%',
                    right: '8%',
                    bottom: '20%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: this.echarts7Data.xiedianName,
                        axisPointer: {
                            type: 'shadow'
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: 'white'
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                color: 'white',
                                width: 1
                            }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '产量(T)',
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: 'white'
                            }
                        },
                        axisLine: {
                            lineStyle: {
                                color: 'white',
                                width: 0
                            }
                        }
                    }
                ],
                series: [
                    {
                        type: 'bar',
                        data: this.echarts7Data.outputNum,
                        barWidth: 10,
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                { offset: 0, color: '#00B7FF' },
                                { offset: 1, color: '#2244AC' }
                            ])
                            
                        },
                    }
                ]
            };
            option && myChart.setOption(option);
        },
        monthCurrentTimeFn(){
			var date = new Date();
			var year = date.getFullYear();        //年 ,从 Date 对象以四位数字返回年份
			var month = date.getMonth() + 1;      //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
			//修改月份格式
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			let currentFormatDate = year + "-" + month;
			this.currentTime.month = currentFormatDate;
		},
    },
    beforeDestroy(){
        if(this.DPcomputer28BoxTimer) {
			clearInterval(this.DPcomputer28BoxTimer);
            this.DPcomputer28BoxTimer = null;
		}
    }
}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
}
.DPcomputer28Box{
    width: 20vw;
    height: 23.5vh;
    background-color: rgba(32,42,67,0.95);
    padding: 5px 7px;
    box-sizing: border-box;
    overflow: hidden;
}
.DPcomputer28Box .dataAnalysisScrView_rightView_title{
    margin-bottom: 5px;
    width: 100%;
    height: 3.5vh;
    background:no-repeat center center url('~@/assets/images/cutGraph/biaoti1.png');
	background-size:100% 100%;
    padding-left: 10px;
    box-sizing: border-box;
    font-size: 18px;
    line-height: 3.5vh;
    color: #FAFAFB;
    letter-spacing: 1px;
    text-shadow: 1px 1px 1px #92CBFF;
}
.DPcomputer28Box .dataAnalysisScrView_rightView_content{
    width: 100%;
    height: 19vh;
}
.DPcomputer28Box #echarts7View{
    position: absolute;
    left: 0vw;
    top: -2.5vh;
    width: 105%;
    height: 25.5vh;
}
</style>