<template>
  <el-upload
    class="upload-demo"
    :on-change="handleFileChange"
    :http-request="handleClick"
    :show-file-list="false"
  >
    <Button size="small" type="text" @click="handleClick">票据导入</Button>
  </el-upload>
</template>

<script>
import moment from 'moment'
export default {
  props: {
    selectedRows: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      file: null,
    }
  },
  computed: {
    baseUrl() {
      return'http://10.2.9.28:8091'
    }
  },
  methods: {
    handleFileChange(file) {
      this.file = file
    },
    handleClick() {
      if (!this.file) return
      const param = new FormData()
      param.append('file', this.file.raw)
      param.append('ownerId', '0232228d-b2d2-4911-ace6-6a191b594439')
      param.append('ownerType', 'eis')
      param.append('category', `eis\\${moment().format('YYYYMMDD')}\\`)
      window.GMS.$http.post(
        `/yxgl/upload`,
        param,
        {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }
      ).then((res) => {
        if (res.data && res.data.code != 0) {
          this.$Message.error(res.data.msg)
        }
      }).finally(() => {
        this.file = null
        this.$emit('after-click')
      })
      return false
    },
  },
}
</script>

<style>

</style>