<template>
  <el-form ref="form" :model="model" :rules="rules" label-position="right" label-width="80px">
    <el-form-item v-for="(grade,index) in dataSource" :key="index" :prop="grade.name" :label="grade.name"
                  class="form-item-readonly">
      <el-checkbox-group v-model="model[grade.name]" :disabled="disabled">
        <el-checkbox v-for="(clazz,idx) in grade.classList" :key="idx" :label="clazz.classId">{{ clazz.className }}
        </el-checkbox>
      </el-checkbox-group>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'class-tree-form',
  props: {
    modelValue: Object,
    rules: Object,
    dataSource: Array,
    disabled: Boolean
  },
  data() {
    return {
      model: {}
    }
  },
  watch: {
    modelValue: {
      immediate: true,
      handler: function(newVal) {
        if (!newVal) return
        this.model = this.deepClone(newVal)
      }
    }
  },
  methods: {
    validate() {
      return this.$refs.form.validate()
    },
    getModel() {
      return this.model
    }
  }
}
</script>

<style scoped>
</style>
