<template>
  <div>
    <Upload
      ref='upload_excel'
      :action="this.$api.uploadExcel()"
      :data="{manager_access_token}"
      :on-success="handleSuccess"
      :format="['xls','xlsx']"
      :before-upload="handleBeforeUpload"
      :on-format-error="handleFormatError">
      <Button>上传文件</Button>
    </Upload>
  </div>
</template>

<script>
import { getStore } from "@/utils/utils";
export default {
  name: "upload_excel",
  data() {
    return {};
  },
  computed: {
    manager_access_token() {
      return getStore("userInfo").manager_access_token;
    }
  },
  methods: {
    handleSuccess(data, file) {
      if (data.code == 200) {
        this.$emit('saveurl',data.data.saveName)
        this.$Message.info("上传成功");
      } else {
        this.$Message.info(data.msg);
      }
    },
    handleFormatError(file) {
      this.$Message.error("上传的文件只允许xls、xlsx格式");
    },
    handleBeforeUpload() {
      const check = this.$refs.upload_excel.fileList;
      if (check.length&&check.length>0) {
        this.$Message.info("只能上传一个文件");
        return false;
      }else{
        return true;
      }
      
    }
  },
  created() {},
  mounted() {}
};
</script>
<style>
</style>