<template>
  <div class="radio-group-form">
    <el-form-item
      :key="item.model"
      :prop="item.model"
      :label="item.label || ''"
      :label-width="item.labelWidth || item['label-width'] || ''"
      :required="item.required || false"
      :rules="item.rules || []"
      :size="item.size"
    >
      <el-radio-group
        v-bind="item.attrs"
        v-on="$listeners"
        v-model="formData[item.model]"
        :style="{ width: item.modelWidth || item['model-width'] || '89%' }"
        :disabled="item.disabled || false"
      >
        <el-radio
          v-for="radio in item.values"
          :label="radio.value"
          :key="radio.value"
        >{{radio.label}}</el-radio>
      </el-radio-group>
      <template v-if="formData[item.model] !== null && formData[item.model] !== '' && formData[item.model] !== undefined">
        <div class="self-icon el-icon-circle-check" style="color: #237f00;"></div>
      </template>
      <div class="self-icon el-icon-circle-close" style="color: #b01c40;"></div>
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'RadioGroupForm',
  componentName: 'RadioGroupForm',
  props: {
    item: {
      type: Object,
      default () {
        return {}
      }
    },
    formData: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {}
  }
}
</script>

<style lang="scss">
  .self-icon {
    display: none !important;
    vertical-align: middle;
    margin-left: 10px;
    font-size: 21px;
    line-height: 22px;
  }
  .is-error .self-icon.el-icon-circle-close { display: inline-block !important; }
  .is-success .self-icon.el-icon-circle-check { display: inline-block !important; }
</style>
