<template>
  <div class="n-radio-group" :name="name">
    <template v-for="option in options">
      <u-radio :key="option.value" :name="option.value" :value="nValue === option.value" :label="option.label"
               :disabled="disabled || option.disabled" @u-change="onChange(option.value)"></u-radio>
    </template>
  </div>
</template>

<script>
import URadio from '@uif/next/lib/components/radio'
import {prop} from '@uif/next/lib/utils/tools'
import vModel from '_common/vModel'

export default {
  mixins: [vModel],
  name: 'n-radio-group',
  components: {
    URadio
  },
  props: {
    // 选中radio的value
    value: {},
    // 表单name
    name: prop.string(),
    // 选项
    options: prop.array(),
    // 禁用
    disabled: prop.boolean()

  },
  methods: {
    onChange (value) {
      if (this.nValue !== value) {
        this.nValue = value
        this.$emit('input', this.nValue)
        this.$emit('u-update', this.nValue)
        this.$emit('u-change', this.nValue)
      }
    }
  }
}
</script>
