<template>


  <el-dialog class="common-dialog" :fullscreen='isfullscreen' :title="title" :modal="false" top="2vh" :visible.sync="diaShow" @close="coloseDia"
    :width="width">
    <div slot="title">
      <span class="el-dialog__title">{{title}}</span>
      <slot name="searchtype"></slot>
    </div>

    <div class="dialogConcent" :style="{height:wheight+'px'}">
      <vue-office-docx v-if="urlType==='docx'"  :src="url" @rendered="renderingCompleted"></vue-office-docx>
      <vue-office-pdf v-if="urlType==='pdf'"  :src="url" @rendered="renderingCompleted"></vue-office-pdf>
      <vue-office-excel v-if="urlType==='excel'" :src="url" @rendered="renderingCompleted"></vue-office-excel>
      <iframe v-else id="iframeWin" :src="baseUrl+url" frameborder="0" scrolling="auto" align="center" class="iframeWeb">
      </iframe>
    </div>

    <div slot="footer" class="dialog-footer">
      <div>
        <el-button size="small" @click="coloseDia">关闭</el-button>

      </div>
      <slot name="footerbtn"></slot>
    </div>
  </el-dialog>

</template>

<script>
  import vueOfficeDocx from "@vue-office/docx"
  import vueOfficeExcel from "@vue-office/excel"
  import vueOfficePdf from "@vue-office/pdf"
  import '@vue-office/docx/lib/index.css'
  export default {
    components:{
      vueOfficeDocx,
      vueOfficeExcel,
      vueOfficePdf
    },
    props: {
      title: {
        type: String,
        default: "文件预览"
      },
      width: {
        type: String,
        default: "60%"
      },
      isShow: {
        type: Boolean,
        default: () => {
          return false
        }
      },
      type: {
        type: String,
        default: "showinfo"
      },
      url:{
        type: String,
        default: ""
      }
    },
    data() {
      return {
        diaShow: this.isShow,
        isfullscreen:false,
        baseUrl: "http://192.168.60.24:8012/onlinePreview?url=",
        wheight: "400",
        form:{
          show:''
        },
        urlType:'others'
      }
    },
    watch: {
      isShow(val) {
        this.diaShow = this.isShow;
      },
      url(val){
        console.log("url",val)
        if(val){
          if(val.includes('docx')||val.includes('DOCX')){
            this.urlType = 'docx'
          }else if(val.includes('pdf')||val.includes('PDF')){
            this.urlType = 'pdf'
          }else if(val.includes('xls')||val.includes('xlsx')||val.includes('XLS')||val.includes('XLSX')){
            this.urlType = 'excel'
          }else{
            this.urlType = 'others'
          }
          console.log('urltype',this.urlType)
        }
      }
    },
    methods: {
      renderingCompleted(){
        console.log("渲染完成")
      },
      coloseDia() {
        // this.url = ""
        this.diaShow = false
        this.$emit('update:isShow', false)
        this.$emit('resetform')
      }
    }
  }
</script>

<style scoped>
  /deep/ .show{
    flex-basis: 100%;
  }
  .dialogConcent {
    overflow-y: hidden;
  }

  .iframeWeb {
    text-align: center;
    border: none;
    display: block;
    height: 100vh;
    width: 100%;
  }
</style>
