JDictSelectTag.vue 2.2 KB
Newer Older
1
<template>
2 3 4 5
  <a-radio-group v-if="tagType=='radio'" @change="handleInput" :value="value" :disabled="disabled">
    <a-radio v-for="(item, key) in dictOptions" :key="key" :value="item.value">{{ item.text }}</a-radio>
  </a-radio-group>

JEECG低代码平台's avatar
JEECG低代码平台 已提交
6
  <a-select v-else-if="tagType=='select'" :getPopupContainer = "(target) => target.parentNode" :placeholder="placeholder" :disabled="disabled" :value="value" @change="handleInput">
7
    <a-select-option value="">请选择</a-select-option>
8 9 10 11 12
    <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.value">
      <span style="display: inline-block;width: 100%" :title=" item.text || item.label ">
        {{ item.text || item.label }}
      </span>
    </a-select-option>
13 14 15 16 17 18 19
  </a-select>
</template>

<script>
  import {ajaxGetDictItems} from '@/api/api'

  export default {
20
    name: "JDictSelectTag",
21 22 23
    props: {
      dictCode: String,
      placeholder: String,
24
      triggerChange: Boolean,
25 26 27
      disabled: Boolean,
      value: String,
      type: String
28 29 30 31
    },
    data() {
      return {
        dictOptions: [],
32
        tagType:""
33 34
      }
    },
35 36 37 38 39 40 41 42
    watch:{
      dictCode:{
        immediate:true,
        handler() {
          this.initDictData()
        },
      }
    },
43
    created() {
44
      // console.log(this.dictCode);
45 46 47 48 49
      if(!this.type || this.type==="list"){
        this.tagType = "select"
      }else{
        this.tagType = this.type
      }
50
      //获取字典数据
51
      // this.initDictData();
52 53 54 55 56 57 58 59 60 61 62
    },
    methods: {
      initDictData() {
        //根据字典Code, 初始化字典数组
        ajaxGetDictItems(this.dictCode, null).then((res) => {
          if (res.success) {
//                console.log(res.result);
            this.dictOptions = res.result;
          }
        })
      },
63 64 65 66 67 68 69
      handleInput(e) {
        let val;
        if(this.tagType=="radio"){
          val = e.target.value
        }else{
          val = e
        }
70
        console.log(val);
71 72 73 74 75
        if(this.triggerChange){
          this.$emit('change', val);
        }else{
          this.$emit('input', val);
        }
76 77 78 79 80 81
      },
      setCurrentDictOptions(dictOptions){
        this.dictOptions = dictOptions
      },
      getCurrentDictOptions(){
        return this.dictOptions
82 83 84 85 86 87 88
      }
    }
  }
</script>

<style scoped>
</style>