<template>
  <el-dialog
    title="详情"
    :visible.sync="visible"
    v-if="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    width="80%"
  >
    <div>
      <iframe
        :src="fileUrl"
        width="100%"
        style="height: calc(70vh - 20px); margin-top: 30px"
        frameborder="0"
        allowfullscreen="true"
      ></iframe>
    </div>

    <div slot="footer">
      <el-button @click="handleClose"> 关闭 </el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    components: {},
    mixins: [],

    data() {
      return {
        fileType: 1,
        fileUrl: '',
        visible: false
      };
    },
    computed: {},
    mounted() {},
    methods: {
      setFileUrl(row) {
        console.log(row);
        let file = row.storagePath[0];
        let url = sessionStorage.filePath + file.storePath;
        const fileExt = file.name.substr(file.name.lastIndexOf('.') + 1);
        this.fileType = this.getFileType().includes(fileExt) ? 2 : 1;
        if (this.fileType == 2) {
          this.fileUrl =
            '/fm/' +
            (['dxf', 'dwg'].includes(fileExt) ? '2DViewer' : '3DViewer') +
            '/view.html?url=' +
            sessionStorage.filePath +
            '/' +
            row.outputNdsFiles;
        } else {
          if (process.env.NODE_ENV === 'development') {
            this.fileUrl =
              'http://192.168.1.251:51001/kkfile/onlinePreview?url=' +
              btoa(url);
          } else {
            this.fileUrl = '/kkfile/onlinePreview?url=' + btoa(url);
          }
        }
        this.visible = true;
      },

      getFileType() {
        return [
          'par',
          'asm',
          'psm',
          'dft',
          'sldprt',
          'sldasm',
          'ipt',
          ' iam',
          'prt',
          '3dxml',
          'CATPart',
          'CATProduct',
          'cgr',
          'model',
          'exp',
          'session',
          'x_t',
          'xmt_txt',
          'x_b',
          'xmp_bin',
          'xmp_txt',
          'sat',
          '.sab',
          '.igs',
          'iges',
          'stp',
          'step',
          'jt',
          'xcgm',
          '3dm',
          'stl',
          'obj',
          '3mf',
          'fbx',
          'vda',
          'dxf',
          'dwg',
          'pdf',
          'idf',
          'idb',
          'emn',
          'brd'
        ];
      },

      handleClose() {
        this.visible = false;
      }
    }
  };
</script>

<style lang="scss" scoped></style>
