<template>
    <a-col
      class="grid-col"
      :key="key"
      v-if="curIndex>=minIndex && (maxIndex = 0 || curIndex<=maxIndex)"
      :span="record.mode === 'single'? 6 : 12 "
    >
      <LQKFormItem
        v-if="record.mode === 'single'"
        ref="nestedComponents"
        @handleReset="$emit('handleReset')"
        @change="handleChange"
        :disabled="disabled"
        :dynamicData="dynamicData"
        :key="record.key"
        :record="record"
        :formConfig="formConfig"
        :config="config"
      />
      <div v-else>
        <LQKFormItem
          ref="nestedComponents"
          @handleReset="$emit('handleReset')"
          @change="handleChange"
          :disabled="disabled"
          :dynamicData="dynamicData"
          :key="record.key"
          :record="record"
          :formConfig="formConfig"
          :config="config"
          :postfix="_begin"
        />
        <span class="query-group-split-cust"></span>
        <LQKFormItem
          ref="nestedComponents"
          @handleReset="$emit('handleReset')"
          @change="handleChange"
          :disabled="disabled"
          :dynamicData="dynamicData"
          :key="record.key"
          :record="record"
          :formConfig="formConfig"
          :config="config"
          :postfix="_end"
        />
      </div>
    </a-col>
</template>
<script>
/*
 * author kcz
 * date 2019-11-20
 */
export default {
  name: "buildBlocks",
  props: {
    record: {
      type: Object,
      required: true
    },
    formConfig: {
      type: Object,
      required: true
    },
    config: {
      type: Object,
      default: () => ({})
    },
    dynamicData: {
      type: Object,
      required: true
    },
    disabled: {
      type: Boolean,
      default: false
    },
    minIndex: {
      type: Number,
      default: 0
    },
    maxIndex: {
      type: Number,
      default: 0
    },
    curIndex: {
      type: Number,
      default: 0
    },
  },
  methods: {
    validationSubform() {
      // 验证动态表格
      let nestedComponents = this.$refs.nestedComponents;
      if (
        typeof nestedComponents === "object" &&
        nestedComponents instanceof Array
      ) {
        for (let i = 0; nestedComponents.length > i; i++) {
          if (!nestedComponents[i].validationSubform()) {
            return false;
          }
        }
        return true;
      } else if (typeof nestedComponents !== "undefined") {
        return nestedComponents.validationSubform();
      } else {
        return true;
      }
    },
    handleChange(value, key) {
      this.$emit("change", value, key);
    }
  }
};
</script>
