<!--  -->
<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      学校账号管理
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
        ref="saveForm"
      >
        <el-form-item>
          <el-input
            v-model.trim="searchForm.search"
            clearable
            @keyup.enter.native="
              (e) => {
                e.target.blur();
                $refs.saveForm.save();
                search();
              }
            "
            placeholder="老师姓名/编号/手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="organId">
          <el-select
            style="width: 180px !important"
            class="multiple"
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="search">
          <el-select
            v-model.trim="searchForm.search"
            :disabled="!searchForm.organId"
            filterable
            clearable
            placeholder="请选择合作单位"
          >
            <el-option
              v-for="(item, index) in cooperationList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column align="center" prop="studentId" label="编号"></el-table-column>
          <el-table-column align="center" prop="studentId" label="分部"></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="合作单位"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="老师姓名"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="账号类型"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="账号状态"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="联系电话"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="studentId"
            label="注册日期"
          ></el-table-column>
          <el-table-column align="center" prop="studentId" label="操作"></el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
import pagination from "@/components/Pagination/index";
import load from "@/utils/loading";
import { getTimes } from "@/utils";
import { queryByOrganId } from "@/api/systemManage";
import { courseType, courseListType } from "@/utils/searchArray";
export default {
  components: { pagination },
  data() {
    return {
      searchForm: {
        search: null,
        organId: null,
        courseType: null,
      },
      courseType,
      tableList: [],
      organList: [],
      cooperationList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    // 获取分部
    this.$store.dispatch("setBranchs");
    this.init();
  },
  methods: {
    init() {},
    getList() {
      let { timer, ...rest } = this.searchForm;
      let params = {
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(timer, ["startTime", "endTime"]),
      };
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {},
  },
  watch: {
    "searchForm.organId"(val) {
      if (val) {
        queryByOrganId({ organId: val }).then((res) => {
          if (res.code == 200) {
            this.cooperationList = res.data;
          }
        });
      }
    },
    // "searchForm.cooperationId"(val) {
    //   if (val) {
    //     getMusicGroup({ cooperationId: val }).then((res) => {
    //       this.musicList = res.data;
    //     });
    //   }
    // },
  },
};
</script>
<style lang="scss" scoped></style>
