<template>
  <div>
    <div
      v-for="(attachment, index) in attachmentList"
      :key="index"
      @click.native="downLoadAttachment(attachment)"
    >
      <div>
        <span>
          <rt-icon
            name="rt-xrm-jpg"
            size="45"
            v-if="attachment.Type=='png'||attachment.Type=='jpg'||attachment.Type=='gif'||attachment.Type=='bmp'"
          ></rt-icon>
          <rt-icon
            name="rt-xrm-xls"
            size="45"
            v-else-if="attachment.Type=='xls'||attachment.Type=='xlsx'"
          ></rt-icon>
          <rt-icon
            name="rt-xrm-word"
            size="45"
            v-else-if="attachment.Type=='doc'||attachment.Type=='docx'||attachment.Type=='wps'"
          ></rt-icon>
          <rt-icon name="rt-xrm-pdf" size="45" v-else-if="attachment.Type=='pdf'"></rt-icon>
          <rt-icon
            name="rt-xrm-ppt"
            size="45"
            v-else-if="attachment.Type=='ppt'||attachment.Type=='pptx'"
          ></rt-icon>
          <rt-icon name="rt-xrm-txt" size="45" v-else-if="attachment.Type=='txt'"></rt-icon>
          <rt-icon name="rt-xrm-music" size="45" v-else-if="attachment.Type=='mp4'"></rt-icon>
          <rt-icon name="rt-xrm-unknown" size="45" v-else></rt-icon>
        </span>
        <div class="annexname" @click="downLoadAttachment(attachment)">{{attachment.FileName}}</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'rtAttachmentShow',
  props: {
    attachmentList: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      docinfo: null,
      tenantCode: this.$store.state.auth.tenantCode,
      token: this.$store.state.auth.accessToken
    };
  },
  methods: {
    downLoadAttachment(doc) {
      this.docinfo = doc;
      rt.confirm('是否打开附件？').then(resp => {
        this.openAttachment();
      });
    },
    openAttachment() {
      let baseUrl = rt.getBaseURL();
      var fileExt = this.docinfo.FileName.substring(this.docinfo.FileName.lastIndexOf('.') + 1);
      var url =
        baseUrl +
        'FileDownloadHandler.ashx?moduleType=weekly_report&fileid=' +
        this.docinfo.Id +
        '&filename=' +
        this.docinfo.FileName +
        '&fileext=' +
        fileExt +
        '&issharefile=false&tenantcode=' +
        this.tenantCode +
        '&token=' +
        this.token;
      window.open(url, '打开附件', 'toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no', true);
    }
  }
};
</script>

<style scoped lang="less">
.annexname {
  font-size: 14px;
  position: relative;
  display: inline-block;
  top: -10px;
  width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
