<!--
 * @Descripttion:
 * @Version: 1.0
 * @Author: +C
 * @Date: 2022-02-15 08:47:06
 * @LastEditors: wufz
 * @LastEditTime: 2022-02-25 15:54:44
-->
<script>
export default {
  name: `DxxModal`,
  functional: true, //函数式组件
  props: [],
  //建立虚拟 DOM
  render(createElement, context) {
    // console.log(context.slots().default);
    let isLastForm = true //弹窗最后一个子元素为表单
    let isFirstForm = true //弹窗第一个子元素为表单
    context.slots().default.forEach((item, index) => {
      if (!item.data || !item.data.class || item.data.class.indexOf('dxx-form') == -1) {
        if (index == 0) {
          isFirstForm = false
        }
        if (index == context.slots().default.length - 1) {
          isLastForm = false
        }
      }
    })
    let className = 'modalNormal'
    className += isFirstForm ? ' modalFirstForm' : ''
    className += isLastForm ? ' modalLastForm' : ''
    //  编辑：dom表单元素
    let drawComponents = createElement(
      // 标签名称
      `vxe-modal`,
      // 传递数据
      {
        ...context.data,
        attrs: {
          ...context.data.attrs
        },
        props: {
          ...context.props
        },
        scopedSlots: {
          ...context.scopedSlots
        },
        class: (context.data.staticClass || "") + ' ' + className, //自定义class
        style: {
          ...context.data.staticStyle
        }
      },
      // 子节点数组，createElement...
      [
        context.slots().default
      ]
    );

    return drawComponents;
  }
};
</script>

<style scoped>
</style>