<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>学员列表
    </h2>
    <div class="m-core">
      <!-- <div class="newBand">声部调整</div> -->
      <!-- 搜索标题 -->
      <el-form :inline="true"
               class="searchForm"
               v-model="searchForm">
        <el-form-item>
          <el-input placeholder="家长联系电话"
                    @keyup.enter.native='onSearch'
                    v-model="searchForm.search"></el-input>
        </el-form-item>
        <el-form-item prop='organId'>
          <el-select class='multiple'
                     v-model="searchForm.organId"
                     clearable
                     placeholder="请选择分部">
            <el-option v-for="(item,index) in organList"
                       :key="index"
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input placeholder="学生姓名"
                    @keyup.enter.native='onSearch'
                    v-model="searchForm.studentName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="onSearch"
                     type="danger">搜索</el-button>
          <el-button @click="onReSet"
                     type="primary">重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 列表 -->
      <div class="tableWrap">
        <el-table :data='tableList'
                  :header-cell-style="{background:'#EDEEF0',color:'#444'}">
          <el-table-column align='center'
                           prop="userId"
                           label="学员编号">
          </el-table-column>
          <el-table-column align='center'
                           prop="realName"
                           label="学员姓名">
          </el-table-column>
          <el-table-column align='center'
                           label="性别">
            <template slot-scope="scope">
              {{ scope.row.gender ? '男': '女' }}
            </template>
          </el-table-column>
          <el-table-column align='center'
                           prop="parentsName"
                           label="家长姓名">
          </el-table-column>
          <el-table-column align='center'
                           prop="parentsPhone"
                           label="家长联系电话">
          </el-table-column>
          <el-table-column align='center'
                           prop="courseBalance"
                           label="课程余额(元)">
          </el-table-column>
          <el-table-column align='center'
                           label="操作">
            <template slot-scope="scope">
              <router-link style="color:#409EFF"
                           v-permission="'/studentDetail'"
                           :to="{path:`/business/studentDetail?userId=${scope.row.userId}`,query:{search:JSON.stringify(searchForm),rules:JSON.stringify(pageInfo)}}">查看</router-link>

            </template>
          </el-table-column>
        </el-table>
        <pagination :total="pageInfo.total"
                    :page.sync="pageInfo.page"
                    :limit.sync="pageInfo.limit"
                    :page-sizes="pageInfo.page_size"
                    @pagination="getList" />
      </div>
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { queryStudentList } from '@/api/studentManager'
import { getEmployeeOrgan } from '@/api/buildTeam'
import store from '@/store'
export default {
  name: 'studentList',
  components: { pagination },
  data () {
    return {
      searchForm: {
        organId: null,
        search: null,
        studentName: null
      },
      searchList: [],
      tableList: [],
      organList: [],

      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
    }
  },
  mounted () {
    if (this.$route.query.search) {
      this.$route.query.search instanceof Object ? this.searchForm = this.$route.query.search : this.searchForm = JSON.parse(this.$route.query.search);
    }
    if (this.$route.query.rules) {
      this.$route.query.rules instanceof Object ? this.pageInfo = this.$route.query.rules : this.pageInfo = JSON.parse(this.$route.query.rules);
    }
    getEmployeeOrgan().then(res => {
      if (res.code == 200) {
        this.organList = res.data;
      }
    })
    this.getList();
  },
  methods: {
    onSearch () {
      this.pageInfo.page = 1;
      this.getList()
    },
    getList () {
      let params = this.searchForm
      params.rows = this.pageInfo.limit
      params.page = this.pageInfo.page
      params.organId ? params.organId : params.organId = null;
      queryStudentList(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    onReSet () {
      this.searchForm = {
        organId: null,
        search: null,
        studentName: null
      }
    }
  }
}
</script>
<style lang="scss">
</style>