<template>
  <div>
    <div>
      <Upload
        :action="action"
        :on-success="_handelsuccess"
        :before-upload="_beupload"
        :on-progress="_handelprogress"
        :data="dataObj"
        :with-credentials="true"
        :show-upload-list="false"
      >
        <Button type="success">导入文件</Button>
      </Upload>
    </div>
    <div v-show="isLoad">
      <Spin fix>
        <Icon type="load-c" size=18 class="file-spin-icon-load"></Icon>
        <div>正在上传,请稍后...</div>
      </Spin>
    </div>
  </div>
</template>
<script>
/**
 * 添加编辑文件夹表
 */
import global from '../../../api/config'

export default {
  data() {
    return {
      action: '',
      dataObj: {
        file: '',
        contractId: ''
      },
      isLoad: false, // 是否显示loading...
      contractId: '' // 合同id
    }
  },
  methods: {
    _open(data) {
      this.isLoad = false
      this.contractId = data.id
      this.action = global.baseURL + data.uploadFileUrl + this.contractId
    },
    _beupload(file) {
      this.dataObj.file = file.name
    },
    _handelprogress(event, file, fileList) {
      this.isLoad = true
    },
    _handelsuccess(response, file, fileList) {
      // 上传成功
      if (response.success) {
        this.isLoad = false
        this.$Message.success('上传成功！')
        this.$emit('on-result-change')
      } else {
        this.isLoad = false
        this.$Message.error(response.msg)
      }
    }
  }
}
</script>
