<template>
  <div style="width: 240px;">
    <a-upload
      ref="upload"
      :action="url"
      :accept="'.xls'"
      :multiple="true"
      :headers="header"
      @change="handleChange"
    >
      <a-button type="primary"><a-icon type="upload" />{{ txt }}</a-button>
    </a-upload>
  </div>
</template>

<script>
export default {
  props: {
    url: {
      type: String,
      default: '',
    },
    txt: {
      type: String,
      default: '',
    },
  }, // 上传基础路径
  data() {
    return {
      header: {
        persId: localStorage.getItem('persId'),
        accessToken: localStorage.getItem('accessToken'),
      },
    };
  },
  computed: {
    userid() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {},
  methods: {
    handleChange(info, ...args) {
      if (info.file.status === 'done') {
        this.$message.success('上传成功!');
        this.$refs.upload.handleRemove(info.file);
      } else if (info.file.status === 'error') {
        this.$message.error('上传出错，请修改文件！');
        this.$refs.upload.handleRemove(info.file);
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
