<template>
    <div class="DPcomputer24Box">
        <!-- 月生产完成效率-->
        <div class="dataAnalysisScrView_leftView_title">月生产完成效率</div> 
        <div class="dataAnalysisScrView_leftView_content" style="position: relative;">
            <div id="echarts3View"></div>
        </div>
    </div>
</template>

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


export default {
    data(){
        return {
            DPcomputer24BoxTimer:null,
            //时间
            currentTime:{
                month:'',
            },
            //月生产完成效率
            echarts3Data:{
                caiquName:[],
                wanchengNum:[],
                jihuaNum:[],
            },
        }
    },
    mounted(){
        this.loadData();
    },
    methods:{
        loadData(){
            this.monthCurrentTimeFn();
            //各采区当月完成率 和 月生产完成效率
            HttpReq.truckDispatching.caiquAreaQueryMonth({size:9999,createTime:this.currentTime.month}).then((res) => {
                let eh2_1_arr1 = [];
                let eh2_1_arr2 = [];
                let eh2_1_arr3 = [];
                let eh2_1_arr4 = [];
                res.forEach((item)=>{
                    eh2_1_arr1.push(item.name);
                    eh2_1_arr2.push(item.total);
                    eh2_1_arr3.push(item.nowPlan);
                    eh2_1_arr4.push(item.ratio);
                })
                this.echarts3Data.caiquName = eh2_1_arr1;
                this.echarts3Data.wanchengNum = eh2_1_arr2;
                this.echarts3Data.jihuaNum = eh2_1_arr3;
                this.echarts3Fn();
            })

            this.DPcomputer24BoxTimer = setInterval(() => {
                //各采区当月完成率 和 月生产完成效率
                HttpReq.truckDispatching.caiquAreaQueryMonth({size:9999,createTime:this.currentTime.month}).then((res) => {
                    let eh2_1_arr1 = [];
                    let eh2_1_arr2 = [];
                    let eh2_1_arr3 = [];
                    let eh2_1_arr4 = [];
                    res.forEach((item)=>{
                        eh2_1_arr1.push(item.name);
                        eh2_1_arr2.push(item.total);
                        eh2_1_arr3.push(item.nowPlan);
                        eh2_1_arr4.push(item.ratio);
                    })
                    this.echarts3Data.caiquName = eh2_1_arr1;
                    this.echarts3Data.wanchengNum = eh2_1_arr2;
                    this.echarts3Data.jihuaNum = eh2_1_arr3;
                    this.echarts3Fn();
                })
            },20000)
        },
        //月生产完成效率
        echarts3Fn(){
            echarts.init(document.getElementById('echarts3View')).dispose();
            var myChart = echarts.init(document.getElementById('echarts3View'));
            var option = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['目标完成', '计划完成'],
                    textStyle:{
                        color:'white',
                        fontSize:15,
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    data: this.echarts3Data.caiquName,
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: 'white'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'white',
                            width: 0
                        }   
                    }
                },
                yAxis: {
                    type: 'value',
                    name: '完成量',
                    nameTextStyle: { fontSize: 14 },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: 'white'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'white',
                            width: 0
                        }
                    }
                },
                series: [
                    {
                        name: '目标完成',
                        type: 'line',
                        data: this.echarts3Data.wanchengNum,
                        itemStyle: {
                            normal: {
                                lineStyle: { color: '#FFC200' } //设置线条颜色
                            }
                        }
                    },
                    {
                        name: '计划完成',
                        type: 'line',
                        data: this.echarts3Data.jihuaNum,
                        itemStyle: {
                            normal: {
                                lineStyle: { color: '#21DDF3' } //设置线条颜色
                            }
                        }
                    }
                ]
            };
            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.DPcomputer24BoxTimer) {
			clearInterval(this.DPcomputer24BoxTimer);
            this.DPcomputer24BoxTimer = null;
		}
    }
}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
}
.DPcomputer24Box{
    width: 20vw;
    height: 23.5vh;
    background-color: rgba(32,42,67,0.95);
    padding: 5px 7px;
    box-sizing: border-box;
    overflow: hidden;
}
.DPcomputer24Box .dataAnalysisScrView_leftView_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;
}
.DPcomputer24Box .dataAnalysisScrView_leftView_content{
    width: 100%;
    height: 19vh;
}
.DPcomputer24Box #echarts3View{
    position: absolute;
    left: 0vh;
    width: 100%;
    height: 19vh;
}
</style>