<style lang="scss">
	.area{
		.el-select{
			width: 120px;
			display: inline-block;
			margin-right: 6px;
		}
	}
</style>
<template>
  <section class="content">
    <div class="breadcrumb">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item><a href="/">学校管理</a></el-breadcrumb-item>
            <el-breadcrumb-item>班级管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <el-form :model="queryParams" size="mini" label-width="80px" class="filter-form" :inine="true">
      <el-row>
        <el-col :span="4">
          <el-form-item label="学校">
			  <el-select placeholder="请选择学校">
			    <!-- <el-option label="高三一班" value="高三一班">高三一班</el-option> -->
			  </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="年级" v-model="queryParams.grade_id">
            <el-select placeholder="请选择年级">
              <!-- <el-option label="高三一班" value="高三一班">高三一班</el-option> -->
            </el-select>
          </el-form-item>
        </el-col>
		<el-col :span="4">
		  <el-form-item label="创建时间" v-model="queryParams.grade_id">
		    <el-date-picker
		          v-model="queryParams.ctime"
		          type="datetime"
		          placeholder="选择日期时间">
		    </el-date-picker>
		  </el-form-item>
		</el-col>
        <el-col :span="11">
          <el-form-item label-width="10" style="margin-left: 10px">
            <el-button type="primary" @click="getData" size="mini"
              >搜索</el-button
            >
            <el-button
              type="info"
              size="mini"
              @click="handleAdd"
              >重置</el-button
            >
			<el-button style="float: right;"
			  type="primary"
			  plain 
			  icon="el-icon-plus"
			  size="mini"
			  @click="handleAdd"
			  >添加班级</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%; margin-top: 10px"
      height="50vh"
    >
      <el-table-column align="center" prop="name" label="班级名称" />
      <el-table-column align="center" prop="phone" label="年级" />
      <el-table-column label="所属学校">
      </el-table-column>
      <el-table-column label="教师人数"></el-table-column>
	  <el-table-column label="学生人数"></el-table-column>
      <el-table-column align="center" prop="ctime" label="创建时间" />
      <el-table-column align="center" prop="date" label="操作" width="320">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row.id)" size="mini" type="info" plain
            >编辑</el-button
          >
          <el-button @click="del(scope.row.id)" size="mini" type="info" plain
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <Page
      ref="pageButton"
      :current="form.page"
      :page_size="form.page_size"
      :total="total"
      @pageChange="gopage"
    />
    <!-- 新增班级-->
	<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
	  <el-form   ref="form" :model="form" :rules="rules" label-width="80px">
		<el-form-item label="所属学校" prop="name">
		  <el-select
		    v-model="form.parent_id"
		    placeholder="请选择学校"
		    clearable
		    filterable  
		  >
		    <el-option
		      v-for="item in doctorList"
		      :key="item.value"
		      :label="item.name"
		      :value="item.id"
		    >
		    </el-option>
		  </el-select>
		</el-form-item>
	    <el-form-item label="所属年级">
	      <el-select 
	        v-model="form.parent_id"
	        placeholder="请选择"
	        clearable
	        filterable  
	      >
	        <el-option
	          v-for="item in doctorList"
	          :key="item.value"
	          :label="item.name"
	          :value="item.id"
	        >
	        </el-option>
	      </el-select>
	    </el-form-item>
	    
	    <el-form-item label="班级数量" prop="">
			<el-input-number v-model="form.number" controls-position="right"  :min="1" >			
			</el-input-number>
	    </el-form-item>
	
	    <el-form-item label="班级名称" prop="hospital_name">
	      <el-input
	        clearable
	        v-model="form.hospital_name"
	        placeholder="请输入班级名称"
	      ></el-input>
	    </el-form-item>
	  </el-form>
	  <div slot="footer" class="dialog-footer">
	    <el-button type="primary" @click="submitForm">保存</el-button>
	    <el-button @click="open = false">取 消</el-button>
	  </div>
	</el-dialog>
  </section>
</template>
<script>
import Page from "../../components/Page";
export default {
  components: {
    Page,
  },
  data() {
    return {
      loading: false,
      queryParams: {
        page: 1,
      },
      form: {},
      form1: {},
      form2: {},
      list: [{}, {}],
      total: 0,
      title: "新增学校",
      open: false,
	  open2: false,
      doctorList: [],
      rules: {},
    };
  },
  methods: {
    del(id) {
      this.$confirm("确认删除?", "提示", {
        type: "warning",
      }).then(() => {
        this.$api
          .delDoctorInfo({
            id: id,
          })
          .then((res) => {
            if (!res.data.code) {
              this.$msgSuccess("删除成功");
              this.getData();
            } else {
              this.$msgError(res.data.message);
            }
          });
      });
    },
    gopage(size) {
      if (size) {
        this.queryParams.page_size = size;
      }
      this.queryParams.page = this.$refs.pageButton.page;
      this.getData();
    },
    getData() {
      this.loading = true;
      this.$api.getDoctorsList(this.queryParams).then((res) => {
        this.list = res.data.data.list;
        this.total = res.data.data.total;
        this.loading = false;
      });

      this.$api
          .getDoctorsSearchList({
          })
          .then((res) => {
            this.doctorList = res.data.data;
            this.$set(this.doctorList, res.data.data);
            // this.loading = false;
          });
    },
    handleAdd() {
      this.open = true;
      this.title = "新增班级";
      this.form = {};
    },
    edit(id) {
      this.title = "编辑";
      this.$api
        .getDoctorInfo({
          id: id,
        })
        .then((res) => {
          this.form = res.data.data;
          this.open = true;
        });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            this.$api.editDoctorInfo(this.form).then((res) => {
              if (res.data.code == 0) {
                this.msgSuccess("成功!");
                this.open = false;
                this.getData();
              } else {
                this.msgError(res.data.message);
              }
            });
          } else {
            this.$api.addDoctorInfo(this.form).then((res) => {
              if (res.data.code == 0) {
                this.msgSuccess("成功!");
                this.open = false;
                this.getData();
              } else {
                this.msgError(res.data.message);
              }
            });
          }
        }
      });
    },
    remoteMethod(query) {
      if (query !== "") {
        // this.loading = true;
        this.$api
          .getDoctorsSearchList({
            name: query,
          })
          .then((res) => {
            this.doctorList = res.data.data;
            this.$set(this.doctorList, res.data.data);
            // this.loading = false;
          });
      } else {
        this.doctorList = [];
      }
    },
  },
  created() {
    this.getData();
    
  },
};
</script>