<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="所属幼儿园" prop="categoryName">
        <el-button
          @click="kindergartenshow = true"
          v-if="kindergartenName == '请选择幼儿园'"
          style="
            width: 230px;
            text-align: left;
            height: 32px;
            color: #c0c4cc;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          "
          >{{ kindergartenName }}</el-button
        >
        <el-button
          @click="kindergartenshow = true"
          style="width: 230px; text-align: left; height: 32px"
          v-else
          >{{ kindergartenName }}</el-button
        >
      </el-form-item>

      <el-form-item label="所属批次" prop="categoryName">
        <el-button
          @click="batchCodeshowclick"
          style="width: 230px; text-align: left; height: 32px; color: #c0c4cc"
          v-if="batchName == '请选择批次'"
          >{{ batchName }}</el-button
        >
        <el-button
          @click="batchCodeshowclick"
          style="width: 230px; text-align: left; height: 32px"
          v-else
          >{{ batchName }}</el-button
        >
      </el-form-item>
    </el-form>

    <!-- //批次 -->
    <el-dialog
      width="700px"
      title="选择批次"
      :visible.sync="batchCodeshow"
      append-to-body
      style="margin-top: 20px"
      :before-close="batchCodecancel"
    >
      <el-form
        :model="testqueryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="90px"
      >
        <el-form-item label="批次编号" prop="batchCode">
          <el-input
            v-model="testqueryParams.batchCode"
            placeholder="请输入批次编号"
            clearable
          />
        </el-form-item>
        <el-form-item label="批次名称" prop="batchCode">
          <el-input
            v-model="testqueryParams.batchName"
            placeholder="请输入批次名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="testScore"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="testresetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table
        :data="testScorelist"
        align="center"
        style="margin-top: 0px"
        @cell-dblclick="batchCodeclick"
      >
        <el-table-column label="请选择" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 20px; height: 20px"
              v-if="batchCode == scope.row.batchCode"
              circle
              @click="batchCodeclick(scope.row)"
            ></el-button>
            <el-button
              v-else
              style="width: 15px; height: 15px"
              circle
              @click="batchCodeclick(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          property="batchCode"
          label="批次编号"
          width="230"
          align="center"
        />
        <el-table-column
          property="batchName"
          label="批次名称"
          width="230"
          align="center"
        />
      </el-table>
      <pagination
        v-show="total4 > 0"
        :total="total4"
        :page.sync="testqueryParams.pageNum"
        :limit.sync="testqueryParams.pageSize"
        @pagination="testScore"
      />
    </el-dialog>

    <!-- //幼儿园 -->
    <el-dialog
      width="850px"
      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="请选择" width="70" 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="幼儿园名字"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="kindergartenAddress"
          label="幼儿园地址"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="幼儿园所在组织"
          align="center"
          prop="organizeName"
          width="150"
        >
        </el-table-column>
        <el-table-column
          property="contacts"
          label="联系人"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          property="phone"
          label="联系电话"
          width="150"
          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, testScoreBatch } from "@/api/system/quality";

export default {
  name: "",
  components: {},
  data() {
    return {
      total1: 0,
      total4: 0,
      //遮罩层
      kindergartenshow: false,
      batchCodeshow: 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: "",
      //批次名称
      batchCode: "",
      batchName: "请选择批次",
      //批次list
      testScorelist: [],
      //批次编号
      testqueryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  mounted() {},
  created() {
    this.getList();
    this.onshow();
  },
  methods: {
    onshow() {
      this.batchCode = localStorage.getItem("batchCode2");
      this.batchName = localStorage.getItem("batchName2");
      this.kindergartenId = localStorage.getItem("kindergartenId");
      if (localStorage.getItem("kindergartenName") == null) {
        this.kindergartenName = "请选择幼儿园";
        this.batchCode = "请选择批次";
      } else {
        this.kindergartenName = localStorage.getItem("kindergartenName");
      }
      if (localStorage.getItem("batchCode2") == null) {
        this.batchCode = "请选择批次";
      } else {
        this.batchCode = localStorage.getItem("batchCode2");
      }
      this.$emit("kinbatlist", this.kindergartenId, this.batchCode);
    },

    //幼儿园左侧点击
    kindergartenNameclick(row) {
      this.kindergartenName = row.kindergartenName;
      this.kindergartenId = row.id;
      this.kindergartenshow = false;
      localStorage.setItem("kindergartenName", this.kindergartenName);
      localStorage.setItem("kindergartenId", this.kindergartenId);
      this.$emit("kinbatlist", this.kindergartenId, this.batchCode, 1);
    },

    //点击批次左边
    batchCodeclick(row) {
      this.batchCode = row.batchCode;
      this.batchName = row.batchName;
      this.batchCodeshow = false;
      localStorage.setItem("batchCode2", this.batchCode);
      localStorage.setItem("batchName2", this.batchName);
      if (this.kindergartenId != "") {
        this.$emit("kinbatlist", this.kindergartenId, this.batchCode, 2);
      }
    },
    //点击批次
    batchCodeshowclick() {
      this.testScore();
      this.batchCodeshow = true;
    },
    //批次
    testScore() {
      testScoreBatch(this.testqueryParams).then((res) => {
        this.testScorelist = res.rows;
        this.total4 = res.total;
      });
    },
    testresetQuery() {
      this.testqueryParams = {
        pageNum: 1,
        pageSize: 10,
        batchCode: "",
        batchName: "",
      };
      this.testScore();
    },
    //批次关闭
    batchCodecancel() {
      this.batchCodeshow = false;
      this.testresetQuery();
    },
    //幼儿园关闭
    kindergartencancel() {
      this.kindergartenshow = false;
      this.kinresetQuery();
    },
    kinhandleQuery() {
      //获取幼儿园list
      listKindergartenInfo(this.kqueryParams).then((response) => {
        this.kindergartenList = response.rows;
        this.total1 = response.total;
        // console.log(this.kindergartenList);
      });
    },
    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;
        console.log(user);
        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, this.batchCode, 0);
            localStorage.setItem("kindergartenName", res.data.kindergartenName);
            localStorage.setItem("kindergartenId", res.data.kindergartenId);
          }
          return;
        } else if (user.includes("parent")) {
          return;
        }
      });
      tKindergartenInfo(this.kindergartenType).then((res) => {
        this.type = res.data[0];
        this.type2 = res.data[1];
      });

      //获取幼儿园list
      listKindergartenInfo(this.kqueryParams).then((response) => {
        this.kindergartenList = response.rows;
        this.total1 = response.total;
        // console.log(this.kindergartenList);
      });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
  },
};
</script>
<style scoped='scss'>
::v-deep .el-card__header {
  border: none;
}
</style>
