<!--
 * @Author: Devin
 * @Date: 2023-02-17 15:37:24
 * @LastEditors: Devin
 * @LastEditTime: 2023-02-22 14:51:51
 * @Description: 复杂表单：
  1. 支持slot组件嵌入；
  2. 支持动态组件插入；
  3. 支持表单元素联动；
-->
<template>
  <el-form label-width="auto" :inline="true">
    <el-row :gutter="20">
      <template v-for="(formItem, index) in complexForms" :key="index">
        <template v-if="formItem?.['childForms']">
          <el-col :span="formItem?.['span'] || 12">
            <common-complex-form-item
              :form-item="formItem"
            ></common-complex-form-item>
          </el-col>
          <template v-if="formItem?.['value']">
            <el-col
              v-for="(child, childIdx) in formItem?.['childForms']?.[
                formItem?.['value']
              ]"
              :key="childIdx"
              :span="child?.['span'] || 12"
            >
              <common-complex-form-item
                :form-item="child"
              ></common-complex-form-item>
            </el-col>
          </template>
        </template>
        <template v-else>
          <el-col :span="formItem?.['span'] || 12">
            <common-complex-form-item
              :form-item="formItem"
            ></common-complex-form-item>
          </el-col>
        </template>
      </template>
    </el-row>
  </el-form>
</template>

<script setup lang="ts">
import { defineProps } from 'vue';

import CommonComplexFormItem from './CommonComplexFormItem.vue';

defineProps({
  complexForms: {
    type: Array<any>,
    default: () => []
  }
});
</script>

<script lang="ts">
export default {
  name: 'CommonComplexForm'
};
</script>

<style scoped lang="scss"></style>
