<template>
  <el-button icon="el-icon-download" size="small" @click="clickDownload">下 载</el-button>
</template>

<script>
export default {
  props:['checklist'],
  data () {
    return {}
  },
  methods:{
    clickDownload () {
      this.checklist.forEach(e => {
        if (e.postfix === 'FOLDER') {
          this.downLoadFolder(e.attachmentid)
          this.$store.dispatch('createdownlog',{linksid:'',attachmentid:e.attachmentid})
        } else {
          this.dowFile(e.url)
          this.$store.dispatch('createdownlog',{linksid:'',attachmentid:e.attachmentid})
        }
      });
    },
    // 下载文件夹
    async downLoadFolder (id) {
      const res = await this.$api.requested({
        "classname": "system.attachment.huawei.OBS",
        "method": "createAndGetPackFileUrl",
        "content": {
            "attachmentid": id
        }
      })
      window.open(res.url, '_self');
    },
    
    // 一般附件下载
    dowFile (url) {
      window.open(url, '_self');
    }
  }
}

</script>
<style>
</style>