<!--
 * @Author: your name
 * @Date: 2021-05-12 17:39:58
 * @LastEditTime: 2021-05-18 09:43:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ipublishment-ssr-web/components/Icon.vue
-->
<template>
  <div class="ipub-form">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'IpubForm',
  componentName: 'IpubForm',
  provide () {
    return {
      ipubForm: this
    };
  },
  props: {
    model: {
      type: Object,
      default () {
        return {}
      }
    },
    rules: {
      type: Object,
      default () {
        return {}
      }
    },
  },
  data () {
    return {
      fields: []
    }
  },
  created () {
    this.$on('ipub.form.addField', (field) => {
      if (field) {
        this.fields.push(field);
      }
    })
    /* istanbul ignore next */
    this.$on('ipub.form.removeField', (field) => {
      if (field.prop) {
        this.fields.splice(this.fields.indexOf(field), 1);
      }
    })
  },
  mounted () {

  },
  methods: {
    validate () {
      let flag = false
      this.fields.forEach(item => {
        const f = item.validate()
        flag = flag || f
      })
      return !flag
    }
  }
}
</script>
