<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
      <el-col :span="4">
        <el-upload
          class="upload-demo"
          :drag="true"
          :action="action"
          :file-list="fileList"
          multiple
          :headers="headers"
          :on-success="successFile"
          accept=".xls,.xlsx"
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将excel文件文件拖到此处，或<em>点击上传</em></div>
        </el-upload>
      </el-col>
      <el-col :span="8">
<!--        <div class="grid-content bg-purple"></div>-->
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-card class="box-card">
          <dataindex ref="dataindex" :t="t"/>
        </el-card>
      </el-col>
    </el-row>
  </div>


</template>

<script>
  import { getToken } from '@/utils/auth'

  import dataindex from '@/views/assets/bulkimport/dataindex.vue'

  export default {
    components: {
      dataindex
    },
    data() {
      return {
        t:Math.random(),
        action: process.env.VUE_APP_BASE_API + '/assets/bulkimport/importExcel',
        headers: {},
        fileList:[]
      }
    },
    created() {
      this.uploadData()
    },
    methods: {
      uploadData() {
        //让每个请求携带自定义token 请根据实际情况自行修改
        this.headers['Authorization'] = 'Bearer ' + getToken()
      },
      successFile(response, file, fileList){
        console.log(fileList)
        if(response.code!=200){
          this.msgError(response.msg)
          fileList.pop();
          this.fileList=fileList
        }else{
          this.msgSuccess(response.msg)
          this.t = Math.random()
        }
      }

    }
  }
</script>

<style rel="stylesheet/scss" lang="scss">
  .el-row {
    margin-bottom: 20px;
  &:last-child {
     margin-bottom: 0;
   }
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #fff;
  }
  .bg-purple {
    background: #fff;
  }
  .bg-purple-light {
    background: #fff;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #fff;
  }
</style>
