<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" @click="importAll">导入</el-button>
        <el-button type="primary" @click="exportAll" :disabled="multipleSelection.length == 0">导出</el-button>

      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="state_value">
          <el-select class="mr10" v-model="team_value" @change="getListData" filterable placeholder="学期">
            <el-option v-for="item in teamData" :key="item.id" :label="item.team_name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="state_value">
          <el-select class="mr10" v-model="school_value" @change="getListData" filterable placeholder="学校名称">
            <el-option v-for="item in schoolData" :key="item" :label="item" :value="item">
            </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" ref="multipleTable" @selection-change="handleSelectionChange" v-loading="loading" style="width: 100%">
      <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="jkda_xq_mc" width="auto"></el-table-column>
      <el-table-column label="学校" width="auto" prop="jkda_xs"></el-table-column>
      <el-table-column label="年级编号" width="80" prop="jkda_njbh"></el-table-column>
      <el-table-column label="班级编号" prop="jkda_bjbh" width="70">
      </el-table-column>
      <el-table-column label="班级名称" prop="jkda_bjmc" width="70">
      </el-table-column>
      <el-table-column label="学籍号" prop="jkda_xjh" width="80">
      </el-table-column>
      <el-table-column label="民族" prop="jkda_mz" width="60">
      </el-table-column>
      <el-table-column label="姓名" prop="jkda_xm" width="80">
      </el-table-column>
      <el-table-column label="性别" prop="jkda_xb" width="50">
      </el-table-column>
      <el-table-column label="出生日期" prop="jkda_csrq" width="auto">
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <!-- <el-button type="text" @click="editData(scope.row)">编辑 </el-button> -->
          <el-button type="text" @click="toDetail(scope.row.jkda_id)">详情
          </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>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" v-if="dialogFormVisible" width="580px">
      <el-form :model="dialogForm" ref="dialogForm" :rules="rules" label-width="80px">
        <el-form-item label="学期" prop="jkda_xq">
          <!-- <el-select class="mr10" v-model="dialogForm.jkda_xq" placeholder="请选择学期" >
            <el-option v-for="item in teamData" :key="item.id" :label="item.team_name" :value="item.id">
            </el-option>
          </el-select> -->
          <RemoteSelect url="/jcxx/team/index" v-model="dialogForm.jkda_xq" :label.sync="dialogForm.jkda_xq_mc" field='id,team_name' />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="formCancel">取 消</el-button>
        <el-upload class="upload-demo" :action="import_type_url" :data="{...dialogForm,token,issubmit:1}" :show-file-list="false" :on-success="import_success" style="display: inline-block; margin: 0 10px">
          <el-button type="primary">确 定</el-button>
        </el-upload>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { jkda_list, school_list, team_list, jkda_import } from "./api";
import { useUserStore } from "@/stores/user";
import RemoteSelect from "@/components/RemoteSelect/index.vue";
const { token } = useUserStore();
export default {
  name: "index",
  components: { RemoteSelect },
  data() {
    return {
      token,
      keyword: "",
      fl: [],
      tableData: [],
      limit: 10,
      total: 12,
      detailInfo: {},
      cur_page: 1,
      title: "",
      id: "",
      loading: false,
      multipleSelection: [],
      team_value: "",
      school_value: "",
      schoolData: [],
      teamData: [],
      file: '',
      // 导入导出
      // import_type_url:
      //   window.globalVariables.api +
      //   "/jdbg/jkda/import_standard?issubmit=1&token=" +
      //   token
      //   + "&jkda_xq=" + this.dialogForm.jkda_xq,
      // import_type_data: {},
      dialogFormVisible: false,
      dialogForm: {
        jkda_xq: "",
        jkda_xq_mc: "",
      },
      rules: {
        jkda_xq: [
          { required: true, message: "请选择学期", trigger: "blur" },
        ]
      }
    };
  },
  computed: {
    import_type_url() {
      return window.globalVariables.api + '/jdbg/jkda/import_standard'
      // +
      //   "/jdbg/jkda/import_standard?issubmit=1&token=" +
      //   token
      //   + "&jkda_xq=" + this.dialogForm.jkda_xq + "&jkda_xq_mc=" + this.dialogForm.jkda_xq_mc
    }
  },
  methods: {
    getListData() {
      this.loading = true;
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        jkda_xs: this.school_value,
        jkda_xq: this.team_value,
      };

      jkda_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);
      });
    },
    getSchoolListData() {
      this.loading = true;
      school_list().then((res) => {
        this.loading = false;
        this.schoolData = res.data.school;

      });
    },
    getTeamListData() {
      this.loading = true;
      team_list().then((res) => {
        this.loading = false;
        this.teamData = res.data.page_data;
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },

    formCancel() {
      this.dialogFormVisible = false;
    },
    importAll() {
      this.dialogFormVisible = true;
      this.dialogForm = {
        jkda_xq: "",
        jkda_xq_mc: ""
      }
    },
    import_success(r, file, fl) {
      console.log('import_success')
      this.loading = true;
      this.dialogFormVisible = false;
      this.getListData()
    },
    toDetail(id) {
      this.$router.push({
        name: "xstzjkda_detail",
        params: {
          id: id
        },
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = [];
      for (let i in val) {
        this.multipleSelection.push(val[i].jkda_id);
      }

    },
    exportAll() {
      let ids = this.multipleSelection.join(",");
      let link =
        window.globalVariables.api +
        "/jdbg/jkda/index?api=xls&page=1&limit=10000&token=" +
        token +
        "&jkda_id=" + ids
      window.open(link, "_blank");
    },

    //全部导出
    // exportAll() {
    //   let link =
    //     window.globalVariables.api +
    //     "/jdbg/jkda/index?api=xls&page=1&limit=10000&token=" +
    //     token
    //   window.open(link, "_blank");
    // },
  },
  mounted() {
    this.getListData();
    this.getTeamListData();
    this.getSchoolListData();
  },
};
</script>

<style scoped lang="scss">
.pop-content {
  width: 100%;
  height: 650px;
  overflow-y: auto;
}
</style>