let appFullsrn=new Vue({
    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,
            show_prospec:'show',
            show_device_name:'show',
            checkedKeys:[],
            getDevicesHandle:null,
            changePageHandle:null,
            echartsIns:{},
            ...commonOption,
            getDevicesCounter:0
        }
    },
    methods:{
        show(){
            let that=this
            this.$el.style.display='block'
            this.$nextTick(()=>{
                this.getDevices(function(){    
                     console.log(1000*60*that.config['fullscreen_page_change'])        
                    that.changePageHandle=setTimeout(that.changePage,1000*60*that.config['fullscreen_page_change']);              
                }); 
            })


        },
        back(){
            clearTimeout(this.changePageHandle)
            clearTimeout(this.getDevicesHandle)
            this.$el.style.display='none'
            let lastApp=appStack[appStack.length-1]
            lastApp.show()

        },
        init(option){
            let that=this
            for(let i in option){
                this[i]=option[i]
            }
        },
        showDetail(device){
            let that=this
            clearTimeout(this.changePageHandle)
            clearTimeout(this.getDevicesHandle)

            //this.$el.style.display='none'            
            if(device.IsCNC==1){
                that.showDetail1(device);
            }else{
                that.showDetail2(device)
            }
        },
        showDetail1(device){
            let that=this
            //appStack.push(appCnc)
            appCnc.init({
                machineId:device.MachineId,
                equNo:device.EquNo
            })
            appCnc.show()
        },
        showDetail2(device){
            let that=this
            //appStack.push(appNormalEqu)
            appNormalEqu.init({
                equNo:device.EquNo                
            })
            appNormalEqu.show()
        }, 
        changePage(e){
            let that=this
            that.devicePage++;
            if(that.devicePage>Math.ceil(that.devices.length/20)){
                that.devicePage=1
            }
            console.log(1000*60*that.config['fullscreen_page_change'])
            this.changePageHandle=setTimeout(this.changePage,1000*60*that.config['fullscreen_page_change']);
        }, 
        getDevices(f){
            let that=this;
            const params = new URLSearchParams();
                params.append('wcids', this.wcids_right);
                params.append('starttime', this.starttime.getTime()/1000);  
                params.append('endtime', this.endtime.getTime()/1000); 
            let onlyStatus=0
                if(that.getDevicesCounter==0 && this.mode=='SCADA'){
                    onlyStatus=0
                }else{
                    onlyStatus=1
                }  
                params.append('onlyStatus',onlyStatus)

                that.getDevicesCounter++
                if(that.getDevicesCounter>(60*that.config['interval_devices_refresh']/3)){
                    that.getDevicesCounter=0
                }

                axios.post('module/getDevices.php',params).then((res)=>{   

                    if(res.data.code==1){
                        let data=res.data.data
                        that.show_device_name=data.show_device_name;
                        that.show_prospec=data.show_prospec;  
                        if(onlyStatus==1){
                            let equs={}
                            data.devices.forEach(v=>{
                               equs[v.EquNo]=v
                            })
                            let tDevices=[]
                            
                           that.devices.forEach(element => {
                               let equNo=element.EquNo
                               if(equs[equNo]!=undefined){
                                   that.$set(element,'status',equs[equNo].status)
                                   tDevices.push(element)
                               }

                            });
                            that.devices=tDevices
                        }else{
                            console.log(onlyStatus)
                            that.devices=data.devices;
                        }                    
                     
                        let totalDevicesNum=that.devices.length;
                        that.totalDevicesNum=totalDevicesNum;
                        let totalDevicesPage=Math.ceil(totalDevicesNum/20);
                        that.totalDevicesPage=totalDevicesPage;

                        let runNum=0;
                        let stopNum=0;
                        let failNum=0;
                        let blackout=0;
    
                       
                        for(let i=0;i<that.devices.length;i++){
                            if(that.devices[i].status=='green'){
                                runNum++;
                            }
                            if(that.devices[i].status=='red'){
                                stopNum++;
                            }
                            if(that.devices[i].status=='yellow'){
                                failNum++;
                            }
                            if(that.devices[i].status=='gray'){
                                blackout++;
                            }                                                                                    
                        }
                        that.runDevicesNum=runNum;
                        that.stopDevicesNum=stopNum;
                        that.failDevicesNum=failNum;
                        that.blackoutDevicesNum=blackout
                        if(f!=undefined){
                            f();
                        }
                        // loading.close();
                        that.getDevicesHandle=setTimeout(function(){
                            that.getDevices();
                        },1000*3);

                    }else{
                        throw new Error(res.data.msg);
                    }

                }).catch(function(res){
                    //loading.close();
                    console.log(res)
                    that.$message({
                    type:'error',
                    message:'请求失败'
                    })                        
                })
        }
    }
})