<template>
  <section>
    <!--搜索栏-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" @submit.native.prevent>
        <!-- <el-form-item label="姓名">
          <el-input v-model="keyword" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
        </el-form-item>
        <el-form-item label="课程名称">
          <el-input v-model="courseName" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
        </el-form-item> -->

        <el-button type="primary" size="small" style="float: right;margin-bottom: 10px" @click="exportExcel()"
          :loading="exportExcelLoading">导出</el-button>
      </el-form>
    </el-col>

    <!--表格-->
    <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
      <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
      <el-table-column prop="name" label="学员姓名" min-width="120" align="center"></el-table-column>
      <el-table-column prop="idNumber" label="证件号码" min-width="180" align="center"></el-table-column>
      <el-table-column prop="teachVeriPrice" label="培训费/认证费" min-width="150" align="center"></el-table-column>
      <el-table-column prop="materialPrice" label="资料费" min-width="120" align="center"></el-table-column>
      <el-table-column prop="other1Price" label="其他费用1" min-width="120" align="center"></el-table-column>
      <el-table-column prop="other2Price" label="其他费用2" min-width="120" align="center"></el-table-column>
      <el-table-column prop="payDate" label="打款日期" min-width="150" align="center"></el-table-column>
      <el-table-column prop="name" label="汇款方名称" min-width="180" align="center"></el-table-column>
      <el-table-column prop="receiveMoneyCompany" label="收款单位" min-width="150" align="center"></el-table-column>
      <el-table-column prop="payWay" label="打款方式" min-width="150" align="center"></el-table-column>
      <el-table-column prop="invoiceDate" label="开票日期" min-width="150" align="center"></el-table-column>
    </el-table>

    <!--分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 50, 100]" :page-size="size" layout="total, sizes, prev, pager, next" :total="total"
        style="float:right;"></el-pagination>
    </el-col>
  </section>
</template>

<script>
import { fixedDataGender, fixedDataCertificateType, fixedDataOrNot, fixedDataInvoiceSubject, fixedDatainvoiceType } from '../../common/js/fixedData'
export default {
  data() {
    return {
      // 搜索条件
      keyword: null,
      courseName: null,

      // 表格相关
      tableHeight: 0,
      listLoading: false,
      total: 0,
      page: 1,
      size: 20,
      list: [],
      exportExcelLoading: false
    }
  },
  methods: {
    exportExcel() {
      this.exportExcelLoading = true;
      this.http.post('/user-exam-info/exportInvoiceList', {
        // name: this.keyword,
        // courseName: this.courseName
      }, res => {
        if (res.code == "ok") {
          var filePath = res.data;
          const a = document.createElement('a'); // 创建a标签
          a.setAttribute('download', '学员缴费情况.xlsx');// download属性
          a.setAttribute('href', filePath);// href链接
          a.click(); //自执行点击事件
          a.remove();
        } else {
          this.$message({
            message: res.msg,
            type: "error"
          });
        }
      }, () => {
        this.exportExcelLoading = false;
      })
    },
    searchList() {
      this.page = 1;
      this.getList();
    },

    getList() {
      this.listLoading = true;
      this.http.post('/user-exam-info/getInvoiceList', {
        name: this.keyword,
        courseName: this.courseName,
        pageIndex: this.page,
        pageSize: this.size
      }, res => {
        this.list = (res.data.records || []).map(item => {
          const { sex, idType, invoiceType, isIndivdual } = item
          return {
            ...item
          }
        });
        this.total = res.data.total;
        this.listLoading = false;
      }, () => {
        this.listLoading = false;
      })
    },

    // 分页相关
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    handleSizeChange(val) {
      this.page = 1;
      this.size = val;
      this.getList();
    }
  },
  created() {
    let height = window.innerHeight;
    this.tableHeight = height - 195;
    const that = this;
    window.onresize = function temp() {
      that.tableHeight = window.innerHeight - 195;
    };
  },
  mounted() {
    this.getList();
  }
}
</script>

<style lang="scss" scoped>
.toolbar {
  padding-bottom: 10px;
}
</style>
