<template>
  <div class="app-container">
    <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="kindergartitle" prop="kindergartenName">
        <i class="el-icon-circle-close" @click="kindergartenicon" v-if="nameicon && nameicons"></i>
        <el-button
          @click="kindergartenshow = true"
          class="btn"
          :style="kindergartenName == '请选择幼儿园'?'color: #c0c4cc;':''"
        >{{ 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",
  props: ["iddnamelist", "nameicon"],
  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: "",
      nameicons: false
    };
  },
  mounted() {},
  created() {
    this.getList();
    this.reset();
    if (this.iddnamelist) {
      this.kindergartenId = this.iddnamelist.kindergartenId;
    }
    if (this.iddnamelist.kindergartenId) {
      this.nameicons = true;
    }
    if (this.iddnamelist.kindergartenName) {
      this.kindergartenName = this.iddnamelist.kindergartenName;
    }
  },
  watch: {
    iddnamelist: {
      handler(newlist, oldlist) {
        if (newlist.kindergartenId) {
          this.nameicons = true;
        }
        this.kindergartenId = newlist.kindergartenId;
        this.kindergartenName = newlist.kindergartenName;
      }
    }
  },
  methods: {
    kindergartenicon() {
      this.kindergartenName = "请选择幼儿园";
      this.kindergartenId = "";
      this.nameicons = false;
      if (this.kindergartenName != "请选择幼儿园") {
        this.$emit("kinbatlist", this.kindergartenId, this.kindergartenName);
      } else {
        this.$emit("kinbatlist", this.kindergartenId, "");
      }
    },
    resetlist() {
      this.kindergartenName = "请选择幼儿园";
      this.kindergartenId = "";
    },
    //幼儿园左侧点击
    kindergartenNameclick(row) {
      this.nameicons = true;
      this.kindergartenName = row.kindergartenName;
      this.kindergartenId = row.id;
      this.kindergartenshow = false;
      if (this.kindergartenName != "请选择幼儿园") {
        this.$emit("kinbatlist", this.kindergartenId, this.kindergartenName);
      } else {
        this.$emit("kinbatlist", this.kindergartenId, "");
      }
    },
    //幼儿园关闭
    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() {
      //获取幼儿园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;
}
::v-deep .el-icon-circle-close:before {
  position: absolute;
  left: 90%;
  top: 33%;
  color: #c0c8d3;
}
</style>
