<template>
  <view class="p-30">
    <view class="flex items-center justify-between">
      <text class="text-30 text-fore-title font-bold">我的班级</text>
      <view>
        <ie-picker ref="pickerRef" v-model="classId" :list="classList" placeholder="选择班级" title="选择班级" icon="arrow-down"
          key-label="name" key-value="classId" @change="handleClassChange"></ie-picker>
      </view>
    </view>
    <view>
      <slot :teachClass="selectedClass"></slot>
    </view>
  </view>

</template>
<script lang="ts" setup>
import { TeachClass } from '@/types/study';
import { getTeachClassList } from '@/api/modules/study';
const classId = ref<number | null>(null);
const classList = ref<TeachClass[]>([]);
const selectedClass = ref<TeachClass>();
const pickerRef = ref();
const loadData = async () => {
  try {
    const { data } = await getTeachClassList({});
    classList.value = data;
    classId.value = classList.value[0].classId;
    selectedClass.value = classList.value[0];
  } catch (error) {
    console.log(error);
  }
}
onMounted(() => {
  loadData();
});
const handleClassChange = (value: number, selectedItem: TeachClass) => {
  classId.value = value;
  selectedClass.value = selectedItem;
}
</script>
<style lang="scss" scoped></style>