<template>
  <div class="QdmRadio" :class="inline ? 'inline' : ''">
    <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
    <el-radio-group v-model="radio" @change="radioChange" :disabled="disabled">
      <el-radio v-for="(item, index) in list" :key="index" :label="item.id">{{ item.name }}</el-radio>
    </el-radio-group>
  </div>
</template>
<script>
export default {
  name: "QdmRadio",
  props: {
    name: {
      type: String,
      default: ''
    },
    value: {
      type: [ Number, String, Boolean ],
      default: ''
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    colSpan: {
      type: Number,
      default: 60
    },
    align: {
    	type: String,
      default: 'right'
    },
    inline: {
      type: Boolean,
      default: false
    },
    must: {
      type: Boolean,
      default: false
    },
    disabled: {
    	type: Boolean,
      default: false
    }
  },
  data() {
    return {
      radio: null
    }
  },
  created() {
    this.radio = this.value
  },
  methods: {
    radioChange() {
      this.$emit('radioReturn', this.radio)
    }
  },
  watch: {
  	value(val) {
  		this.radio = val
  	}
  }
}
</script>
<style lang="less">
.QdmRadio {
  margin-right: 10px;
  margin-bottom: 8px;
  height: 30px;
  >span {
    display: block;
    height: 30px;
    float: left;
    line-height: 30px;
    padding-right: 8px;
    font-size: 12px;
    >i {
      color: #F5222D;
      margin-right: 5px;
      padding-left: 3px;
    }
  }
  .el-radio-group {
    float: left;
    >label {
      line-height: 30px;
    }
    .el-radio__label {
    	font-size: 12px;
    }
  }
  &.inline {
    float: left;
  }
}
</style>