<template>
  <BasicModal v-bind="$attrs" @register="register" title="缺失院校" @visible-change="handleVisibleChange">
    <div class="pt-3px pr-3px">
      <a-table :columns="columns" :data-source="dataList" :hideOnSinglePage="true" />
      <BasicForm @register="registerForm" :model="model" />
    </div>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, nextTick } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';

  const columns = [
    {
      title: '院校代码',
      dataIndex: 'schoolCode',
      key: 'name',
    },
  ];
  const dataList = [{
      key: '1',
      schoolCode: '胡彦斌',
    },
    {
      key: '2',
      schoolCode: '胡彦祖',
    },];
  const schemas: FormSchema[] = [];
  export default defineComponent({
    components: { BasicModal, BasicForm },
    props: {
      userData: { type: Object },
    },
    setup(props) {
      const modelRef = ref({});
      const [
        registerForm,
        {
          // setFieldsValue,
          // setProps
        },
      ] = useForm({
        labelWidth: 120,
        schemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });

      const [register] = useModalInner((data) => {
        data && onDataReceive(data);
      });

      function onDataReceive(data) {
        if(data.data){
          for (let i = 0; i < data.data.length; i++) {
            dataList.push({
              schoolCode: data.data[i], key : i
            });
          }
          console.log(dataList);
          modelRef.value = { dataList: dataList };
        }

        // setProps({
        //   model:{ field2: data.data, field1: data.info }
        // })
      }

      function handleVisibleChange(v) {
        v && props.userData && nextTick(() => onDataReceive(props.userData));
      }

      return { columns, dataList, register, schemas, registerForm, model: modelRef, handleVisibleChange };
    },
  });
</script>
