<template>
    <el-button icon="el-icon-delete" size="small" @click="clickDelete">删 除</el-button>
</template>

<script>
export default {
  props:['checklist'],
  data () {
    return {
      filecount:0
    }
  },
  methods:{
    clickDelete () {
      this.filecount = 0
      this.$confirm(`确定删除这${this.checklist.length}个文件吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.checklist.forEach(e => {
          this.deleteFiles(e.attachmentid)
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    },
    async deleteFiles (id) {
      this.filecount ++
      let param  = {
        "classname": "system.attachment.MediaCenter",
        "method": "deleteAttachment",
        "content": {
          "attachmentid": id
        }
      }
      const res = await this.$api.requested(param)
      this.checklist.length === this.filecount?this.$emit('onSuccess'):''
    }
  },
  watch:{
    filecount (val) {
      if (this.checklist.length === val) {
        this.$message({
          message:`成功,共删除${this.checklist.length}个文件`,
          type:'success'
        })
      }
    }
  }
}

</script>
<style>
</style>