<template>
  <BaseSameLayer
    :hosSameLayerArgs="hosSameLayerArgs"
    embedType="native/midea-pdf-view"
    :defaultWidth="300"
    :defaultHeight="300"
  ></BaseSameLayer>
</template>

<script>
import BaseSameLayer from "./baseSameLayer.vue";

export default {
  data() {
    return {
      width: 0,
      height: 0
    }
  },
  name: "MideaPdfView",
  components: {
    BaseSameLayer,
  },
  props: {
    hosUniqueProps: {
      type: Object,
      default() {
        return {};
      },
    },
    pdfPath: {
      type: String,  // android是pdfPath, ios为src, 后续可以做兼容
      require: true
    },
  },
  computed: {
    hosSameLayerArgs() {
      return {
        ...this.hosUniqueProps, // 鸿蒙原生组件独有属性
        width: this.width,
        height: this.height,
        pdfPath: this.pdfPath,
        pagestart: this.handlePagestart,
        pageprogress: this.handlePageprogress,
        pagefinish: this.handlePagefinish,
        pagefailed: this.handlePagefailed,
        retry: this.handleRetry,
      };
    },
  },
  mounted() {
    this.width = this.$el.clientWidth;
    this.height = this.$el.clientHeight;
  },

  methods: {
    // 自定义拓展其它逻辑
    handlePagestart(res) {
      this.$emit("pagestart", res);
    },
    handlePageprogress(res) {
      this.$emit("pageprogress", res);
    },
    handlePagefinish(res) {
      this.$emit("pagefinish", res);
    },
    handleRetry(res) {
      this.$emit("pagefailed", res);
    },
    handlePagefailed(res) {
      this.$emit("retry", res);
    },
  },
};
</script>
