<template>
  <a-spin :spinning="confirmLoading">
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-row>
        <a-col :span="24" style="text-align: center">
          <div style="font-size: 20px;font-weight: bold;">{{formData.kcmc}}</div>
          <div style="line-height: 40px;">
            <span>{{formData.jsbh}} - </span>
            <span>{{formData.jsxm}} - </span>
            <span>{{formData.jsyx}} - </span>
            <span>{{formData.xqxn}}</span>
          </div>
        </a-col>
        <a-col :span="12" style="margin-top: 10px;">
          <a-card >
            <template #cover>
              <span style="font-size: 16px;font-weight: bold;margin: 30px 0 0 30px;">评价指标平均分</span>
            </template>
            <a-row>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />重视学生的成长引领，关心学生的学习需求，乐于与学生交流:{{formData.col1}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />上课准备充分。课堂教学秩序良好。作业布置合理，反馈及时:{{formData.col2}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学目标明确，重点突出，逻辑性强:{{formData.col3}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学内容清晰易懂，体现适当的深度、广度和前沿性:{{formData.col4}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学方法合理。教学媒体得当，课程资源丰富:{{formData.col5}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教师知识渊博，教学水平高，教学特色鲜明，教学有吸引力:{{formData.col6}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学语言规范、准确，情绪饱满，热忱投入，为人师表:{{formData.col7}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学中启发学生思考，引导自主学习，激发学习动力，鼓励创新探索:{{formData.col8}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />掌握了所学课程的基础知识和基本理论，能用所学知识解决实际问题:{{formData.col9}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />体会到本门课程学习的乐趣和挑战，理解课程内容的意义与价值:{{formData.col10}}</span></a-col>
              <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />优点或建议:{{formData.col11}}</span></a-col>
            </a-row>
          </a-card>
        </a-col>
        <a-col :span="12" style="margin-top: 10px;">
          <a-card >
            <template #cover>
              <span style="font-size: 16px;font-weight: bold;margin: 30px 0 0 30px;">雷达图</span>
            </template>
            <a-row>
              <a-col :span="24">
                <Radar :chartData="radarData" height="50vh"></Radar>
              </a-col>
            </a-row>
          </a-card>
        </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 { getValueType } from '/@/utils';
  import { saveOrUpdate } from '../KcXsktjxmydcp.api';
  import { Form } from 'ant-design-vue';
  import { Icon } from '/@/components/Icon';
  import Radar from '/@/components/chart/Radar.vue';
  
  const radarData = ref<any>([]);
  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: '',
    kktzdh: '',
    kcbh: '',
    kcmc: '',
    jgh: '',
    skjs: '',
    kkdw: '',
    sxxs: '',
    sjxs: '',
    jzxs: '',
    jkxs: '',
    xsrs: '',
    ybzs: '',
    cpl: '',
    yxs: '',
    zhpj: '',
    col1: '',
    col2: '',
    col3: '',
    col4: '',
    col5: '',
    col6: '',
    col7: '',
    col8: '',
    col9: '',
    col10: '',
    xnxq: '',
  });
  const { createMessage } = useMessage();
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const labelCol2 = ref<any>({ xs: { span: 24 }, sm: { span: 20 } });
  const wrapperCol2 = ref<any>({ xs: { span: 24 }, sm: { span: 4 } });
  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);
      
      // <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />重视学生的成长引领，关心学生的学习需求，乐于与学生交流:{{formData.col1}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />上课准备充分。课堂教学秩序良好。作业布置合理，反馈及时:{{formData.col2}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学目标明确，重点突出，逻辑性强:{{formData.col3}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学内容清晰易懂，体现适当的深度、广度和前沿性:{{formData.col4}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学方法合理。教学媒体得当，课程资源丰富:{{formData.col5}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教师知识渊博，教学水平高，教学特色鲜明，教学有吸引力:{{formData.col6}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学语言规范、准确，情绪饱满，热忱投入，为人师表:{{formData.col7}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />教学中启发学生思考，引导自主学习，激发学习动力，鼓励创新探索:{{formData.col8}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />掌握了所学课程的基础知识和基本理论，能用所学知识解决实际问题:{{formData.col9}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />体会到本门课程学习的乐趣和挑战，理解课程内容的意义与价值:{{formData.col10}}</span></a-col>
      //         <a-col :span="24"><span class="pjzbClass"><Icon icon="ant-design:caret-right-outlined" />优点或建议:{{formData.col11}}</span></a-col>
      radarData.value = [
        { value: formData.col1, name: '重视学生的成长引领，关心学生的学习需求，乐于与学生交流',  max: 10 },
        { value: formData.col2, name: '上课准备充分。课堂教学秩序良好。作业布置合理，反馈及时',  max: 10 },
        { value: formData.col3, name: '教学目标明确，重点突出，逻辑性强',  max: 10 },
        { value: formData.col4, name: '教学内容清晰易懂，体现适当的深度、广度和前沿性',  max: 10 },
        { value: formData.col5, name: '教学方法合理。教学媒体得当，课程资源丰富',  max: 10 },
        { value: formData.col6, name: '教师知识渊博，教学水平高，教学特色鲜明，教学有吸引力',  max: 10 },
        { value: formData.col7, name: '教学语言规范、准确，情绪饱满，热忱投入，为人师表',  max: 10 },
        { value: formData.col8, name: '教学中启发学生思考，引导自主学习，激发学习动力，鼓励创新探索',  max: 10 },
        { value: formData.col9, name: '掌握了所学课程的基础知识和基本理论，能用所学知识解决实际问题',  max: 10 },
        { value: formData.col10, name: '体会到本门课程学习的乐趣和挑战，理解课程内容的意义与价值',  max: 10 },
      ];


    });
  }

  /**
   * 提交数据
   */
  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;
  }
  .xsxxClass{
    font-size: 16px;
    line-height: 40px;
  }
  .pjzbClass{
    font-size: 16px;
    line-height: 40px;
  }
</style>
