<template>
  <div class="mainBase">

    <el-select class="mr-10px" v-model="normal_school" placeholder="请选择学校" size="large" @change="(name)=>{ handelOption(name,'scholl')}">
      <el-option label="全部" value="0" />
      <el-option v-for="item in school_list" :key="item.value" :label="item.label" :value="item.value"  />
    </el-select>

    <el-select class="mr-10px" v-model="normal_classroom" placeholder="请选择班级" size="large" @change="(name)=>{ handelOption(name,'grade')}">
      <el-option label="全部" value="0" />
      <el-option v-for="item in classroom_list" :key="item.value" :label="item.label" :value="item.value" />
    </el-select>

    <el-select class="mr-10px" v-model="normal_subject" placeholder="请选择学科" size="large"  @change="(name)=>{ handelOption(name,'subject')} " >
      <el-option label="全部" value="0" />
      <el-option v-for="item in subject_list" :key="item.value" :label="item.label" :value="item.value" />
    </el-select>

  </div>
</template>

<script setup lang="ts">
import {ksjh_detail } from '@/pages/ksfx/apiItem';
import { defineProps,defineEmits } from 'vue';
const props = defineProps(['normal_school','normal_subject','normal_classroom','school_list','classroom_list','subject_list']);
const emit = defineEmits(['optionClick'])
const route = useRoute();


let normal_school =ref();
let normal_subject = ref();
let normal_classroom = ref();

let school_list = ref([]);
let classroom_list =ref([]) ;
let subject_list = ref([]);

let schoolAndClass = ref([]);

onMounted(() => {
  initOption();
})

// 初始化选项列表
const initOption = () => {
  let transObj = {
    ykj_id:route.params.ykj_id,
  }

  ksjh_detail(transObj)
    .then(res => {
      if (res.code == "1") {
        //初始化联考学校
        let linkao_scholl = res.data.one_info.ykj_lkxx_ex;
        let temp_school: { value: any; label: any; }[] = [];
        linkao_scholl.forEach((item: { sm_id: any; sm_name: any; }) => {
          temp_school.push({
            value: item.sm_id,
            label: item.sm_name
          })
        });
        school_list.value = temp_school;

        //
        schoolAndClass.value = res.data.one_info.school_and_class;
        //联考下的学科-从lc下取值
        let allLc = res.data.one_info.lc;
        let temp_xueke: { value: any; label: any; }[] = [];
        allLc.forEach((item: { ze_id: any; ykl_lc: string; }) => {
          temp_xueke.push({
            value: item.ze_id,
            label: JSON.parse(item.ykl_lc).ze_xueke_name
          })
        })
        subject_list.value = temp_xueke;

      }
    })
    .catch(error => { console.log(error) })
}

// 筛选点击
const handelOption = (value,marke) => {
  emit('optionClick', value,marke);
}

</script>

<style scoped>

</style>
