<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="24">
          <el-card style="height: 30px">
            <div class="grid-content bg-purple-dark">
              <span>电量绩效榜</span>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-header>

    <el-main>
      <el-card>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-row :gutter="1">
            <el-form-item label="风场">
              <el-input
                v-model="formInline.wpIds"
                id="windfarm"
                placeholder="风场"
              ></el-input>
            </el-form-item>

            <el-form-item label="项目">
              <el-input
                v-model="formInline.project"
                id="project"
                placeholder="项目"
                @focus="checkwindfarm"
              ></el-input>
            </el-form-item>

            <el-form-item label="线路">
              <el-input
                v-model="formInline.line"
                id="line"
                placeholder="线路"
                @focus="checkproject"
              ></el-input>
            </el-form-item>

            <el-form-item label="开始时间">
              <el-date-picker
                v-model="beginDate"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item label="结束时间">
              <el-date-picker
                v-model="endDate"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="queryPowerAll" :plain="true"
                >查询</el-button
              >
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="queryApDataMx"
                >明细信息</el-button
              >
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="toExcel">导出</el-button>
            </el-form-item>
          </el-row>
        </el-form>

        <el-tabs
          v-model="activeName"
          type="card"
          @tab-click="handleClick"
          style="height: 100%; width: 100%"
        >
          <el-tab-pane label="风场" name="first" id="fc">
            <el-row
              style="
                width: 100%;
                height: 100%;
                display: flex;
                justify-content: space-between;
              "
            >
              <el-card
                shadow="always"
                ref="fc_zzt_card"
                style="
                  height: 440px;
                  width: 45%;
                  display: table-cell;
                  vertical-align: middle;
                "
              >
                <div
                  id="histogram_fc"
                  ref="fc_zzt"
                  style="width: 800px; height: 400px; margin: auto"
                ></div>
              </el-card>

              <el-card
                shadow="always"
                style="width: 45%"
                height="400px"
                id="moban"
              >
                <el-table
                  id="fc_table"
                  :data="fc_date"
                  style="width: 100%"
                  max-height="400px"
                >
                  <el-table-column label="项目列表">
                    <el-table-column fixed type="index" width="45">
                    </el-table-column>
                    <el-table-column prop="wtName" label="名称" width="150">
                    </el-table-column>
                    <el-table-column
                      prop="total"
                      label="理论发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daydl2"
                      label="SCADA发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="dayspeed" label="风速" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhgzssdl"
                      label="非计划检修"
                      width="300"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhwhssdl"
                      label="计划检修"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="daynhcfdl" label="受累" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="限电"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="性能"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="lyl" label="风能利用率%" width="120">
                    </el-table-column>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="项目" name="second" id="xm">
            <el-row
              style="
                width: 100%;
                height: 100%;
                display: flex;
                justify-content: space-between;
              "
            >
              <el-card
                shadow="always"
                style="
                  height: 440px;
                  width: 45%;
                  display: table-cell;
                  vertical-align: middle;
                "
              >
                <div
                  id="histogram_xm"
                  style="width: 800px; height: 400px; margin: auto"
                ></div>
              </el-card>

              <el-card
                shadow="always"
                style="width: 45%"
                height="400px"
                id="moban"
              >
                <el-table
                  id="pj_table"
                  :data="pj_date"
                  style="width: 100%"
                  max-height="400px"
                >
                  <el-table-column label="项目列表">
                    <el-table-column fixed type="index" width="45">
                    </el-table-column>
                    <el-table-column prop="wtName" label="名称" width="150">
                    </el-table-column>
                    <el-table-column
                      prop="total"
                      label="理论发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daydl2"
                      label="SCADA发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="dayspeed" label="风速" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhgzssdl"
                      label="非计划检修"
                      width="300"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhwhssdl"
                      label="计划检修"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="daynhcfdl" label="受累" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="限电"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="性能"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="lyl" label="风能利用率%" width="120">
                    </el-table-column>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="集电线路" name="jdxl" id="jdxl">
            <el-row
              style="
                width: 100%;
                height: 100%;
                display: flex;
                justify-content: space-between;
              "
            >
              <el-card
                shadow="always"
                style="
                  width: 45%;
                  display: table-cell;
                  vertical-align: middle;
                "
              >
                <div
                  id="histogram_jdxl"
                  style="width: 800px;  margin: auto"
                  :style="{height : judge === true ? '1200px' : '600px'}"
                ></div>
              </el-card>

              <el-card
                shadow="always"
                style="width: 45%"
                height="400px"
                id="moban"
              >
                <el-table
                  id="xl_table"
                  :data="xl_date"
                  style="width: 100%"
                  max-height="600px"
                >
                  <el-table-column label="项目列表">
                    <el-table-column fixed type="index" width="45">
                    </el-table-column>
                    <el-table-column prop="wtName" label="名称" width="150">
                    </el-table-column>
                    <el-table-column
                      prop="total"
                      label="理论发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daydl2"
                      label="SCADA发电量"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="dayspeed" label="风速" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhgzssdl"
                      label="非计划检修"
                      width="300"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhwhssdl"
                      label="计划检修"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="daynhcfdl" label="受累" width="120">
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="限电"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="daynhxdssdl"
                      label="性能"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column prop="lyl" label="风能利用率%" width="120">
                    </el-table-column>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </el-main>
  </el-container>
</template>

<script>
import * as echarts from "echarts";
import excelHelper from "@/utils/excelHelper";
export default {
  data() {
    return {
      judge:true,
      autoHeight:1200,
      formInline: {
        wpIds: "NSS_FDC",
        project: "NSS01_GC",
        line: "NSS01_XL",
      },
      fc_date: [],
      pj_date: [],
      xl_date: [],
      beginDate: "2021-01-01",
      endDate: "2021-01-02",
      activeName: "first",
      tableid: "fc",
      celname: [],
      histogram_fc: {},
      histogram_xm: {},
      histogram_jdxl: {},
      table_fc: {},
      table_xm: {},
      table_jdxl: {},
      queryAll_querybutton: {},
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    handleClick(tab) {
      if (tab.name === "first") {
        this.tableid = "fc";
        this.query();
      } else if (tab.name === "second") {
        this.tableid = "pj";
        this.query();
      } else if (tab.name === "jdxl") {
        this.tableid = "xl";
        this.query();
      }
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    query() {
      this.fc_date = "";
      this.xl_date = "";
      this.pj_date = "";
      this.$http
        .get(
          "powercompare/queryPowerAll?wpIds=" +
            this.formInline.wpIds +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate +
            "&queryType=" +
            this.tableid
        )
        .then((res) => {
          let that = this;
          if (this.tableid === "fc") {
            that.drawhistogram_fc(res.data.data);
          } else if (this.tableid === "pj") {
            that.drawhistogram_pj(res.data.data);
          } else if (this.tableid === "xl") {
            this.autoHeight = 1200;
            that.drawhistogram_xl(res.data.data);
          }
        });
      //表格数据获取
      this.$http
        .get(
          "powercompare/powerAjaxAll?wpIds=" +
            this.formInline.wpIds +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate +
            "&queryType=" +
            this.tableid +
            "&sortName=" +
            this.formInline.wpIds +
            "&sortOrder=" +
            "Asc"
        )
        .then((res) => {
          let that = this;

          console.log(res);
          let queryAll_table = res.data.data;
          if (this.tableid === "fc") {
            that.fc_date = queryAll_table;
          } else if (this.tableid === "pj") {
            that.pj_date = queryAll_table;
          } else if (this.tableid === "xl") {
            that.xl_date = queryAll_table;
          }
        });
    },
    async queryPowerAll() {
      this.judge = false;
      this.autoHeight = 600;
      let that = this;
      if (this.beginDate == "" || this.endDate == "" || this.beginDate == undefined || this.endDate == undefined) {
        this.beginDate = "2021-01-01";
        that.endDate =  "2021-01-02";
        that.$message.error("请选时间！");
        return;
      }
      this.fc_date = "";
      this.xl_date = "";
      this.pj_date = "";
      
      if (
        that.formInline.wpIds == "" ||
        that.formInline.wpIds == null ||
        that.formInline.wpIds == undefined
      ) {
        that.query();
      } else {
        this.$http
          .get(
            "powercompare/queryPower?wpIds=" +
              this.formInline.wpIds +
              "&pjIds=" +
              this.formInline.project +
              "&lineIds=" +
              this.formInline.line +
              "&beginDate=" +
              this.beginDate +
              "&endDate=" +
              this.endDate
          )
          .then((res) => {
            let that = this;
            let queryAll = res.data.data;
            if (this.tableid === "fc") {
              that.drawhistogram_fc(queryAll);
            } else if (this.tableid === "pj") {
              that.drawhistogram_pj(queryAll);
            } else if (this.tableid === "xl") {
              that.drawhistogram_xl(queryAll);
            }
          });
        this.$http
          .get(
            "powercompare/powerAjax?wpIds=" +
              this.formInline.wpIds +
              "&pjIds=" +
              this.formInline.project +
              "&lineIds=" +
              this.formInline.line +
              "&beginDate=" +
              this.beginDate +
              "&endDate=" +
              this.endDate +
              "&sortName=" +
              this.formInline.wpIds +
              "&sortOrder=" +
              "Asc"
          )
          .then((res) => {
            let that = this;
            let queryAll_table = res.data.data;
            if (this.tableid === "fc") {
              that.fc_date = queryAll_table;
            } else if (this.tableid === "pj") {
              that.pj_date = queryAll_table;
            } else if (this.tableid === "xl") {
              that.xl_date = queryAll_table;
            }
          });
      }
    },
    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;
      }
    },
    checktime() {
      if (new Date(this.timedate) == null) {
        this.$message.error("请选择时间");
        return;
      }
    },
    queryApDataMx() {
      this.$router.push({ path: "/new_performanceList_fan" });
    },
    toExcel() {
            let that = this;
            if (this.tableid === "fc") {
            excelHelper.exportExcel("fc_table","fc数据",".xls",true);
            } else if (this.tableid === "pj") {
            excelHelper.exportExcel("pj_table","pj数据",".xls",true);
            } else if (this.tableid === "xl") {
            excelHelper.exportExcel("xl_table","xl数据",".xls",true);
            }
      
    },
    drawhistogram_fc(date) {
      this.chartLine = echarts.init(document.getElementById("histogram_fc"));

      var option;
      option = {
        title: {
          text: "风机绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "总和",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
        },
        yAxis: {
          type: "category",
          data: date.names,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sfdl,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.whdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.gzdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.xddl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sldl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: date.qfdl,
            },
            emphasis: {
              focus: "series",
            },
            data: date.qfdl,
          },
          //曲线
          {
            name: "总和",
            data: date.yfdl,
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
    drawhistogram_pj(date) {
      this.chartLine = echarts.init(document.getElementById("histogram_xm"));
      var option;

      var option;
      option = {
        title: {
          text: "风机绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "总和",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
        },
        yAxis: {
          type: "category",
          data: date.names,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sfdl,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.whdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.gzdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.xddl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sldl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: date.qfdl,
            },
            emphasis: {
              focus: "series",
            },
            data: date.qfdl,
          },
          //曲线
          {
            name: "总和",
            data: date.yfdl,
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
    drawhistogram_xl(date) {
      this.chartLine = echarts.init(document.getElementById("histogram_jdxl"));
      this.chartLine.clear();
      this.chartLine.resize({height: this.autoHeight})
      var option;

      var option;
      option = {
        title: {
          text: "风机绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "总和",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
        },
        yAxis: {
          type: "category",
          data: date.names,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sfdl,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.whdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.gzdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.xddl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.sldl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: date.qfdl,
            },
            emphasis: {
              focus: "series",
            },
            data: date.qfdl,
          },
          //曲线
          {
            name: "总和",
            data: date.yfdl,
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
  },
  mounted() {
    this.query();
  },
};
</script>
<style scoped>
.bg-purple-dark {
  background: #fff;
}
.grid-content {
  border-radius: 2px;
  min-height: 36px;
  margin-top: -15px;
}
.item {
  margin-top: 10px;
  margin-right: 40px;
}
.el-row {
  margin: 10px;
}
</style>
