<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="exportAll">
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button>
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="state_value">
          <el-select class="mr10" v-model="jjtx_xb" placeholder="全部" @change="getListData">
            <el-option value="" label="选择">全部</el-option>
            <el-option v-for="item in state_list" :key="item.v" :label="item.n" :value="item.v">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="keyword" clearable @clear="getListData">
          </el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索</el-button>
      </el-form>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" v-loading="loading" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column label="学校（单位）" prop="jjtx_uo_name"></el-table-column>
      <el-table-column label="姓名" prop="jjtx_xm"></el-table-column>
      <el-table-column label="性别" prop="jjtx_xb"></el-table-column>
      <el-table-column label="出生日期" prop="jjtx_csny"></el-table-column>
      <el-table-column label="年龄" prop="nl"></el-table-column>
      <el-table-column label="距离退休时长">
        <template slot-scope="scope">
          <span class="text-red">{{ scope.row.jjtx_jltxsc}}</span>
        </template>
      </el-table-column>
    </el-table>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total" :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>
  </div>
</template>

<script>
import {useUserStore} from "@/stores/user";

const {token} = useUserStore();
import { txjstx_list } from "./api";

export default {
  name: "index",
  data() {
    return {
      time: "",
      keyword: "",
      tableData: [],
      limit: 10,
      total: 0,
      cur_page: 1,
      dialogFormVisible: false,
      state_value: "",
      state_list: [
        {
          "v": "1",
          "n": "男"
        },
        {
          "v": "2",
          "n": "女"
        },
        {
          "v": "3",
          "n": "保密"
        }
      ],
      id: "",
      title: "",
      loading: false,
      jjtx_xb:'',
      multipleSelection: []
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = [];
      val.forEach(item=>{
        this.multipleSelection.push(item.jjtx_id)
      })
    },
    getListData() {
      this.loading = true;
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        jjtx_xb: this.jjtx_xb
      };
      txjstx_list(data).then((res) => {
        this.loading = false;
        this.tableData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    exportAll() {
      let link =
        window.globalVariables.api +
        "/jdbg/jsldgl_txjstx/index?api=xls&page=1&limit=10000&token=" +
        token + '&jjtx_id='+ this.multipleSelection.join(',');
      window.open(link, "_blank");
    },
  },

  mounted() {
    this.getListData();
  },
};
</script>

<style lang="scss" scoped>
</style>