<template>
  <div>
    <birt-work-book
      v-if="birtModel.controlName == 'BirtWorkBook'"
      :ref="birtModel.controlId"
      :conf="birtModel"
      :param="birtParam"
    />
    <!-- <birt-work-book
      v-for="wb in printPage"
      :key="wb.controlId"
      :ref="wb.controlId"
      :conf="wb"
      :param="birtParam"
    >
    </birt-work-book> -->
  </div>
</template>

<script>
import page from "./mixins/page";
import func from "./mixins/func";
import flow from "./mixins/flow";
import axios from 'axios';

export default {
  name: "birt-page",
  mixins: [page, func, flow],
  props: {
    conf: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      param: {},
      birtModel: {},
      birtParam: {},
      // printPage: [],
    };
  },
  methods: {
    // 获取报表workbook实例
    _getWorkBook() {
      return this.$refs[this.birtModel.controlId];
    },
    // 根据模型路径获取数据集实例对象
    _getStore(modelFilePath) {
      let wb = this._getWorkBook();
      if (wb) {
        let stores = wb.getStores();
        for (let i = 0, l = stores.length; i < l; i++) {
          let dsInsc = stores[i];
          if (dsInsc.modelFilePath == modelFilePath) {
            return dsInsc;
          }
        }
      }
    },
    // 应用地址栏参数
    applyRouteParam() {
      if (this.birtModel && this.birtModel.controlName) {
        let param = '';
        this._setParam(param);
        this._initPage();
      }
    },
    // 设置页面下推参数
    setWorkBookParam() {
      this.$nextTick(() => {
        let wb = this._getWorkBook();
        wb && wb.setParam(this.param);
        // this.$set(this, "birtParam", this.param);
        // this.birtParam = this.param;
      });
    },
  },
  created() {
    this.applyRouteParam();
  },
  mounted() {
    this.setWorkBookParam();
  },
};
</script>
