<template>
  <div>
    <el-tabs
      type="border-card"
      :v-loading="loading">
      <el-tab-pane label="参保覆盖人员" v-loading="loading">
        <el-alert
          align="left"
          title="请上传格式完全相同的excel,格式如下:"
          type="warning"
          show-icon>
        </el-alert>
        <table style="text-align: center;border-collapse: collapse" cellspacing="0px" cellpadding="0px">
          <tr>
            <td style="border: 1px solid black">&nbsp;统筹区&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;街道或乡镇名称&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;社区名称&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;所属组&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;户口所在地&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;户口性质&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;个人编号&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;证件号码&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;姓名&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;性别&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;民族&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;出生日期&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;险种类型&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;参保状态&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;是否老农保&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;缴费状态&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;缴费档次&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;人员类别&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;离退休标志&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;个人身份&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;参保日期&nbsp;</td>
            <td style="border: 1px solid black">&nbsp;档案编号&nbsp;</td>
          </tr>
        </table>
        <el-upload
          style="margin-top: 10px"
          class="upload-demo"
          ref="upload1"
          :action="baseInfoUrl"
          multiple
          drag
          accept=".xls,.xlsx"
          :limit="5"
          :headers="myHeader"
          :before-upload="handleBeforeUpload"
          :file-list="fileList"
          :on-exceed="handleExceed"
          :on-success="uploadSuccess"
          :auto-upload="false">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件,一次最多只能上传5个文件</div>
        </el-upload>
        <el-button style="margin-top: 10px" size="small" type="success" @click="submitUpload1">数据导入</el-button>
      </el-tab-pane>
      <el-tab-pane label="缴费情况明细">
        <el-upload
          class="upload-demo"
          ref="upload2"
          action="/"
          multiple
          accept=".xls,.xlsx"
          :limit="5"
          :headers="myHeader"
          :before-upload="handleBeforeUpload"
          :file-list="fileList"
          :on-exceed="handleExceed"
          :auto-upload="false">
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload2">数据导入</el-button>
          <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件,一次最多只能上传5个文件</div>
        </el-upload>
      </el-tab-pane>
      <el-tab-pane label="领取人员">
        <el-upload
          class="upload-demo"
          ref="upload3"
          action="/"
          multiple
          accept=".xls,.xlsx"
          :limit="5"
          :headers="myHeader"
          :before-upload="handleBeforeUpload"
          :file-list="fileList"
          :on-exceed="handleExceed"
          :auto-upload="false">
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload3">数据导入</el-button>
          <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件,一次最多只能上传5个文件</div>
        </el-upload>
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      ref="dialog"
      :title="dialogTitle"
      width="30%"
      :visible.sync="dialogVisible">
      <span v-text="dialogContent" style="font-size: 16px"></span>
    </el-dialog>
  </div>
</template>

<script>
  import {baseUrl} from "../../utils/global";
  import Cookies from "js-cookie";

  let uploadedList = [];
  export default {
    name: "importByExcel",
    data() {
      return {
        baseInfoUrl: baseUrl + "/baseInfo/importFromNewExcel",
        myHeader: {
          token: Cookies.get("token")
        },
        fileList: [],
        dialogTitle: "",
        dialogVisible: false,
        dialogContent: "",
        loading: false
      };
    },
    methods: {
      submitUpload1() {
        this.$refs.upload1.submit();
      },
      submitUpload2() {
        this.$refs.upload2.submit();
      },
      submitUpload3() {
        this.$refs.upload3.submit();
      },
      handleExceed() {
        this.$message.warning("当前限制选择 1 个文件，请删除后继续上传");
      },
      handleBeforeUpload(file) {
        this.loading = true;
        if (!file.name.endsWith(".xls") && !file.name.endsWith(".xlsx")) {
          this.$message.warning(file.name + "不是excel文件");
          return false;
        }
        // if (uploadedList.includes(file.name)) {
        //   this.$message.warning(file.name + "已被选中过,请勿重复选择");
        //   return false;
        // }
        // uploadedList.push(file.name);
      },
      uploadSuccess(response) {
        this.dialogTitle = "导入结果";
        this.dialogContent = response.data;
        this.dialogVisible = true;
        this.loading = false;
        // console.log(response);
        // this.$alert(response.data, '导入结果', {
        //   confirmButtonText: '确定',
        //   callback: action => {
        //     // this.$message({
        //     //   type: 'info',
        //     //   message: `action: ${ action }`
        //     // });
        //   }
        // });
      }
    }
  }
</script>

<style scoped>

</style>
