<template>
  <div>
    <div class="d-flex flex-between pt7">
      <div>
        <el-button type="primary" @click="exportAll">导出</el-button>
        <el-button
          type="danger"
          @click="delData"
          :disabled="multipleSelection.length == 0"
          >删除</el-button
        >
      </div>
      <el-form class="mt20" :inline="true">
        <el-form-item label="">
          <el-select
            v-model="firstForm.class"
            placeholder="请选择班级"
            clearable
            filterable
            @change="getListData"
          >
            <el-option
              v-for="item in classList"
              :label="item.class_name"
              :value="item.class_num"
              :key="item.class_id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="num">
          <!-- <el-select
            v-model="num"
            placeholder="请选择人数"
            @change="getListData"
          >
            <el-option
              v-for="item in numList"
              :label="item.label"
              :value="item.label"
              :key="item.value"
              clearable
              filterable
            ></el-option>
          </el-select> -->
          <el-input v-model="num" placeholder="请选择人数"> </el-input>
        </el-form-item>
        <el-button type="primary" @click="getListData">搜索</el-button>
        <!-- <el-button type="primary" class="ml5" @click="clearData">清空</el-button> -->
      </el-form>
    </div>

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

      <el-table-column label="学期学年" prop="team_name" width="450">
      </el-table-column>
      <el-table-column label="年级" prop="grade_name" width="">
      </el-table-column>
      <el-table-column label="班级" prop="class_name" width="">
      </el-table-column>
      <el-table-column label="人数" prop="num" align="" width="auto">
      </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 { rstjck_list, rstjck_del, class_search } from "./api";
import { useUserStore } from "@/stores/user";
const { token } = useUserStore();
export default {
  name: "index",
  data() {
    return {
      limit: 10,
      total: 12,
      cur_page: 1,
      class_id: "",
      class_name: "",

      num: "",
      firstForm: {
        class: "",
      },
      classList: [],
      tableData: [],

      numList: [
        {
          label: "20",
          value: "1",
        },
        {
          label: "50",
          value: "2",
        },
        {
          label: "60",
          value: "3",
        },
        {
          label: "70",
          value: "4",
        },
        {
          label: "80",
          value: "5",
        },
      ],
      title: "",
      team_id: "",
      grade_id: "",
      dept_id: "",
      loading: false,
      multipleSelection: [],
    };
  },

  methods: {
    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,
        team_id: this.team_id,
        dept_id: this.dept_id,
        class_id: this.firstForm.class,
        num: this.num,
      };

      rstjck_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);
      });
    },
    classListData() {
      let data = {
        page: 1,
        limit: 9999,
        grade_id: this.grade_id,
      };
      class_search(data).then((res) => {
        if (res.code == 1) {
          this.classList = res.data.page_data;
          // let obj = {
          //   class_id: "",
          //   class_name: "全部",
          // };
          // this.classList.unshift(obj);
        }
      });
    },
    delData() {
      this.$confirm("确认删除这些信息?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = {
            id: this.multipleSelection,
          };

          rstjck_del(data).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: "信息删除成功！",
                type: "success",
              });
              this.getListData();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => {});
    },

    handleSelectionChange(val) {
      this.multipleSelection = [];
      for (let i in val) {
        this.multipleSelection.push(val[i].id);
      }
    },

    exportAll() {
      let link =
        window.globalVariables.api +
        "/xddy/dygl_xsrstjlb_ck/index?api=xls&page=1&limit=10000&token=" +
        token;
      window.open(link, "_blank");
    },
    clearData() {
      this.firstForm.class = "";
      this.num = "";
    },
  },
  mounted() {
    this.team_id = this.$route.params.team_id;
    this.grade_id = this.$route.params.grade_id;
    this.dept_id = this.$route.params.dept_id;
    this.getListData();
    this.classListData();
  },
};
</script>

<style scoped>
</style>

  