<template>
  <el-col :span="span">
    <el-form-item :label="label" :prop="prop" :label-width="labelWidth" :rules="rules" :class="table ? 'table-form-item' : ''">
      <div class="form-item-content">
        <div class="slot-content" :class="{'no-tip': tip == null}">
          <slot></slot>
        </div>
        <div v-if="tip" class="tip">{{tip}}</div>
      </div>
    </el-form-item>
  </el-col>
</template>

<script>
export default {
  name: 'FormCol',
  props: {
    span: {
      type: Number,
      default: 24
    },
    label: {
      type: String,
      default: null
    },
    prop: {
      type: String,
      default: null
    },
    labelWidth: {
      type: String,
      default: null
    },
    rules: {
      type: Array,
      default: null
    },
    table: {
      type: Boolean,
      default: false
    },
    tip: {
      type: String,
      default: null
    }
  }
}
</script>

<style scoped lang="scss">
.table-form-item {
  margin: 0;
}
.table-form-item.is-error {
  margin-bottom: 18px;
}
.form-item-content {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  
  .slot-content.no-tip {
    width: 100%;
  }
  .tip {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
    line-height: 1.5em;
    margin-left: 12px;
  }
}
</style>
