<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-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>
    <!-- <Mlc height="650px" :list="chartData" :units="chartUnit" :showLegend="true" /> -->
    <Lbc
      height="650px"
      :list="chartData"
      :units="chartUnit"
      :showLegend="true"
      :barMaxWidth="'4%'"
      :barGap="'150%'"
    />
  </div>
</template>

<script>
import ComTable from "@com/coms/table/table.vue";
import Lbc from "@com/chart/bar/multiple-bar-chart.vue";
import api from "@api/economic/index.js";
export default {
  // 名称
  name: "cutAnalyse",

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

  // 数据
  data() {
    const that = this;
    return {
      isAsc: "asc",
      typeArray: [
        {
          id: "1",
          name: "按报警统计",
        },
        {
          id: "2",
          name: "按报警分类统计",
        },
        {
          id: "3",
          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: "index",
            is_num: false,
            is_light: false,
            sortable: true,
          },
          {
            name: "名称",
            field: "name",
            is_num: false,
            is_light: false,
            sortable: true,
          },
          {
            name: "频率（次）",
            field: "frequencyday",
            is_num: false,
            is_light: false,
            sortable: true,
          },
        ],
        data: [],
      },
      chartData: [
        {
          title: "",
          yAxisIndex: 0,
          value: [],
        },
      ],
      chartUnit: ["(次)"],
    };
  },

  // 函数
  methods: {
    // 请求服务
    requestData() {
      let that = this;
      if (!that.typeId || !that.beginDate || !that.endDate) {
        that.BASE.showMsg({
          msg: "维度与日期不可为空",
        });
      } else {

        api.leaderboardQuerywarningStatistical({
         type: this.typeId,
            isAsc: this.isAsc,
            beginDate: this.beginDate,
            endDate: this.endDate,
            orderByColumn: "",
      }).then((res) => {
           let chartData = [];

            res.data.forEach((ele, index) => {
				if(ele.name != null){
					ele.index = i++;
					data.push(ele)
					chartData.push({
					  title: ele.name,
					  yAxisIndex: 0,
					  value: [
					    {
					      text: ele.name,
					      value: ele.frequencyday,
					    },
					  ],
					});
				}
            });

            this.chartData = chartData;
            this.tableData.data = res.data;
      });


        // that.API.requestData({
        //   method: "POST",
        //   subUrl: "leaderboard/querywarningStatistical",
        //   data: {
        //     type: that.typeId,
        //     isAsc: that.isAsc,
        //     beginDate: that.beginDate,
        //     endDate: that.endDate,
        //     orderByColumn: "",
        //   },
        //   success(res) {
        //     let chartData = [];

        //     res.data.forEach((ele, index) => {
        //       ele.index = index + 1;
        //       chartData.push({
        //         title: ele.name,
        //         yAxisIndex: 0,
        //         value: [
        //           {
        //             text: ele.name,
        //             value: ele.frequencyday,
        //           },
        //         ],
        //       });
        //     });

        //     that.chartData = chartData;
        //     that.tableData.data = res.data;
        //   },
        // });
      }
    },

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

  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>
