<template>
  <!-- 学生评价 -->
  <div ref="tabs" class="wrapper">
    <!-- 搜索框开始 -->
    <div class="search">
      <van-search v-model.trim="userName" placeholder="学生姓名" />
    </div>
    <div style="height: 54px;width: 100%;"></div>

    <!-- 模糊搜索页面 -->
    <div class="searchPage" v-if="searchList.length">
      <!-- <selects :listContent="classLists" :tit="'请选择班级'"></selects> -->
      <div class="students">
        <div class="stuBlock" v-for="(i, index) in searchList" :key="index + 'p'" @click="gotoStudentDetail2(i)">
          {{ i.username }}
        </div>
      </div>
    </div>

    <div>
      <van-tabs
        @change="cutPage"
        v-if="!searchList.length"
        :swipeable="true"
        :lazy-render="true"
        @click="spread"
        @touchmove.stop="handleTouchMove"
      >
        <van-tab v-for="(e, index) in classLists" :key="index + 't'" :name="e.id" :title="e.name">
          <!-- <classList :claName="i"></classList> -->
          <div class="students">
            <div class="stuBlock" v-for="(i, index) in stuList" :key="index + 'p'" @click="gotoStudentDetail(i.id, e)">
              {{ i.name }}
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import { selectClassStudent } from '@/api/eva'
import { selectSerStudent } from '@/api/eva'
import { select_techerAllClass } from '@/api/eva'
// import classList from './components/classList.vue'
// 多选框组件
// import selects from './components/selects.vue'

export default {
  // components: { selects },
  data() {
    return {
      // 搜索栏数据
      userName: '',
      // 班级名称数组
      classLists: [],

      // 班级学生数组
      stuList: [],
      // 搜索结果数组
      searchList: [],
      scorllTaps: null
    }
  },
  watch: {
    userName(val) {
      // console.log(val)
      if (val !== '') {
        this.likeSearch(val)
      } else {
        this.searchList = []
      }
    }
  },
  methods: {
    handleTouchMove(event) {
      event.preventDefault()
    },
    likeSearch(e) {
      console.log(e)
      const data = {
        id: this.$store.state.user.userinfo.organizeid,
        txt: e
      }
      selectSerStudent(data).then(res => {
        // console.log('res', res)
        this.searchList = res[0]
        if (!res[0].length) {
          this.searchList = [{ username: '暂时没有您想要查询的学生' }]
        }
      })
    },
    // 切换导航栏获取数据
    cutPage(e) {
      // this.claName.id = e
      selectClassStudent({ cid: e }).then(res => {
        // console.log('res', res)
        this.stuList = res[0]
      })
    },
    // 班级入口跳转详情页
    gotoStudentDetail(e, i) {
      // e学生id，i班级id
      localStorage.setItem('userId', e)
      localStorage.setItem('classId', i.id)
      this.$router.push(`/studentDetail?cid=${i.id}`)
    },
    // 搜索按钮跳转详情页
    gotoStudentDetail2(i) {
      localStorage.setItem('userId', i.userid)
      localStorage.setItem('classId', '')
      this.$router.push('/studentDetail')

      // this.$router.push('/searchstuDetail')
    },
    spread(name, tit) {
      // console.log(5555);
      // return console.log('spread', name)
      // selectClassStudent({ cid: name }).then(res => {
      //   console.log('res', res)
      //   this.stuList = res[0]
      // })
    },
    // 获取老师所管理班级
    getData() {
      const id = this.$store.state.user.userinfo.organizeid
      select_techerAllClass({ cid: id }).then(res => {
        // console.log('获取老师所管理班级学生', res)
        this.classLists = res[0]
        // 调用一次，将导航栏数据展示出来
        this.cutPage(this.classLists[0].id)
      })
    }
  },
  // beforeRouteEnter(to, from, next) {
  //   document.addEventListener(
  //     'touchmove',
  //     function(event) {
  //       event.preventDefault()
  //     },
  //     false
  //   )
  //   next(vm => {})
  // },
  mounted() {},
  created() {
    this.getData()
    // console.log('state', this.$store.state)
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  height: 100%;
  width: 100%;
  overflow: hidden;
}
/deep/ .van-tab {
  width: 100px;
  text-align: center;
}

/deep/ .van-tabs__line {
  width: 90px;
  height: 2px;
  flex-shrink: 0;
  background: #4a8efc;
}

/deep/ .van-tab__pane {
  height: calc(100vh - 150px);
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
}

.searchPage {
  width: 100%;
  height: calc(100vh - 125px);
  // background-color: #4a8efc;
  box-sizing: border-box;
  // margin-top: 20px;
  min-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}

.search {
  position: fixed;
  top: 0;
  width: 100%;
  // height: 54px;
}

.students {
  width: 95%;
  display: flex;
  // justify-content: space-between;
  flex-wrap: wrap;
  margin: 10px;

  .stuBlock {
    min-width: 100px;
    margin-top: 10px;
    margin-right: 15px;
    display: flex;
    box-sizing: border-box;
    padding: 4px 5px;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    background: #f6fafb;
    color: rgba(0, 0, 0, 0.9);
    font-family: Microsoft YaHei;
    font-size: 14px;
    font-style: normal;
  }
}

// 搜索框开始
.searchBlock {
  width: 100%;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(232, 232, 235, 1);

  // 搜索框结束
}

.claTit {
  margin-top: 20px;
  margin-left: 10px;
  width: 130px;
  height: 30px;
  line-height: 20px;
  color: rgba(16, 16, 16, 1);
  font-size: 14px;
  text-align: left;
  font-family: PingFangSC-regular;
}
</style>
