// import excelHelper from "@/utils/excelHelper";
export default {
    data(){
        return {
            formInline: {
                windfarm: "",
                project: "",
                line: "",
            },
            activeName: 'first',
            information:'first',
            value:'MHS_FDC',
            value2:'',
            options: [],
            time:'',
            timemonth:'',
            month:'',
            timeyear:'',
            year:'',
            title:'月曲线偏差率排行榜',
            daymonth:'',
            dayyear:'',
            currentPage2: 1,
		    pagesize: 10,
            orderByColumn:'',
            isAsc: '',
            type:'1',
            gridData:[],
            dialogFormVisible:false,
            fanData:[],
            ChartData:[],
            dayChartData:[],
            Xdata:[],
            sjdata:[],
            bzdata:[],
            eldialogtitle:'',

            
        }
    },
    created(){
        this.API.get('/powercompare/windfarmAjax').then((res) => {
            this.options = res.data;
        })
        this.DeviceRatData();
    },
    methods:{
        queryApData() {
             this.DeviceRatData();
        },
        headStyle() {
			return "text-align:center"
		},
        handleClick(tab) {
            this.information = tab.name;
            this.DeviceRatData();
        },
        clickCopy(e) {
             this.type = e;
        },
        tableDatawindturbineName(val) {
            if(this.type == "1"){
                this.dialogFormVisible = false;
            }else{
          this.dialogFormVisible = true;
          this.Xdata = [];
          this.sjdata = [];
          this.bzdata = [];
          this.fanData = val;
          var deviceRateChartData = new URLSearchParams();
          if(this.information == 'first'){
            this.eldialogtitle = '月曲线偏差率排行';
            deviceRateChartData.append('type',this.type);
            deviceRateChartData.append('wtId',this.fanData.windturbineid);
            this.timeyear = this.year.toString();
            deviceRateChartData.append('year',this.timeyear);  
            this.timemonth = this.month.toString();
            if(this.timemonth.substring(6,7) < 10){
                this.timemonth = this.timemonth.substring(6,7);
            }else{
                this.timemonth = this.timemonth.substring(5,7)
            }      
            deviceRateChartData.append('month',this.timemonth);
            this.API.post('/leaderboard/curveMonthchatAjax',deviceRateChartData).then((res) =>{
                this.ChartData = res.data.datas;
                for(let i = 0; i<this.ChartData.length ; i++){
                    this.Xdata.push(this.ChartData[i].value1);
                    this.sjdata.push(this.ChartData[i].value2);
                    this.bzdata.push(this.ChartData[i].value3);
                }
                this.$nextTick(function() {
                    this.drawPie('leiDaTu')
                })
            })
          }else if(this.information == 'second'){
            this.eldialogtitle = '日曲线偏差率排行';
            deviceRateChartData.append('type',this.type);
            deviceRateChartData.append('wtId',this.fanData.windturbineid);
            deviceRateChartData.append('recorddate',this.time);
            this.API.post('/leaderboard/getCurvechatAjax',deviceRateChartData).then((res) =>{
                this.ChartData = res.data.datas;
                for(let i = 0; i<this.ChartData.length ; i++){
                    this.Xdata.push(this.ChartData[i].value1);
                    this.sjdata.push(this.ChartData[i].value2);
                    this.bzdata.push(this.ChartData[i].value3);
                }
                this.$nextTick(function() {
                    this.drawPie('leiDaTu')
                })
            })
           }
            }
        },
        changeTableSort(column){
			this.orderByColumn = column.prop;
			if(column.order == "descending"){
				this.isAsc = 'desc';
			}else if(column.order == "ascending"){
				this.isAsc = "asc";
			}
			this.DeviceRatData();
		},
        DeviceRatData(){
            this.gridData = [];
            var deviceRatData = new URLSearchParams();
            if(this.information == 'first'){
                var newData = new Date();
                this.updateTime = this.BASE.getBzDate(newData.getTime(), 0);
                this.title = '月曲线偏差率排行榜';
                deviceRatData.append('pageNum',this.currentPage2);
                deviceRatData.append('pageSize',this.pagesize);
                deviceRatData.append('orderByColumn',this.orderByColumn);
                deviceRatData.append('isAsc',this.isAsc);
                deviceRatData.append('wpId',this.value); 
                if(this.year == ''){
                    this.year = this.updateTime;
                    this.year = this.year.slice(0,4);
                }else{
                    this.year = this.year.toString();          
                    
                }  
                deviceRatData.append('year',this.year);
                if(this.month == ''){
                    this.month = this.updateTime;
                    if(this.month.substring(5,7) < 10 ){
                        this.timemonth = this.month.substring(6,7);
                    }else{
                        this.timemonth = this.month.substring(5,7);
                    }
                }else{
                    if(this.month.substring(5,7) < 10){
                        this.timemonth = this.month.substring(6,7);
                    }else{
                        this.timemonth = this.month.substring(5,7)
                    }
                }
                deviceRatData.append('month',this.timemonth);
                this.API.post("/leaderboard/curvefittingmonthmainList",deviceRatData).then((res) => {
                    this.gridData = res.data;
                })
            }else if(this.information == 'second'){
                this.title = '日曲线偏差率排行榜';
                deviceRatData.append('pageNum',this.currentPage2);
                deviceRatData.append('pageSize',this.pagesize);
                deviceRatData.append('orderByColumn',this.orderByColumn);
                deviceRatData.append('isAsc',this.isAsc);
                deviceRatData.append('wpId',this.value);
                var newData = new Date();
                this.updateTime = this.BASE.getBzDate(newData.getTime(), 0);
                if(this.time == ''){
                    this.time = this.updateTime;
                }
                deviceRatData.append('recorddate',this.time);
                this.API.post("/leaderboard/curvefittingmainList",deviceRatData).then((res) =>{
                    this.gridData = res.data;
                })
            }
        },
        drawPie() {
				this.ECLZX.getCurveDeviationRate("leiDaTu",
                ['实际功率(kw)', '保证功率(kw)'],this.Xdata,this.sjdata,this.bzdata);
		},
        toExcel(){
            excelHelper.exportExcel("devicerattable","负荷率排行榜",".xls",true);
        }
    }
}