let appNormalEqu=new Vue({
    // el:'#app',
    data(){
        return {
            time:'',
            curDeviceName:'',
            autorun:0,
            autorun2:'0%',
            autostop:0,
            autostop2:'0%',
            prepare:0,
            prepare2:'0%',
            warntime:0,
            warntime2:'0%',
            closetime:0,
            closetime2:'0%',         
            dialogVisible:false,
            devices:[],
            totalDevicesNum:0,
            runDevicesNum:0,
            stopDevicesNum:0,
            failDevicesNum:0,
            blackoutDevicesNum:0,
            devicePage:0,
            totalDevicesNum:0,
            totalDevicesPage:0,
            curDeviceIx:0,
            autorun:0,
            autostop:0,
            equNo:'',
            getDeviceData3Handle:null,
            ...commonOption,
            countDownSec:15,
            countDownHandle:null,
            devStatus:''
        }
    },
    created(){
        
    },
    mounted(){     

    },
    computed:{
        curStatus(){
            let status=''
            switch (parseInt(this.devStatus) ){
                case 1:
                    status='运转'
                    break;
                case 2:
                    status='报警'
                    break;
                case 3:
                    status='停止'
                    break;            
                default:

                    break;
            }

            return status
        }
    },
    methods:{
        show(){
            let that=this           
            this.$el.style.display='block'
            this.devStatus=''
            this.countDownSec=15
            that.countDown()
            this.$nextTick(()=>{
                // const loading=this.$loading({
                //     lock: true,
                //     text: '加载中',
                //     spinner: 'el-icon-loading',
                //     background: 'rgba(0, 0, 0, 0.7)'
                // }); 
                that.getDeviceData3(this.equNo).then(res=>{
                    // loading.close()
                })
            })

        },
        back(){
            // console.log('getDeviceData3Handle',this.getDeviceData3Handle)
            // clearTimeout(this.getDeviceData3Handle)
            clearTimeout(this.countDownHandle)
            this.$el.style.display='none'
            // let lastApp=appStack[appStack.length-1]
            // lastApp.show()

        },
        countDown(){
            let that=this
            that.countDownHandle=setTimeout(function(){
                if(that.$el.style.display=='none'){
                    return
                }
                that.countDownSec--
                if(that.countDownSec>0){
                    that.countDown()
                }else{
                    that.back()
                }
            },1000)
        },
        init(option){
            let that=this
            for(let i in option){
                this[i]=option[i]
            }

        },
        getDeviceData3(equNo){

            let that=this
            that.autorun=null;
            that.autorun2=null;
            that.autostop=null;
            that.autostop2=null;
            that.warntime=null;
            that.warntime2=null;
            that.closetime=null;
            that.closetime2=null;
            that.prepare=null;
            that.prepare2=null;                
            return axios.get('module/getCurDeviceInfo.php',{
                params:{
                    equNo:equNo,
                    starttime:this.starttime.getTime()/1000,
                    endtime:this.endtime.getTime()/1000                       
                }
            }).then((res)=>{
                

                that.$nextTick(()=>{
                    that.autorun=res.data.autoRun;
                    that.autorun2=res.data.autoRun2;
                    that.autostop=res.data.autoStop;
                    that.autostop2=res.data.autoStop2;
                    that.warntime=res.data.warnTime;
                    that.warntime2=res.data.warnTime2;
                    that.closetime=res.data.closeTime;
                    that.closetime2=res.data.closeTime2;
                    that.prepare=res.data.prepare;
                    that.prepare2=res.data.prepare2;
                        try{
                            let myChart = echarts.init(that.$refs.chartFsOutputRunRate);
                            let option = {
                                    title:{
                                        text:'',
                                        textStyle:{
                                            color:'#fff'
                                        },
                                        top:'10%',
                                        left:'10%'
                                    },
                                    tooltip:{
                                        show:true,
                                        trigger: 'axis'
                                    },
                                    legend:{
                                        show:true,
                                        data:['产量','运转率'],
                                        icon:'rect',
                                        right:10,
                                        top:'45%',
                                        type: 'scroll',
                                        orient: 'vertical',
                                        itemHeight:10,
                                        textStyle:{
                                            color:'white',
                                            fontSize:'16px'
                                        }
                                    },
                                    grid: [{
                                    left: '10%',
                                    bottom: '18%',
                                    top: '23%',
                                    right: '20%'
                                    }],                                       
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.timeline,
                                        splitNumber:8,
                                        axisLabel:{show:true,color:'#fff',rotate:45}
                                    },
                                    yAxis: [{
                                        type: 'value',
                                        name:'产量',
                                        nameTextStyle:{
                                            color:'#fff'
                                        },
                                        splitLine:{
                                            show:false
                                        },
                                        axisLabel:{show:true,color:'#fff'},
                                        axisLine:{
                                            show:true
                                        }
                                    }, {
                                        type: 'value',
                                        name:'运转率(%)',
                                        nameTextStyle:{
                                            color:'#fff'
                                        },
                                        splitLine:{
                                            show:false
                                        },
                                        axisLabel:{show:true,color:'#fff',formatter:(v)=>v*100},
                                        axisLine:{
                                            show:true
                                        }
                                    }],                         
                                    series: [
                                        {
                                            name: '产量',
                                            type: 'line',
                                            smooth: true,
                                            // symbol:'none',
                                            color:['#0d7334'],
                                            data: res.data.outputs,
                                            yAxisIndex:0
                                        },
                                        {
                                            name: '运转率',
                                            type: 'line',
                                            smooth: true,
                                            color:['#cb0000'],
                                            data: res.data.runrates,
                                            yAxisIndex:1
                                        }
                                    ]
                                };
                            myChart.setOption(option)
                            myChart.resize()
                            let devStatuses=[{
                                value:parseFloat(res.data.autoRun2),name:'自动运转'
                            },{
                                value:parseFloat(res.data.autoStop2),name:'自动停止'
                            },{
                                value:parseFloat(res.data.warnTime2),name:'报警'
                            },{
                                value:parseFloat(res.data.closeTime2),name:'电源关闭'
                            },{
                                value:parseFloat(res.data.prepare2),name:'准备'
                            }];


                            let chartFsDevStatuses1 = echarts.init(that.$refs.chartFsDevStatuses1);
                            let optionDevStatuses1 = {
                                series: [
                                            {
                                                type: 'pie',
                                                smooth: true,
                                                data:devStatuses
                                            }
                                    ]
                            }
                            chartFsDevStatuses1.setOption(optionDevStatuses1)
                            chartFsDevStatuses1.resize()

                            // let chartFsDevStatuses2 = echarts.init(that.$refs.chartFsDevStatuses2);


                            // let colors=['rgba(0,255,0,0.3)','rgba(255,0,0,0.3)','rgba(255,255,0,0.3)'];
                            if(res.data.devStatus!=undefined){
                                that.devStatus=res.data.devStatus
                                // if(res.data.devStatus==1){//运行
                                //     colors[0]='rgba(0,255,0,0.8)';
                                // }else if(res.data.devStatus==2){//报警
                                //     colors[1]='rgba(255,0,0,0.8)';
                                // }else if(res.data.devStatus==3){//停止
                                //     colors[2]='rgba(255,255,0,0.8)';
                                // }
                            }

                            // let optionDevStatuses2 = {
                            //     xAxis: {
                            //         type: 'category',
                            //         show:false,
                            //         data:['stack1']
                            //     },
                            //     yAxis:{
                            //         type:'value',
                            //         show:false
                            //     },
                            //     series: [

                            //                 {
                            //                     name:'停止',
                            //                     type: 'bar',
                            //                     stack: 'total',
                            //                     data:[1],
                            //                     itemStyle:{
                            //                         color:colors[2]
                            //                     }
                            //                 },
                            //                 {
                            //                     name:'报警',
                            //                     type: 'bar',
                            //                     stack: 'total',
                            //                     data:[1],
                            //                     itemStyle:{
                            //                         color:colors[1]
                            //                     }
                            //                 },
                            //                 {
                            //                     name:'主机运转',
                            //                     type: 'bar',
                            //                     stack: 'total',
                            //                     data:[1],
                            //                     itemStyle:{
                            //                         color:colors[0]
                            //                     }
                            //                 }
                            //         ]
                            // }

                            // chartFsDevStatuses2.setOption(optionDevStatuses2)                                
      
                        }catch(e){
                            console.log(e,that.$refs)
                        }
                    })


            }).catch(err=>{
                console.log(err)
            }).then(res=>{
                
                // that.getDeviceData3Handle=setTimeout(()=>{
                //     that.getDeviceData3(equNo)
                // },2*1000)

            })
        },	
    }
})