<template>
  <div>
    <el-upload
      ref="uploadPicture"
      class="upload-demo"
      action="#"
      :file-list="searchData"
      :on-remove="handleRemove"
      :on-exceed="handleExceed"
      :on-change="changeUpload"
      multiple
      :limit="limit"
      :accept="picExt"
      :auto-upload="false"
    >
    <el-button slot="trigger" size="mini" type="primary">上传</el-button>
    <el-button style="margin-left: 10px;" size="mini" type="info" @click="uploadListView">查看</el-button>
    </el-upload>
    
  </div>
</template>
<script>
export default {
  name: "currenUploadList",
  props: {
    limit: {
      type: Number,
      default: 0
    },
    searchData: {
      type: Array,
      default: () => {
        return []
      }
    },
    picExt: {
      type: String,
      default: "",
    }
  },
  data () {
    return {
      isFileType: '',
    }
  },
  methods: {
    changeUpload (val) {
      // let suffix = val.name.substring(val.name.lastIndexOf('.') + 1)
      // if (this.picExt.indexOf(suffix) === -1) {
      //   this.$warningMsg('上传文件只能是 ' + this.picExt + '格式!')
      //   return false
      // }
      let rd = new FileReader(); // 创建文件读取对象
      let file = val.raw;
      this.$emit('changeUpload', file)
      rd.readAsDataURL(file); // 文件读取装换为base64类型
    },
    handleRemove (file, fileList) {
      this.$emit('handleRemove', fileList)
    },
    handleExceed (val) {
      this.$warningMsg('最多上传' + this.limit + '个文件')
    },
    uploadListView() {
      this.$emit('uploadListView')
    },
    submitUpload() {
      this.$refs.upload.submit();
    },
  }
}
</script>
