<template>
  <div class="app-container">
    <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item :label="kindergartitle" prop="kindergartenName">
        <el-button
          @click="kindergartenshow = true"
          v-if="kindergartenName == '请选择幼儿园'"
          class="btn"
          style="color: #c0c4cc;"
        >{{ kindergartenName }}</el-button>
        <el-button @click="kindergartenshow = true" class="btn" v-else>{{ kindergartenName }}</el-button>
      </el-form-item>
    </el-form>
    <!-- //幼儿园 -->
    <el-dialog
      width="900px"
      title="选择所属幼儿园"
      :visible.sync="kindergartenshow"
      append-to-body
      :before-close="kindergartencancel"
    >
      <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
        <el-form-item label="幼儿园名称" prop="kindergartenName">
          <el-input
            style="width: 200px"
            v-model="kqueryParams.kindergartenName"
            placeholder="请输入幼儿园名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="kinhandleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="kinresetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="kindergartenList" @cell-dblclick="kindergartenNameclick">
        <el-table-column label="请选择" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="kindergartenNameclick(scope.row)"
              v-if="kindergartenId == scope.row.id"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="kindergartenNameclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column property="kindergartenName" label="幼儿园名字" align="center"></el-table-column>
        <el-table-column property="kindergartenAddress" label="幼儿园地址" align="center"></el-table-column>
        <el-table-column label="幼儿园所在组织" align="center" prop="organizeName"></el-table-column>
        <el-table-column property="contacts" label="联系人" align="center"></el-table-column>
        <el-table-column property="phone" label="联系电话" align="center"></el-table-column>
      </el-table>
      <pagination
        v-show="total1 > 0"
        :total="total1"
        :page.sync="kqueryParams.pageNum"
        :limit.sync="kqueryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div>
</template>
<script>
import {
  listKindergartenInfo,
  tKindergartenInfo
} from "@/api/system/kindergartenInfo";
import { getRoleInfo } from "@/api/system/quality";
export default {
  name: "kindergar",
  components: {},
  data() {
    return {
      kindergartitle: "所属幼儿园",
      total1: 0,
      //遮罩层
      kindergartenshow: false,
      // 显示搜索条件
      showSearch: true,
      // 表单参数
      form: {},
      //幼儿园查询参数
      kqueryParams: {
        pageNum: 1,
        pageSize: 10,
        organizeId: null,
        kindergartenName: null,
        kindergartenAddress: null,
        kindergartenType: null,
        phone: null,
        contacts: null
      },
      //幼儿园list
      kindergartenList: [],
      //幼儿园名字
      kindergartenName: "请选择幼儿园",
      //幼儿园ID
      kindergartenId: ""
    };
  },
  mounted() {},
  created() {
    this.getList();
    this.onshow();
  },
  methods: {
    onshow() {
      // this.kindergartenId = localStorage.getItem("kindergarId");
      if (localStorage.getItem("kindergarName") == null) {
        this.kindergartenName = "请选择幼儿园";
      } else {
        // this.kindergartenName = localStorage.getItem("kindergarName");
      }
      this.$emit("kinbatlist", this.kindergartenId);
    },
    //幼儿园左侧点击
    kindergartenNameclick(row) {
      this.kindergartenName = row.kindergartenName;
      this.kindergartenId = row.id;
      this.kindergartenshow = false;
      localStorage.setItem("kindergarName", this.kindergartenName);
      // localStorage.setItem("kindergarId", this.kindergartenId);
      this.$emit("kinbatlist", this.kindergartenId, 1);
    },
    //幼儿园关闭
    kindergartencancel() {
      this.kindergartenshow = false;
      this.kinresetQuery();
    },
    kinhandleQuery() {
      //获取幼儿园list
      listKindergartenInfo(this.kqueryParams).then(response => {
        this.kindergartenList = response.rows;
        this.total1 = response.total;
      });
    },
    kinresetQuery() {
      this.kqueryParams = {
        pageNum: 1,
        pageSize: 10,
        organizeId: null,
        kindergartenName: null,
        kindergartenAddress: null,
        kindergartenType: null,
        phone: null,
        contacts: null
      };
      this.kinhandleQuery();
    },
    getList() {
      //用户权限
      // getRoleInfo().then(res => {
      //   var user = res.data.roleKeys;
      //   if (user.includes("enchou")) {
      //     return;
      //   } else if (user.includes("teacher")) {
      //     if (res.data != 999999) {
      //       this.kindergartenId = res.data.kindergartenId;
      //       this.kindergartenName = res.data.kindergartenName;
      //       this.$emit("kinbatlist", this.kindergartenId, 0);
      //       localStorage.setItem("kindergarName", res.data.kindergartenName);
      //       localStorage.setItem("kindergarId", res.data.kindergartenId);
      //     }
      //     return;
      //   } else if (user.includes("parent")) {
      //     return;
      //   }
      // });
      //获取幼儿园list
      listKindergartenInfo(this.kqueryParams).then(response => {
        this.kindergartenList = response.rows;
        this.total1 = response.total;
      });
    },
    // 表单重置
    reset() {
      this.kindergartenName = "请选择幼儿园";
      this.kindergartenId = "";
    }
  }
};
</script>
<style scoped='scss'>
::v-deep .el-card__header {
  border: none;
}
.btn {
  width: 230px;
  text-align: left;
  height: 32px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 13px;
}
</style>
