<template>
  <div>
    <template
      v-for="(col, colIndex) in field.field_options.columns"
    >
      <template v-for="(item, index) in col.fields">
        <!--嵌套布局-->
        <ibps-dynamic-form-grid
          v-if="item.field_type === 'grid' || item.field_type === 'tabs' ||item.field_type === 'steps' || item.field_type === 'collapse' "
          ref="formItem"
          :key="item.name+colIndex+index"
          :models="models"
          :rights="rights"
          :field="item"
          :desc-position="descPosition"
          :params="params"
          :main-code="mainCode"
          :code="code"
          :readonly-rights="readonlyRights"
          :form-opinion="formOpinion"
          v-on="$listeners"
        />
        <!--其他类型-->
        <ibps-dynamic-form-item
          v-else
          ref="formItem"
          :key="item.name+colIndex+index"
          :models="models"
          :rights="rights"
          :field="item"
          :desc-position="descPosition"
          :params="params"
          :main-code="mainCode"
          :code="code"
          :readonly-rights="readonlyRights"
          :form-opinion="formOpinion"
          v-on="$listeners"
        />
      </template>
    </template>
  </div>
</template>
<script>

export default {
  props: {
    field: Object, // 字段
    models: [Object, Array], // 字段数据
    rights: { // 字段权限
      type: [String, Object]
    },
    defaultValue: Object, // 默认值
    mainCode: String, // 主表名
    code: String, // 表名
    row: [String, Number], // 子表行数
    readonlyRights: { // 只读
      type: Boolean,
      default: false
    },
    params: Object,
    formOpinion: Array,
    descPosition: String
  },
  methods: {
    /**
     * 获得表单验证
     */
    getFormValidator() {
      if (!this.$refs.formItem) { return }
      const $validate = []
      this.$refs.formItem.forEach(el => {
        const v = new Promise((resolve, reject) => {
          el.getFormValidator().validate().then((result) => {
            resolve(result)
          })
        })
        $validate.push(v)
      })
      return Promise.all($validate)
    },
    /**
     *  当前字段
     */
    getEl() {
      if (!this.$refs.formItem) { return }
      const $el = []
      this.$refs.formItem.forEach(el => {
        $el.push(el)
      })
      return $el
    }
  }
}
</script>
