<template>
  <div class="draught-fan-list">
    <div class="query mg-b-8">
			<div class="query-items">
        <div class="query-item">
					<div class="lable">类型：</div>
					<div class="search-input">
						<el-select v-model="typeId" clearable placeholder="请选择"
							popper-class="select" @change="renderWprray">
							<el-option v-for="item in typeArray" :key="item.id" :value="item.id" :label="item.name" />
						</el-select>
					</div>
				</div>
				<div class="query-item">
					<div class="lable">场站：</div>
					<div class="search-input">
						<el-select v-model="wpId" clearable placeholder="请选择"
							popper-class="select">
							<el-option v-for="item in wpArray" :key="item.id" :value="item.id" :label="item.name" />
						</el-select>
					</div>
				</div>
				<div class="query-item">
					<div class="lable">开始日期：</div>
					<div class="search-input">
						<el-date-picker v-model="beginDate" type="date"
							value-format="YYYY-MM-DD" placeholder="选择日期" popper-class="date-select">
						</el-date-picker>
					</div>
				</div>
        <div class="query-item">
					<div class="lable">结束日期：</div>
					<div class="search-input">
						<el-date-picker v-model="endDate" type="date"
							value-format="YYYY-MM-DD" placeholder="选择日期" popper-class="date-select">
						</el-date-picker>
					</div>
				</div>
			</div>
			<div class="query-actions">
				<button class="btn green" @click="search()">搜索</button>
			</div>
		</div>
    <div class="df-table">
      <ComTable height="100vh" :data="tableData"></ComTable>
    </div>
    <el-dialog title="切入切出风速整合历史" v-model="dialogShow" width="85%" top="10vh" custom-class="modal" :close-on-click-modal="true" @closed="dialogType = ''">
      <ComTable height="100vh" :data="tableHistoryData"></ComTable>
    </el-dialog>
  </div>
</template>

<script>
import ComTable from "@com/coms/table/table.vue";
export default {
  // 名称
  name: "cutAnalyse",

  // 使用组件
  components: {
   ComTable
  },

  // 数据
  data() {
    const that = this;
    return {
      isAsc:"asc",
      typeArray:[{
        id:"-1",
        name:"风场"
      },{
        id:"-2",
        name:"光伏电站"
      }],
      typeId:"-1",
      wpArray:[],
      wpId:"",
      beginDate:new Date((new Date().getTime() - 3600 * 1000 * 24)).formatDate("yyyy-MM-dd"),
      endDate:new Date().formatDate("yyyy-MM-dd"),
      dialogShow:false,
      tableData: {
        column: [
          {
            name: "风场",
            field: "windfarm",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "风机",
            field: "windturbine",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "起始日期",
            field: "beginDate",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "截止日期",
            field: "endDate",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "平均风速",
            field: "speed",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "平均功率",
            field: "power",
            is_num: false,
            is_light: false,
            sortable: true
          },
          {
            name: "平均效率",
            field: "generatingCapacity",
            is_num: false,
            is_light: false,
            sortable: true
          }
        ],
        data: [],
      }
    };
  },

  // 函数
  methods: {
    // 请求服务
    requestData() {
      let that = this;
      that.API.requestData({
        method: "GET",
        subUrl: "powercompare/windfarmAllAjax",
        data:{
          type:that.typeId
        },
        success(res) {
          that.allWpArray = res.data;
          that.renderWprray();
        }
      });
    },

    renderWprray(){
      let wpArray = [];
      this.allWpArray.forEach(ele=>{
        if(this.typeId === "-1"){
          if(ele.id.indexOf("FDC") !== -1){
            wpArray.push(ele);
          }
        }else{
          if(ele.id.indexOf("GDC") !== -1){
            wpArray.push(ele);
          }
        }
      });
      this.wpId = wpArray[0].id;
      this.wpArray = wpArray;
      this.getOutputSpeedList();
    },

    getOutputSpeedList(){
      let that = this;
      if(!that.typeId || !that.beginDate || !that.endDate){
        that.BASE.showMsg({
          msg:"类型与日期不可为空"
        });
      }else{
        that.API.requestData({
          method: "POST",
          subUrl: "leaderboard/loadfactortoplist",
          data:{
            wpId:that.wpId,
            type:that.typeId,
            isAsc:that.isAsc,
            beginDate:that.beginDate,
            endDate:that.endDate,
            orderByColumn:"",
          },
          success(res) {
            res.data.forEach(ele=>{
              ele.beginDate=new Date(ele.beginDate).formatDate("yyyy-MM-dd");
              ele.endDate=new Date(ele.beginDate).formatDate("yyyy-MM-dd");
            })
            that.tableData.data = res.data;
          }
        });
      }
      
    },

    search(){
      this.getOutputSpeedList(this.wpId);
    }
  },

  created() {
    this.requestData();
  },

  mounted() {},

  unmounted() {},
};
</script>

<style lang="less" scoped>
.draught-fan-list {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .btn-group-tabs {
    display: flex;
    flex-direction: row;

    .photovoltaic {
      margin-left: 1.481vh;
    }
  }

  .df-table {
    border: 0.093vh solid fade(@darkgray, 50%);
    position: relative;
    overflow: hidden;
    flex-grow: 1;
    margin-top: 1.481vh;
    height:80vh;

    &:before {
      content: "";
      width: 0.37vh;
      height: 0.37vh;
      background: @write;
      position: absolute;
      left: 0.278vh;
      top: 0.278vh;
    }

    tbody {
      height: calc(100vh - 166px);
    }
  }
}
</style>
