<template>
    <div>
        <div v-for="item in fileList" :key="item.id">
            <el-button type="text" size="small" @click="uploaddown(item)" >{{item.name}}</el-button>
        </div>
    </div>
</template>
<script>
export default {
    props:{
        files :{required: false,type: String},
    },
    data() {
      return {
          fileList:[],
          params:{}
      }
    },
    methods:{
        uploaddown(v){
            this.$http({
                url: '/market/tvImport/download',
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                responseType: "blob",
                data: {"id": v.fileId, "fileName": v.name},
            }).then((response) => {
                if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    let blob = new Blob([response.data], {
                        type: 'application/vnd.ms-excel'
                    });
                    window.navigator.msSaveOrOpenBlob(blob, v.name);
                } else {
                    /* 火狐谷歌的文件下载方式 */
                    var blob = new Blob([response.data])
                    var downloadElement = document.createElement('a')
                    var href = window.URL.createObjectURL(blob);
                    downloadElement.href = href;
                    downloadElement.download = v.name;
                    document.body.appendChild(downloadElement);
                    downloadElement.click();
                    document.body.removeChild(downloadElement);
                    window.URL.revokeObjectURL(href);
                }
            });
        }
    },
    created(){
        if(this.files===""){
            this.fileList=[];
        }else{
            this.fileList = JSON.parse(this.files);
        }
    }
}
</script>
<style scoped lang="scss">
  
</style>
