<template>
  <div>
    <div style="margin:100px auto 10px auto;text-align: center">
      <div>
        <Upload
          multiple
          :action="action"
          :on-success="_handelsuccess"
          :before-upload="_beupload"
          :data="dataObj"
          :headers="headers"
          :with-credentials="true"
          :show-upload-list="false"
        >
          <img src="../../../assets/file-add.png" height="100">
        </Upload>
      </div>
      <p style="margin:10px auto">请选择附件上传</p>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        summaryId: '',
        action: '',
        dataObj: {
          file: '',
        },
        headers: '',
      }
    },
    mounted() {
      this._getQuery();
    },
    methods: {
      _getQuery() {
        this.summaryId = this.$route.query.summaryId;
        this.action = this.$global.baseURL + '/drs/v1/sampling_summary_attachment/' + this.summaryId;
        this.headers = {'accessToken': localStorage.getItem('accessToken')};
      },
      //web
      _beupload(file) {
        this.dataObj.file = file.name;
        this.$toast.loading({
          message: '加载中...',
          forbidClick: true,
        });
      },
      _handelsuccess(response) { //上传成功
        this.$toast.clear();
        if (response.success) {
          this.$toast('上传成功');
          this.$router.go(-1);
        } else {
          this.$toast('上传失败');
        }
      },
    }
  }
</script>
