<template>
  <div style=" width:auto; display:inline-block !important;">
    <a-radio-group v-model="selected"  :options="options" @change="onChange" />
  </div>
</template>
<script>


export default {
  name: "paraRadio",
  data () {
    return {
      options: [],
      selected: '',
    };
  },
  props: {
    value: {
      type: String,
      default () {
        return null
      }
    },
    typeId: {
      type: Number,
      default () {
        return null
      }
    },
    code: {
      type: String,
      default () {
        return null
      }
    },
  },
  created () {
    this.loadCheck()
  },
  methods: {
    loadCheck () {
      let pars = { id: this.value, typeId: this.typeId, systemCode: this.code }
      this.$api.parameter.getParameterList(pars).then(({ data = { data } }) => {
        if (data) {
          this.options = []
          this.selected = null
          data.data.forEach(e => {
            this.options.push({ label: e.title, value: e.key })
          })
          if (!!this.value) {
            this.selected = this.value
          }
        }
      }).catch(() => { })
    },
    onChange (e) {
      this.selected = e.target.value
      this.$emit("input", e.target.value);
      this.$emit("change");
    }
  },
  watch: {
    value: {
      handler (value) {
        if (!!value)
          this.selected = this.value
      },
    },
  }
};
</script>
