<template>
  <div>
    <Select size="small" v-model="value" @on-change="onValueSetChange" :disabled="disabled" :clearable="clearable" :filterable="filterable">
      <Option v-for="item in dataList" :title="item.vsiValue" :value="item.vsiKey" :key="item.vsiKey">{{ item.vsiValue }}</Option>
    </Select>
  </div>
</template>
<script>
export default{
  name: 'SelectValueSet',
  components:{

  },
  props:{
    value:{
      type: String,
      default(){
        return '';
      }
    },
    parentKey:{
      type: String,
      default(){
        return '';
      }
    },
    code:{
      type: String,
      required: true,
    },
    onValueSetChange: {
      type: Function
    },
    disabled:{
      type: Boolean,
      default(){
        return false;
      }
    },
    clearable:{
      type: Boolean,
      default(){
        return false;
      }
    },
    filterable:{
      type: Boolean,
      default(){
        return false;
      }
    },
  },
  data(){
    return{
      dataList: [],
    }
  },
  computed:{

  },
  created:function(){
    this.init();
  },
  beforeMount:function(){

  },
  mounted:function(){

  },
  beforeDestroy:function(){

  },
  destroyed:function(){

  },
  methods:{
    init() {
      if(this.parentKey == ''){
        if(this.$store){
          this.$store.dispatch("GetValueSetByCode", { code: this.code }).then(response => {
            this.dataList = response.dataResult;
          });
        }else if($store){
          $store.dispatch("GetValueSetByCode", { code: this.code }).then(response => {
            this.dataList = response.dataResult;
          });
        }else{
          this.dataList = [];
        }
      }else{
        if(this.$store){
          this.$store.dispatch("GetValueSetByCodeAndParentKey", { "parentKey": this.parentKey, code: this.code }).then(response => {
            this.dataList = response.dataResult;
          });
        }else if($store){
          this.$store.dispatch("GetValueSetByCodeAndParentKey", { "parentKey": this.parentKey, code: this.code }).then(response => {
            this.dataList = response.dataResult;
          });
        }else{
          this.dataList = [];
        }
      }
    },
  },
  watch:{
    value(val) {
      this.$emit('input', val);
    },
    parentKey(val) {
      this.init();
    }
  },
  directives:{

  }
}
</script>
