<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 prop="courseName" label="项目名称" min-width="180" align="center"></el-table-column>
      <el-table-column prop="invoiceType" label="发票类型" min-width="180" align="center">
        <template slot-scope="scope">
          {{ scope.row.invoiceType === 1 ? '增值税普通发票' : '增值税专用发票' }}
        </template>
      </el-table-column>
      <el-table-column prop="invoiceHeader" label="开票名称" min-width="150" align="center"></el-table-column>
      <el-table-column prop="taxCode" label="税号" min-width="120" align="center"></el-table-column>
      <el-table-column prop="address" label="地址" min-width="120" align="center"></el-table-column>
      <el-table-column prop="phone" label="电话" min-width="120" align="center"></el-table-column>
      <el-table-column prop="" label="开户行" min-width="150" align="center"></el-table-column>
      <el-table-column prop="" label="银行账号" min-width="180" align="center"></el-table-column>
      <el-table-column prop="email" label="邮箱" min-width="150" align="center"></el-table-column>
      <el-table-column prop="" label="备注" min-width="150" align="center"></el-table-column>
      <el-table-column prop="courseName" label="商品名称" min-width="150" align="center"></el-table-column>
      <el-table-column prop="" label="单位" min-width="150" align="center">
        <template slot-scope="scope">
          次
        </template>
      </el-table-column>
      <el-table-column prop="" label="数量" min-width="150" align="center">
        <template slot-scope="scope">
          1
        </template>
      </el-table-column>
      <el-table-column prop="money" label="单价（元）" min-width="150" align="center"></el-table-column>
      <el-table-column prop="money" label="金额（元）" min-width="150" 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="150" align="center"></el-table-column>
      <el-table-column prop="money" 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,
        invoiceType: '',
      }, res => {
        if (res.code == "ok") {
          var filePath = res.data;
          const a = document.createElement('a'); // 创建a标签
          a.setAttribute('download', '学员缴费情况.xls');// 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,
        invoiceType: '',
        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>
