import FiveLossRatesPieChart from '@views/lossBenchmarking/fiveLossRatesPieChart';
import FiveLossRatesHistogramChart from '@views/lossBenchmarking/fiveLossRatesHistogramChart.vue';
export default {
    data() {
        return {
            formInline: {
                windfarm: "",
                project: "",
                line: "",
            },
            timedate: [
                // {beginDate:'2021-01-01'},
                // {endDate:'2021-01-04'}
            ],
            isAsc: 'asc',
            beginDate: '',
            endDate: '',
            gridData: [],
            multipleSelection: [],
            sortInOrder: [],
            sortInOrderTop: [],
            sortInOrde2: [],
            getTableData: [],
            sortInOrderTop2: [],
            fdcName1: '',
            fdcName2: '',
            currentPage2: 1,
            pagesize: 10,
            fdcLineData: '',
            classification: [{
                id: 'qf',
                label: '弃风率'
            }, {
                id: 'gz',
                label: '故障损失率'
            },
            {
                id: 'jx',
                label: '检修损失率'
            },
            {
                id: 'xn',
                label: '性能损失率'
            },
            {
                id: 'sl',
                label: '受累损失率'
            }],
            options: [{
                value: 'MHS_FDC',
                label: '麻黄山风电场'
            }, {
                value: 'NSS_FDC',
                label: '牛首山风电场'
            },
            {
                value: 'SBQ_FDC',
                label: '石板泉风电场'
            },
            {
                value: 'QS_FDC',
                label: '青山风电场'
            },
            {
                value: 'XS_FDC',
                label: '香山风电场'
            }],
            value: '',
            value2: 'gz',
            wpId: [],
            wpName: [],
            updateTime1: '',
            updateTime: '',
            orderByColumn: '',
            dialogTableVisible: false,
            lineDataOption: [],
            tableData: [{
                date: '2016-05-02',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1518 弄'
            }, {
                date: '2016-05-04',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1517 弄'
            }, {
                date: '2016-05-01',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1519 弄'
            }, {
                date: '2016-05-03',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1516 弄'
            },
            {
                date: '2016-05-03',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1516 弄'
            },
            {
                date: '2016-05-03',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1516 弄'
            }]

        }
    },
    components: {
        FiveLossRatesPieChart: FiveLossRatesPieChart,
        FiveLossRatesHistogramChart: FiveLossRatesHistogramChart
    },
    created() {
        this.API.get('/powercompare/windfarmAjax').then((res) => {
            this.options = res.data;
        })
        this.FiveLossInformation();
    },
    methods: {
        headStyle() {
            return "text-align:center"
        },
        onSubmit() {
            console.log("submit!");
        },
        handleClick() { },
        deleteRow(index, rows) {
            rows.splice(index, 1);
        },
        queryApData() {
            this.FiveLossInformation();
        },
        handleEdit(a, b) {
            this.wpId = [];
            this.lineDataOption = [];
            if (this.multipleSelection.length == 2) {
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    this.wpId.push(this.multipleSelection[i].wpId)
                    this.wpName.push(this.multipleSelection[i].wpName)
                    this.lineDataOption.push({ id: this.multipleSelection[i].wpId, name: this.multipleSelection[i].wpName })
                }
                console.log(this.lineDataOption)
                this.$router.push({
                    path: '/fiveLossLineTable',
                    query: {
                        wpId: this.wpId,
                        beginDate: this.beginDate,
                        endDate: this.endDate,
                        wpName: this.wpName,
                        select: this.lineDataOption
                    }
                })
            } else {
                console.log(b)
                this.lineDataOption.push({ id: b.wpId, name: b.wpName })
                console.log(this.lineDataOption)
                this.$router.push({
                    path: '/fiveLossLineTable',
                    query: {
                        wpId: b.wpId,
                        beginDate: this.beginDate,
                        endDate: this.endDate,
                        wpName: b.wpName,
                        select: this.lineDataOption
                    }
                })
            }
        },
        checkwindfarm() {
            if (this.formInline.windfarm == "") {
                this.$message.error("请选择风场！");
                return;
            }
        },
        checkproject() {
            if (this.formInline.project == "") {
                this.$message.error("请选择项目！");
                return;
            }
            if (new Date(this.timedate) == null) {
                this.$message.error("请选择时间");
                return;
            }
        },
        queryApDataMx() {
            this.dialogTableVisible = true;
            this.$nextTick(function () {
                this.drawPie('leiDaTu')
            })
            this.$nextTick(function () {
                this.drawPie2('leiDaTu2')
            })
        },
        handleSelectionChange(val) {
            this.sortInOrder = [];
            this.sortInOrderTop = [];
            this.getTableData = [];
            this.sortInOrde2 = [];
            this.multipleSelection = val;
            if (this.multipleSelection.length == 2) {
                this.fdcName1 = this.multipleSelection[0].wpName;
                this.fdcName2 = this.multipleSelection[1].wpName;
                this.sortInOrder.push(this.multipleSelection[0].fnlyl, this.multipleSelection[0].xqjsl,
                    this.multipleSelection[0].ztzhjsl, this.multipleSelection[0].fwjsl, this.multipleSelection[0].slssl,
                    this.multipleSelection[0].xnssl, this.multipleSelection[0].qfl, this.multipleSelection[0].jxssl,
                    this.multipleSelection[0].gzssl);
                this.sortInOrderTop.push(this.multipleSelection[1].fnlyl, this.multipleSelection[1].xqjsl,
                    this.multipleSelection[1].ztzhjsl, this.multipleSelection[1].fwjsl, this.multipleSelection[1].slssl,
                    this.multipleSelection[1].xnssl, this.multipleSelection[1].qfl, this.multipleSelection[1].jxssl,
                    this.multipleSelection[1].gzssl);
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    this.sortInOrde2.push({
                        product: this.multipleSelection[i].wpName, '限电损失电量单位:万KWh': this.multipleSelection[i].xdss,
                        '故障损失电量单位:万KWh': this.multipleSelection[i].gzss, '检修损失电量单位:万KWh': this.multipleSelection[i].jxssl,
                        '性能损失电量单位:万KWh': this.multipleSelection[i].xnssl, '受累损失电量单位:万KWh': this.multipleSelection[i].slss
                    });
                }
                this.getTableData.push({ index: '发电量', data1: this.multipleSelection[0].fdl, data2: this.multipleSelection[1].fdl });
                this.getTableData.push({ index: '故障损失电量', data1: this.multipleSelection[0].gzss, data2: this.multipleSelection[1].gzss });
                this.getTableData.push({ index: '检修损失电量', data1: this.multipleSelection[0].jxssl, data2: this.multipleSelection[1].jxssl });
                this.getTableData.push({ index: '性能未达标损失电量', data1: this.multipleSelection[0].xnsslfraction, data2: this.multipleSelection[1].xnsslfraction });
                this.getTableData.push({ index: '受累损失电量', data1: this.multipleSelection[0].slss, data2: this.multipleSelection[1].slss });
                this.getTableData.push({ index: '风能利用率', data1: this.multipleSelection[0].fnlyl, data2: this.multipleSelection[1].fnlyl });
                this.getTableData.push({ index: '故障损失率', data1: this.multipleSelection[0].gzssl, data2: this.multipleSelection[1].gzssl });
                this.getTableData.push({ index: '检修损失率', data1: this.multipleSelection[0].jxssl, data2: this.multipleSelection[1].jxssl });
                this.getTableData.push({ index: '弃风率', data1: this.multipleSelection[0].qfl, data2: this.multipleSelection[1].qfl });
                this.getTableData.push({ index: '性能损失率', data1: this.multipleSelection[0].xnssl, data2: this.multipleSelection[1].xnssl });
                this.getTableData.push({ index: '受累损失率', data1: this.multipleSelection[0].slssl, data2: this.multipleSelection[1].slssl });
                this.getTableData.push({ index: '复位及时率', data1: this.multipleSelection[0].fwjsl, data2: this.multipleSelection[1].fwjsl });
                this.getTableData.push({ index: '消缺及时率', data1: this.multipleSelection[0].xqjsl, data2: this.multipleSelection[1].xqjsl });
                this.getTableData.push({ index: '状态转换率', data1: this.multipleSelection[0].ztzhjsl, data2: this.multipleSelection[1].ztzhjsl });
            }
        },
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pagesize = val;
        },
        changeTableSort(column) {
            this.orderByColumn = column.prop;
            if (column.order == "descending") {
                this.isAsc = 'desc';
            } else if (column.order == "ascending") {
                this.isAsc = "asc";
            }
            this.FiveLossInformation();
        },
        FiveLossInformation() {
            let that = this;
            var newData = new Date();
            this.updateTime = this.BASE.getBzDate(newData.getTime(), 0);
            this.updateTime1 = this.BASE.getBzDate(newData.getTime(), -1);
            if (this.timedate == '') {
                this.timedate[0] = this.updateTime1;
                this.timedate[1] = this.updateTime;
                this.beginDate = this.timedate[0];
                this.endDate = this.timedate[1];
            } else {
                this.beginDate = this.timedate[0];
                this.endDate = this.timedate[1];
            }
            var fiveLossData = new URLSearchParams();
            fiveLossData.append('pageNum', this.currentPage2);
            fiveLossData.append('pageSize', this.pagesize);
            fiveLossData.append('orderByColumn', this.orderByColumn);
            fiveLossData.append('isAsc', this.isAsc);
            fiveLossData.append('wpId', this.value);
            fiveLossData.append('beginDate', this.beginDate);
            fiveLossData.append('endDate', this.endDate);
            this.API.post('/contrast/benchmarkLossList', fiveLossData).then((res) => {
                that.gridData = res.data;
                that.$refs.FiveLossRatesPieChart.getPackageData(that.gridData,that.value2);
                that.$refs.FiveLossRatesHistogramChart.getPackageData2(that.gridData);
            })
        },
        drawPie() {
            this.ECLZX.getFiveLossRadarMap("leiDaTu",[
                {
                    value: this.sortInOrder,
                    name: this.fdcName1
                },
                {
                    value: this.sortInOrderTop,
                    name: this.fdcName2
                }
            ]);
        },
        drawPie2() {
            this.ECLZX.getFiveLossRadarHistogram("leiDaTu2",['product', '限电损失电量单位:万KWh', '故障损失电量单位:万KWh', '检修损失电量单位:万KWh', '性能损失电量单位:万KWh', '受累损失电量单位:万KWh'],this.sortInOrde2);
        },
        toExcel() { }
    },
}