<template>
  <div>
    <div class="containerTop">
      <bm-search-bar-complete
        @getSearch="getSearch"
        @handleExport="handleExport"
      />
    </div>
    <div class="containerBottom">
      <div class="smallTitle">凯盛玻璃控股指标完成情况</div>
      <bm-bar-complete
        :chartHeight="chartHeight"
        :legendList="legendList"
        :chartMsg="chartMsg"
        :chartId="chartId"
        :chartNum="chartNum"
      />
      <base-table
        :table-props="tableProps"
        :page="listQuery.current"
        :limit="listQuery.size"
        :table-data="tableData"
        :max-height="tableH"
      />
    </div>
  </div>
</template>

<script>
import BmSearchBarComplete from "./components/bmSearchBarComplete.vue";
import BmBarComplete from "./components/bmBarComplete.vue";
const tableProps = [
  {
    prop: "factory",
    label: "指标名称",
    // filter: (val) => factoryList[val],
  },
  {
    prop: "unit",
    label: "单位",
  },
  {
    prop: "time1",
    label: "时间1",
  },
  {
    prop: "time2",
    label: "时间2",
  },
];
export default {
  name: "CompletionStatusIntrBM",
  data() {
    return {
      tableProps,
      listQuery: {
        current: 1,
        size: 1000,
      },
      tableData: [
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
        { factory: "工厂1" },
      ],
      chartHeight: this.tableHeight(269) / 2,
      tableH: this.tableHeight(269) / 2,
      legendList: [
        { id: 1, name: "2023年4月", type: 1, color: "#288AFF33" },
        { id: 2, name: "2024年4月", type: 1, color: "#288AFF" },
      ],
      chartMsg: {
        color: ["#288AFF33", "#288AFF"],
        xData: ["成都", "邯郸", "瑞昌"],
        yName: "单位/MW",
        series: [
          {
            name: "2023年4月",
            data: [5505, 6578, 5500],
            type: "bar",
            barWidth: 20,
            label: {
              show: true,
              position: "top",
              color: "#2789FF",
            },
          },
          {
            name: "2024年4月",
            data: [3503, 3456, 4500],
            type: "bar",
            barWidth: 20,
            barGap: "-100%",
            label: {
              show: true,
              position: "top",
              color: "#288AFF",
            },
          },
        ],
      },
      chartId: "completionStatusIntrBMChart",
      chartNum: 1,
    };
  },
  components: {
    BmBarComplete,
    BmSearchBarComplete,
  },
  computed: {
    isOpen() {
      return this.$store.getters.sidebar.opened;
    },
  },
  watch: {
    // 监听左侧菜单栏是否展开
    isOpen(val) {
      if (this.$route.name === "CompletionStatusIntrBM") {
        this.chartNum++;
      }
    },
  },
  created() {
    this.tableH = this.tableHeight(269) / 2;
    this.chartHeight = this.tableHeight(269) / 2;
    window.addEventListener("resize", this._setTableHeight);
  },
  destroyed() {
    window.removeEventListener("resize", this._setTableHeight);
  },
  activated() {
    // 图重新加载，为了防止窗口变化后尺寸图显示不佳，数据不更新
    if (this.$route.name === "CompletionStatusIntrBM") {
      this.chartNum++;
    }
  },
  methods: {
    _setTableHeight() {
      this.tableH = this.tableHeight(269) / 2;
      this.chartHeight = this.tableHeight(269) / 2;
      if (this.$route.name === "CompletionStatusIntrBM") {
        this.chartNum++;
      }
    },
    getSearch(val) {
      console.log(val);
      console.log("=========================");
    },
    handleExport() {
      console.log("导出");
    },
  },
};
</script>

<style lang="scss" scoped>
.containerTop {
  height: 64px;
}
.containerTop,
.containerBottom {
  position: relative;
  background-color: #fff;
  border-radius: 8px;
  padding: 16px;
}
.containerBottom {
  height: calc(100vh - 201px);
  margin-top: 8px;
  .smallTitle {
    font-size: 16px;
    color: #000;
    margin-bottom: 15px;
  }
  .smallTitle::before {
    display: inline-block;
    width: 4px;
    height: 16px;
    background: #0b58ff;
    content: "";
    margin-right: 8px;
    vertical-align: -3px;
  }
}
</style>
