<template>
  <div v-if="attachments">
    <el-row v-for="(item, index) in attachments" :key="index">
      <el-col :span="24">
        <el-link type="primary" @click="handleDownload(item.path)">{{ item.name }}</el-link>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { download } from '@/api/data'
import { downloadFile } from '@/utils/index'

export default {
  name: 'DownloadAttachment',
  props: {
    attachments: {
      type: Array,
      require: true,
      default: null,
    },
  },
  data() {
    return {
      loading: false,
    }
  },
  methods: {
    handleDownload(path) {
      this.changeLoading(true)
      window.open(path)
      // download({ filePath: path })
      //   .then((res) => {
      //     downloadFile(res.data)
      //     this.changeLoading(false)
      //   })
      //   .catch((error) => {
      //     console.error(error)
      //     this.changeLoading(false)
      //   })
    },
    changeLoading(value) {
      this.loading = value
      this.$emit('update:loading', value)
    },
  },
}
</script>
  <style rel="stylesheet/scss" lang="scss" scoped>
</style>