<template>
  <a-spin :spinning="confirmLoading">
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-row>
        <a-col :span="8">
          <a-form-item label="课程编号" v-bind="validateInfos.kcbh">
            <a-input v-model:value="formData.kcbh" placeholder="请输入课程编号" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="课程名称" v-bind="validateInfos.kcmc">
            <a-input v-model:value="formData.kcmc" placeholder="请输入课程名称" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="授课教师" v-bind="validateInfos.skjs">
            <a-input v-model:value="formData.skjs" placeholder="请输入授课教师" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="授课时间" v-bind="validateInfos.sksj">
		        <a-date-picker placeholder="请选择授课时间" v-model:value="formData.sksj" value-format="YYYY-MM-DD"  style="width: 100%" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="上课地点" v-bind="validateInfos.skdd">
            <a-input v-model:value="formData.skdd" placeholder="请输入上课地点" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="评价时间" v-bind="validateInfos.pjsj">
		        <a-date-picker placeholder="请选择评价时间"  v-model:value="formData.pjsj" showTime value-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="1.具有教育理想、敬业精神和教学追求，热爱学生、学科和教学工作。" v-bind="validateInfos.ans1">
            <j-dict-select-tag type='radio' v-model:value="formData.ans1" dictCode="" placeholder="请选择1.具有教育理想、敬业精神和教学追求，热爱学生、学科和教学工作。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="2.掌握所教学科必需的专业与教学知识。具备所教学科的教学设计、实施、评价、反思和研究能力。" v-bind="validateInfos.ans2">
            <j-dict-select-tag type='radio' v-model:value="formData.ans2" dictCode="" placeholder="请选择2.掌握所教学科必需的专业与教学知识。具备所教学科的教学设计、实施、评价、反思和研究能力。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="3.把握学生身心发展规律与特点，尊重学生主体性与差异性。" v-bind="validateInfos.ans3">
            <j-dict-select-tag type='radio' v-model:value="formData.ans3" dictCode="" placeholder="请选择3.把握学生身心发展规律与特点，尊重学生主体性与差异性。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="4.立德树人，为人师表，语言规范，情绪饱满，思想积极向上" v-bind="validateInfos.ans4">
            <j-dict-select-tag type='radio' v-model:value="formData.ans4" dictCode="" placeholder="请选择4.立德树人，为人师表，语言规范，情绪饱满，思想积极向上" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="5.执行教学计划，遵守教学纪律，严谨从教" v-bind="validateInfos.ans5">
            <j-dict-select-tag type='radio' v-model:value="formData.ans5" dictCode="" placeholder="请选择5.执行教学计划，遵守教学纪律，严谨从教" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="6.系统规划和设计教学活动，合理确定教学目标和教学内容的重难点，选择合适的教学方法、教学媒体和教学形式" v-bind="validateInfos.ans6">
            <j-dict-select-tag type='radio' v-model:value="formData.ans6" dictCode="" placeholder="请选择6.系统规划和设计教学活动，合理确定教学目标和教学内容的重难点，选择合适的教学方法、教学媒体和教学形式" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="7.清晰讲解课程内容，恰当解释知识中蕴含的本源性思想和学科方法，适时引导学生关注课程领域发展新动态。" v-bind="validateInfos.ans7">
            <j-dict-select-tag type='radio' v-model:value="formData.ans7" dictCode="" placeholder="请选择7.清晰讲解课程内容，恰当解释知识中蕴含的本源性思想和学科方法，适时引导学生关注课程领域发展新动态。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="8.启发学生思考，鼓励学生发现、提出问题，恰当给予回应和引导。" v-bind="validateInfos.ans8">
            <j-dict-select-tag type='radio' v-model:value="formData.ans8" dictCode="" placeholder="请选择8.启发学生思考，鼓励学生发现、提出问题，恰当给予回应和引导。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="9.监控教学过程，富有教学机智，教学体现生成性。" v-bind="validateInfos.ans9">
            <j-dict-select-tag type='radio' v-model:value="formData.ans9" dictCode="" placeholder="请选择9.监控教学过程，富有教学机智，教学体现生成性。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="10.运用多元评价方式，了解学习状况，诊断学习问题，及时反馈" v-bind="validateInfos.ans10">
            <j-dict-select-tag type='radio' v-model:value="formData.ans10" dictCode="" placeholder="请选择10.运用多元评价方式，了解学习状况，诊断学习问题，及时反馈" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="11.学习认真积极，踊跃参与课堂活动，体会课程学习的挑战与乐趣，感悟课程的意义与价值。" v-bind="validateInfos.ans11">
            <j-dict-select-tag type='radio' v-model:value="formData.ans11" dictCode="" placeholder="请选择11.学习认真积极，踊跃参与课堂活动，体会课程学习的挑战与乐趣，感悟课程的意义与价值。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="12.掌握所学课程的基本概念与原理，理解课程的知识结构与思想体系，了解所学知识的运用情境、策略和方法。" v-bind="validateInfos.ans12">
            <j-dict-select-tag type='radio' v-model:value="formData.ans12" dictCode="" placeholder="请选择12.掌握所学课程的基本概念与原理，理解课程的知识结构与思想体系，了解所学知识的运用情境、策略和方法。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="13.遵循教学一般规律，具有鲜明的创新意识和个性风貌。" v-bind="validateInfos.ans13">
            <j-dict-select-tag type='radio' v-model:value="formData.ans13" dictCode="" placeholder="请选择13.遵循教学一般规律，具有鲜明的创新意识和个性风貌。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="14.尊重学科本质属性，凸显学科育人价值，注重培养学科核心素养。" v-bind="validateInfos.ans14">
            <j-dict-select-tag type='radio' v-model:value="formData.ans14" dictCode="" placeholder="请选择14.尊重学科本质属性，凸显学科育人价值，注重培养学科核心素养。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="15.课堂教学蕴含理性美，具有教学魅力，体现教学艺术性。" v-bind="validateInfos.ans15">
            <j-dict-select-tag type='radio' v-model:value="formData.ans15" dictCode="" placeholder="请选择15.课堂教学蕴含理性美，具有教学魅力，体现教学艺术性。" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="16.你对该课程的总体评价情况，5分是满分，您给打几分？" v-bind="validateInfos.ans16">
            <j-dict-select-tag type='radio' v-model:value="formData.ans16" dictCode="" placeholder="请选择16.你对该课程的总体评价情况，5分是满分，您给打几分？" :disabled="disabled"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="17.您认为该课堂值得肯定的方面" v-bind="validateInfos.ans17">
            <a-input v-model:value="formData.ans17" placeholder="请输入17.您认为该课堂值得肯定的方面" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="18.您认为该课堂需要改进的方面" v-bind="validateInfos.ans18">
            <a-input v-model:value="formData.ans18" placeholder="请输入18.您认为该课堂需要改进的方面" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="19.其它建议" v-bind="validateInfos.ans19">
            <a-input v-model:value="formData.ans19" placeholder="请输入19.其它建议" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-spin>
</template>

<script lang="ts" setup>
  import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import { getValueType } from '/@/utils';
  import { saveOrUpdate } from '../KcZzThpjb.api';
  import { Form } from 'ant-design-vue';
  
  const props = defineProps({
    formDisabled: { type: Boolean, default: false },
    formData: { type: Object, default: ()=>{} },
    formBpm: { type: Boolean, default: true }
  });
  const formRef = ref();
  const useForm = Form.useForm;
  const emit = defineEmits(['register', 'ok']);
  const formData = reactive<Record<string, any>>({
    id: '',
    kcbh: '',
    kcmc: '',
    skjs: '',
    sksj: '',
    skdd: '',
    pjsj: '',
    ans1: '',
    ans2: '',
    ans3: '',
    ans4: '',
    ans5: '',
    ans6: '',
    ans7: '',
    ans8: '',
    ans9: '',
    ans10: '',
    ans11: '',
    ans12: '',
    ans13: '',
    ans14: '',
    ans15: '',
    ans16: '',
    ans17: '',
    ans18: '',
    ans19: '',
  });
  const { createMessage } = useMessage();
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const confirmLoading = ref<boolean>(false);
  //表单验证
  const validatorRules = {
  };
  const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });

  // 表单禁用
  const disabled = computed(()=>{
    if(props.formBpm === true){
      if(props.formData.disabled === false){
        return false;
      }else{
        return true;
      }
    }
    return props.formDisabled;
  });

  
  /**
   * 新增
   */
  function add() {
    edit({});
  }

  /**
   * 编辑
   */
  function edit(record) {
    nextTick(() => {
      resetFields();
      //赋值
      Object.assign(formData, record);
    });
  }

  /**
   * 提交数据
   */
  async function submitForm() {
    // 触发表单验证
    await validate();
    confirmLoading.value = true;
    const isUpdate = ref<boolean>(false);
    //时间格式化
    let model = formData;
    if (model.id) {
      isUpdate.value = true;
    }
    //循环数据
    for (let data in model) {
      //如果该数据是数组并且是字符串类型
      if (model[data] instanceof Array) {
        let valueType = getValueType(formRef.value.getProps, data);
        //如果是字符串类型的需要变成以逗号分割的字符串
        if (valueType === 'string') {
          model[data] = model[data].join(',');
        }
      }
    }
    await saveOrUpdate(model, isUpdate.value)
      .then((res) => {
        if (res.success) {
          createMessage.success(res.message);
          emit('ok');
        } else {
          createMessage.warning(res.message);
        }
      })
      .finally(() => {
        confirmLoading.value = false;
      });
  }


  defineExpose({
    add,
    edit,
    submitForm,
  });
</script>

<style lang="less" scoped>
  .antd-modal-form {
    min-height: 500px !important;
    overflow-y: auto;
    padding: 24px 24px 24px 24px;
  }
</style>
