<template>
  <Select
    v-model="sels"
    style="width:150px;"
    @on-change="onchange"
    clearable
    :multiple="isMulti"
    :placeholder="placeHolder"
  >
    <Option v-for="item in datasource" :value="item.value" :key="item.value">{{ item.label }}</Option>
  </Select>
</template>
<script>
import { refQuery } from "@/api/meta";
export default {
  name: "dicselects",
  components: {},
  model: {
    prop: "value",
    event: "change"
  },
  props: ["value","dicName","placeHolder","isMulti"],
  data() {
    return {
      sels: this.value? this.value:[],
      datasource: []
    };
  },
  watch: {
    value(nv, ov) {
      this.sels = nv;
    }
  },
  methods: {
    onchange(v) {
      console.log("=============", v);
      this.$emit("change", this.sels);
    },
    initDataSource(slike) {
      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]
        });
      });
    }
  },
  created() {
    this.initDataSource();
  },
  mounted() {}
};
</script>

<style>
</style>
