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

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

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

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

      <el-col
        v-else
        :xs="item.xs || 24"
        :sm="item.sm || 24"
        :md="item.md || 24"
        :lg="item.lg || item.span || 12"
        :xl="item.span || 12"
        :key="columnIndex"
        v-show="item.display && isShowIm(item.importantField)"
      >
        <form-item-self
          :form="form"
          :item="item"
          :columns="columns.column || columns.children.column"
          :group="options.group"
        ></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 {}
  },
  methods: {
    handleChange(key, val) {
      if (this.form.hasOwnProperty(key)) this.form[key] = val
    },
  },

  computed: {
    isShowIm() {
      return function (val) {
        return !this.isShowImportant ? true : val
      }
    },
    paddingLeft() {
      const columns = this.columns
      return columns.labelWidth ? `${columns.labelWidth}px` : ""
    },
  },
}
</script>

<style lang="scss" scoped>
.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;
    }
  }
}

.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>
