// import excelHelper from "@/utils/excelHelper";
export default {
    data() {
        return {
            formInline: {
                windfarm: "",
                project: "",
                line: "",
            },
            activeName: 'first',
            information: 'first',
            value: 'MHS_FDC',
            value2: 'MG01_01',
            options: [],
            options2: [],
            month: '',
            time: '',
            timemonth: '',
            timeyear: '',
            updateTime: '',
            title: '月曲线偏差率排行榜',
            daymonth: '',
            dayyear: '',
            currentPage2: 1,
            pagesize: 10,
            orderByColumn: '',
            isAsc: '',
            gridData: [],
            gridDataChart: [],
            gridDataChartX: [],
            gridDataChartYsjnh: [],
            gridDataChartYzynh: [],
            gridDataChartYbzgl: [],
            switchtableall: true,
            switchtableday: false,
            switchtablemonth: false,
            total: 0,
        }
    },
    created() {
        var newData = new Date();
        this.updateTime = this.BASE.getBzDate(newData.getTime(), -1);
        this.API.get('/powercompare/windfarmAjax').then((res) => {
            this.options = res.data;
        })
        this.API.get('/powercompare/windturbineAjax?wpId=' + this.value).then((res) => {
            this.options2 = res.data;
        })
        this.singleMachinePower();
    },
    methods: {
        queryApData() {
            this.singleMachinePower();
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pagesize = val;
            this.singleMachinePower();
        },
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            this.singleMachinePower();
        },
        headStyle() {
            return "text-align:center"
        },
        handleClick(tab) {
            // console.log(tab.name)
            this.information = tab.name;
            this.singleMachinePower();
        },
        changeTableSort(column) {
            this.orderByColumn = column.prop;
            if (column.order == "descending") {
                this.isAsc = 'desc';
            } else if (column.order == "ascending") {
                this.isAsc = "asc";
            }
            this.singleMachinePower();
        },
        singleMachinePower() {
            this.gridDataChart = [];
            this.gridDataChartX = [];
            this.gridDataChartYsjnh = [];
            this.gridDataChartYzynh = [];
            this.gridDataChartYbzgl = [];

            var singleMachinePowerData = new URLSearchParams();
            var singleMachinePowerDataChart = new URLSearchParams();
            if (this.information == 'first') {
                this.title = '单机总功率信息列表';
                this.switchtableall = true;
                this.switchtableday = false;
                this.switchtablemonth = false;
                singleMachinePowerData.append('pageNum', this.currentPage2);
                singleMachinePowerData.append('pageSize', this.pagesize);
                singleMachinePowerData.append('orderByColumn', this.orderByColumn);
                singleMachinePowerData.append('isAsc', this.isAsc);
                singleMachinePowerData.append('wtId', this.value2);
                this.API.post("/powersaturation/powersaturationamonutlist", singleMachinePowerData).then((res) => {
                    this.gridData = res.data.list;
                    this.total = res.data.total;
                })
                singleMachinePowerDataChart.append('wtId', this.value2);
                this.API.post("/powersaturation/powersaturationamonutchart", singleMachinePowerDataChart).then((res) => {
                    this.gridDataChart = res.data;
                    for (let i = 0; i < this.gridDataChart.length; i++) {
                        this.gridDataChartX.push(this.gridDataChart[i].value1);
                        this.gridDataChartYsjnh.push(this.gridDataChart[i].value2);
                        this.gridDataChartYzynh.push(this.gridDataChart[i].value3);
                        this.gridDataChartYbzgl.push(this.gridDataChart[i].value4);
                    }
                    this.$nextTick(function () {
                        this.drawPie('leiDaTu')
                    })
                })
            } else if (this.information == 'second') {
                this.title = '单机月功率信息列表';
                this.switchtableall = false;
                this.switchtableday = true;
                this.switchtablemonth = false;
                singleMachinePowerData.append('pageNum', this.currentPage2);
                singleMachinePowerData.append('pageSize', this.pagesize);
                singleMachinePowerData.append('orderByColumn', this.orderByColumn);
                singleMachinePowerData.append('isAsc', this.isAsc);
                singleMachinePowerData.append('wtId', this.value2);
                if (this.timeyear == '') {
                    this.timeyear = this.updateTime;
                    this.timeyear = this.timeyear.slice(0, 4);
                } else {
                    this.timeyear = this.timeyear.toString();

                }
                singleMachinePowerData.append('year', this.timeyear);
                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 {
                    this.timemonth = this.month.toString();
                    if (this.timemonth.substring(5, 7) < 10) {
                        this.timemonth = this.timemonth.substring(6, 7);
                    } else {
                        this.timemonth = this.timemonth.substring(5, 7)
                    }
                }
                console.log(this.timemonth)
                singleMachinePowerData.append('month', this.timemonth);
                this.API.post("/powersaturation/powersaturationmonthlist", singleMachinePowerData).then((res) => {
                    this.gridData = res.data.list;
                    this.total = res.data.total;
                })
                singleMachinePowerDataChart.append('wtId', this.value2);
                singleMachinePowerDataChart.append('year', this.timeyear);
                singleMachinePowerDataChart.append('month', this.timemonth);
                this.API.post("/powersaturation/powersaturationmonthchart", singleMachinePowerDataChart).then((res) => {
                    this.gridDataChart = res.data;
                    for (let i = 0; i < this.gridDataChart.length; i++) {
                        this.gridDataChartX.push(this.gridDataChart[i].value1);
                        this.gridDataChartYsjnh.push(this.gridDataChart[i].value2);
                        this.gridDataChartYzynh.push(this.gridDataChart[i].value3);
                        this.gridDataChartYbzgl.push(this.gridDataChart[i].value4);
                    }
                    console.log(this.gridDataChart)
                    this.$nextTick(function () {
                        this.drawPie('leiDaTu')
                    })
                })
            } else if (this.information == 'cord') {
                this.title = '单机日功率信息列表';
                this.switchtableall = false;
                this.switchtableday = false;
                this.switchtablemonth = true;
                if (this.time == '') {
                    this.time = this.updateTime;
                }
                singleMachinePowerData.append('pageNum', this.currentPage2);
                singleMachinePowerData.append('pageSize', this.pagesize);
                singleMachinePowerData.append('orderByColumn', this.orderByColumn);
                singleMachinePowerData.append('isAsc', this.isAsc);
                singleMachinePowerData.append('wtId', this.value2);
                singleMachinePowerData.append('recorddate', this.time);
                this.API.post("/powersaturation/powersaturationlist", singleMachinePowerData).then((res) => {
                    this.gridData = res.data.list;
                    this.total = res.data.total;
                })
                singleMachinePowerDataChart.append('wtId', this.value2);
                singleMachinePowerDataChart.append('recorddate', this.time);
                this.API.post("/powersaturation/powersaturationchart", singleMachinePowerDataChart).then((res) => {
                    this.gridDataChart = res.data;
                    for (let i = 0; i < this.gridDataChart.length; i++) {
                        this.gridDataChartX.push(this.gridDataChart[i].value1);
                        this.gridDataChartYsjnh.push(this.gridDataChart[i].value2);
                        this.gridDataChartYzynh.push(this.gridDataChart[i].value3);
                        this.gridDataChartYbzgl.push(this.gridDataChart[i].value4);
                    }
                    this.$nextTick(function () {
                        this.drawPie('leiDaTu')
                    })
                })
            }
        },
        toExcel() {
            excelHelper.exportExcel("singlemachinepower", "负荷率排行榜", ".xls", true);
        },
        drawPie() {
            this.ECLZX.getSingleMachineSaturationChart("leiDaTu",this.gridDataChartX,
            [
                {
                  name: '实际拟合功率',
                  type: 'line',
                  stack: '总量',
                  data: this.gridDataChartYsjnh
                },
                {
                  name: '最优拟合功率',
                  type: 'line',
                  stack: '总量',
                  data: this.gridDataChartYzynh
                },
                {
                  name: '保证功率',
                  type: 'line',
                  stack: '总量',
                  data: this.gridDataChartYbzgl
                },
              ],['实际拟合功率', '最优拟合功率', '保证功率']);

        },
    }
}