<template>
  <div>
    <el-form :inline="true">
      <el-form-item class="mr10" prop="xdfxx_xsxm" label="学生姓名">
        <el-input
          placeholder="输入学生姓名"
          v-model="xdfxx_xsxm"
          clearable
          @clear="getListData"
        ></el-input
      ></el-form-item>
      <el-form-item class="mr10" prop="xdfxx_xsxh" label="学籍号">
        <el-input
          placeholder="输入学籍号"
          v-model="xdfxx_xsxh"
          clearable
          @clear="getListData"
        ></el-input
      ></el-form-item>
      <el-form-item class="mr10" prop="xdfxx_fxzt" label="放学状态">
        <el-select v-model="xdfxx_fxzt" clearable @change="getListData">
          <el-option
            v-for="item in ztList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" class="ml5" @click="getListData"
        >搜索</el-button
      >
    </el-form>
    <el-button
      type="primary"
      @click="exportAll"
      :disabled="tableData.length == 0"
      >导出</el-button
    >

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      v-loading="loading"
      class="mt20"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>

      <el-table-column label="班级" prop="class_name" width="200">
      </el-table-column>
      <el-table-column label="放学日期" prop="xdfxx_fxrq" width="">
        <template slot-scope="scope">
          <span>{{ scope.row.xdfxx_fxrq.substr(0, 10) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学生姓名" prop="xdfxx_xsxm" width="">
      </el-table-column>
      <el-table-column label="学籍号" prop="xdfxx_xsxh" width="250">
      </el-table-column>
      <el-table-column label="性别" prop="xdfxx_xsxb" width="">
      </el-table-column>
      <el-table-column label="年龄" prop="xdfxx_xsnl" width="">
      </el-table-column>
      <el-table-column label="放学状态" prop="xdfxx_fxzt">
        <template slot-scope="scope">
          <span v-if="scope.row.xdfxx_fxzt_option_k == 1">已放学</span>
          <span v-if="scope.row.xdfxx_fxzt_option_k == 2" style="color: #26d48a"
            >滞留</span
          >
          <span v-if="scope.row.xdfxx_fxzt_option_k == 3" class="text-red"
            >留堂</span
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="setData(scope.row)">设置 </el-button> 
        </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 { xs_list, xs_export, xs_del } from "./api";
import { useUserStore } from "@/stores/user";
const { token } = useUserStore();
export default {
  name: "index",
  data() {
    return {
      limit: 10,
      total: 12,
      cur_page: 1,
      keyword: "",
      xdfxx_xsxm: "",
      xdfxx_xsxh: "",
      xdfxx_fxzt: "",
      ztList: [
        {
          label: "已放学",
          value: "1",
        },
        {
          label: "滞留",
          value: "2",
        },
        {
          label: "留堂",
          value: "3",
        },
      ],
      tableData: [],
      loading: false,
      multipleSelection: [],
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = [];
      for (let i in val) {
        this.multipleSelection.push(val[i].xdxx_xsxh);
      }
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    getListData() {
      this.loading = true;
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        grade_id: this.grade_id,
        xdfxx_xsxh: this.xdfxx_xsxh,
        xdfxx_fxrq: this.xdfxx_fxrq,
        xdfxx_xsxm: this.xdfxx_xsxm,
        xdfxx_fxzt: "1",
        xdfxx_fxzt: this.xdfxx_fxzt,
      };

      xs_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);
      });
    },

    exportAll() {
      let link =
        window.globalVariables.api +
        "/xddy/dygl_fxxt_xsfx_xs/index?api=xls&page=1&limit=10000&token=" +
        token;
      window.open(link, "_blank");
    },

    clearData() {
      this.xdfxx_xsxm = "";
      this.xdfxx_xsxh = "";
      this.xdfxx_fxzt = "";
    },
  },
  mounted() {
    this.getListData();
  },
};
</script>

<style scoped>
</style>