<template>
  <div class="zhc-birt-work-book">
    <birt-tool-bar
      ref="pageBar"
      v-if="isShowToolBar()"
      :total-page="this.conf.totalPage"
      @page-change="onPageChange"
    ></birt-tool-bar>
    <template v-if="isInitDataSources()"></template>
    <el-tabs
      v-if="isRenderTabs()"
      v-model="activeTabId"
      :tab-position="tabPosition"
      @tab-click="onTabClick"
    >
      <el-tab-pane
        v-for="sht in getSheets()"
        :label="sht.name"
        :name="sht.controlId"
        :key="sht.controlId"
      >
        <birt-cell-children
          :key="curtSheet.controlId"
          :children="getBirtCellChildren()"
          :style="getCurtSheetStyle()"
        />
      </el-tab-pane>
    </el-tabs>
    <birt-cell-children
      v-else-if="isRenderPages()"
      :key="curtSheet.controlId"
      :children="getBirtCellChildren()"
      :style="getCurtSheetStyle()"
    />
    <div :hidden="true">
      <birt-cell-children
        v-if="isRenderPrint() || isPrint"
        ref="printPages"
        :key="curtSheet.controlId"
        :children="getPrintChildren()"
        style=""
      />
    </div>
  </div>
</template>

<script>
import events from "@birt/components/mixins/events";

import autosize from "./mixins/autosize";
import datasource from "./mixins/datasource";
import dataset from "./mixins/dataset";
import save from "./mixins/save";
import param from "./mixins/param";
import toolbar from "./mixins/toolbar";
import sheet from "./mixins/sheet";
import tabs from "./mixins/tabs";
import pages from "./mixins/pages";
import print from "./mixins/print";

export default {
  name: "birt-work-book",
  mixins: [
    events,
    autosize,
    datasource,
    dataset,
    save,
    param,
    toolbar,
    sheet,
    tabs,
    pages,
    print,
  ],
  props: {
    conf: {
      type: Object,
      default: function () {
        return {};
      },
    },
    param: {
      type: Object | Array,
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      cmps: {},
      dialog: null,
    };
  },
  methods: {
    // 添加VUE组件实例引用
    addRefCmpt(vueCmpt) {
      if (vueCmpt) {
        let controlId = vueCmpt.conf && vueCmpt.conf.controlId;
        if (controlId) {
          this.cmps[controlId] = vueCmpt;
        }
      }
    },
    getEventId(eventId) {
      if (eventId === "afterLoad") {
        return "afterLoad";
      }
    },
    // 重新加载页面
    reload(param) {
      this.setParam(param);
      this.emit(this.getEventId("afterLoad"), param);
    },
    // 设置所在对话框上下文
    setDialog(dlg) {
      this.dialog = dlg;
    },
  },
};
</script>

<style lang="scss" scoped>
.zhc-birt-work-book {
  height: 100%;
  overflow: auto;
}
</style>
