<template>
  <el-row :gutter="options.gutter" class="form-content">
    <template
      v-for="(item, columnIndex) in columns.column || columns.children.column"
    >
      <div
        v-if="item.type === 'dynamic'"
        v-show="item.display"
        :key="columnIndex"
        style="width: 100%"
        class="dynamic-form-container"
      >
        <el-form-item
          :prop="item.prop"
          :label-width="'0px'"
          style="display: none"
        >
        </el-form-item>
        <div class="dynamic-form-container_lable">{{ item.label }}</div>
        <form-dynamic
          v-model="form[item.prop]"
          :options="item.children"
          :dynamic-data="item.dynamicData"
          :is-show-important="isShowImportant"
        ></form-dynamic>
      </div>

      <div
        v-else-if="item.type === 'group'"
        v-show="item.display"
        :key="columnIndex"
        style="width: 100%"
      >
        <el-collapse :value="item.collapse ? item.prop : ''">
          <el-collapse-item
            :title="item.label"
            :name="item.prop"
            :disabled="!item.arrow"
          >
            <form-content
              ref="form-content"
              :form="form"
              :columns="item"
              :options="options"
              :is-show-important="isShowImportant"
            ></form-content>
          </el-collapse-item>
        </el-collapse>
      </div>

      <div
        v-else-if="item.type === 'dental-tab'"
        v-show="item.display && isShowIm(item.importantField)"
        :key="columnIndex"
        style="width: 100%"
      >
        <el-form-item
          :prop="item.prop"
          :label-width="'0px'"
          style="display: none"
        >
        </el-form-item>
        <dental-tab-form
          ref="dental"
          v-model="form[item.prop]"
          :item="item"
          :disabled="options.disabled"
          @change="handleChange"
        ></dental-tab-form>
      </div>

      <div
        v-else-if="item.type === 'dental-tab-tj'"
        v-show="item.display && isShowIm(item.importantField)"
        :key="columnIndex"
        style="width: 100%"
      >
        <el-form-item
          :prop="item.prop"
          :label-width="'0px'"
          style="display: none"
        >
        </el-form-item>
        <dental-tab-tj-form
          ref="dental"
          v-model="form[item.prop]"
          :item="item"
          :disabled="options.disabled"
        ></dental-tab-tj-form>
      </div>

      <el-col
        v-else-if="item.type === 'title'"
        v-show="item.display"
        :key="columnIndex"
        class="row12"
        :xs="item.xs || 24"
        :sm="item.sm || 24"
        :md="item.md || 24"
        :lg="item.span || 12"
      >
        <div class="form_title" :style="item.styles">
          <span>{{ item.value }}</span>
        </div>
      </el-col>

      <el-col
        v-else
        v-show="item.display && isShowIm(item.importantField)"
        :key="columnIndex"
        class="row24"
        :xs="item.xs || 24"
        :sm="item.sm || 24"
        :md="item.md || 24"
        :lg="item.lg || item.span || 12"
        :xl="item.span || 12"
      >
        <form-item-self
          :form="form"
          :column-index="columnIndex"
          :item="item"
          :columns="columns.column || columns.children.column"
          :group="options.group"
          @formChange="formChange"
        ></form-item-self>
      </el-col>
    </template>
  </el-row>
</template>

<script>
/**
 * @description 自定义表单
 */
import FormItemSelf from "./FormItemSelf.vue"
import FormDynamic from "./FormDynamic.vue"
import DentalTabForm from "@/components/DentalTabForm"
import DentalTabTjForm from "@/components/DentalTabForm/index-tj"

export default {
  name: "FormContent",
  components: { FormItemSelf, FormDynamic, DentalTabForm, DentalTabTjForm },

  props: {
    form: {
      type: Object,
      default: () => {
        return {}
      },
    },
    options: {
      type: Object,
      default: () => {
        return {}
      },
    }, //配置 数据
    columns: Object, //表单数据
    size: { type: String, default: "small" },
    formStyle: Object,
    formEdit: {
      type: Object,
      default: () => {
        return {}
      },
    },
    isShowImportant: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {}
  },

  computed: {
    isShowIm() {
      return function (val) {
        return !this.isShowImportant ? true : val
      }
    },
    paddingLeft() {
      const columns = this.columns
      return columns.labelWidth ? `${columns.labelWidth}px` : ""
    },
  },
  methods: {
    handleChange(key, val) {
      if (this.form.hasOwnProperty(key)) this.form[key] = val
    },
    // 切换不符合筛查条件的显示
    formChange() {
      console.log(this.form)
      let arr = [
        "is_one_year",
        "is_subtotal_history",
        "is_ppi",
        "is_symptom",
        "is_subtotal_history",
        "is_disease",
        "is_tumour",
      ]
      let flag = 0
      for (let i = 0; i < arr.length; i++) {
        if (this.form[arr[i]] && this.form[arr[i]] == 0) {
          flag++
        }
      }
      if (flag == 0) {
        this.$emit("showError", false)
      } else {
        this.$emit("showError", true)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep {
  .row24.el-col-lg-12 {
    &:nth-child(2n) {
      border-left: 1px solid #ccc;
    }
  }
}
.form-content ::v-deep {
  display: flex;
  flex-wrap: wrap;
  .el-form-item {
    display: flex;
    align-items: center;
    .el-form-item__label {
      line-height: 1.2;
    }
    .el-form-item__content {
      margin-left: 0 !important;
      flex: 1;
      display: flex;
      align-items: center;
    }
  }
}

.form_title {
  background-color: #fff;
  padding: 10px 0px;
  margin: 3px;
  span {
    height: 33px;
    line-height: 33px;
  }
}
.dynamic-form-container {
  &_lable {
    font-weight: bold;
    font-size: 16px;
    line-height: 40px;
  }
}
</style>
