<template>
  <RadioGroup v-model="sels" @on-change="onchange" type="button">
    <Radio v-for="item in datasource" :label="item.value" :key="item.value" :Border="isborder">{{item.label}}</Radio>
  </RadioGroup>
</template>
<script>
import { refQuery } from "@/api/meta";
export default {
  name: "radiogroups",
  components: {},
  model: {
    prop: "value",
    event: "change"
  },
  props:["value","dicName","refModel","labelField","valueField","refwhere","isborder"],
  data() {
    return {
      sels: this.value,
      datasource: []
    };
  },
  watch: {
    value(nv, ov) {
      this.sels = nv;
    }
  },
  methods: {
    onchange(v) {
      this.$emit("change", this.sels);
    },
    initDataSource(slike) {
      if (this.dicName && this.dicName!="") {
        let objdic = this.$store.getters.dict_info[this.dicName];
        console.log(objdic);
        Object.keys(objdic).forEach(k => {
          this.datasource.push({
            value: k,
            label: objdic[k]
          });
        });
      } else {
        let query = {};
        let url = "/web/common/" + this.refModel + "Ctl/refQuery";
        query.fields = [this.labelField, this.valueField];
        query.likestr = slike;
        query.refwhere = this.refwhere ? this.refwhere : {};
        refQuery(url, query).then(r => {
          if (r.data) {
            this.datasource = r.data;
            console.log(">>>>>>>>>>>>>>>>>>>>",r.data)
          }
        });
      }
    }
  },
  created() {
       this.initDataSource()
  },
  mounted() {
 
  }
};
</script>
<style>
</style>
