eacc4f9fd8051f533668667261e191700fc13e4b.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <a-radio-group v-if="tagType=='radio'" @change="handleInput" :value="getValueSting" :disabled="disabled">
  3. <a-radio v-for="(item, key) in dictOptions" :key="key" :value="item.value">{{ item.text }}</a-radio>
  4. </a-radio-group>
  5. <a-radio-group v-else-if="tagType=='radioButton'" buttonStyle="solid" @change="handleInput" :value="getValueSting" :disabled="disabled">
  6. <a-radio-button v-for="(item, key) in dictOptions" :key="key" :value="item.value">{{ item.text }}</a-radio-button>
  7. </a-radio-group>
  8. <a-select v-else-if="tagType=='select'" :getPopupContainer = "getPopupContainer" :placeholder="placeholder" :disabled="disabled" :value="getValueSting" @change="handleInput">
  9. <a-select-option :value="undefined">请选择</a-select-option>
  10. <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.value">
  11. <span style="display: inline-block;width: 100%" :title=" item.text || item.label ">
  12. {{ item.text || item.label }}
  13. </span>
  14. </a-select-option>
  15. </a-select>
  16. </template>
  17. <script>
  18. import {ajaxGetDictItems,getDictItemsFromCache} from '@/api/api'
  19. export default {
  20. name: "JDictSelectTag",
  21. props: {
  22. dictCode: String,
  23. placeholder: String,
  24. disabled: Boolean,
  25. value: [String, Number],
  26. type: String,
  27. getPopupContainer:{
  28. type: Function,
  29. default: (node) => node.parentNode
  30. }
  31. },
  32. data() {
  33. return {
  34. dictOptions: [],
  35. tagType:""
  36. }
  37. },
  38. watch:{
  39. dictCode:{
  40. immediate:true,
  41. handler() {
  42. this.initDictData()
  43. },
  44. }
  45. },
  46. created() {
  47. // console.log(this.dictCode);
  48. if(!this.type || this.type==="list"){
  49. this.tagType = "select"
  50. }else{
  51. this.tagType = this.type
  52. }
  53. //获取字典数据
  54. // this.initDictData();
  55. },
  56. computed: {
  57. getValueSting(){
  58. // update-begin author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
  59. // 当有null或“” placeholder不显示
  60. return this.value != null ? this.value.toString() : undefined;
  61. // update-end author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
  62. },
  63. },
  64. methods: {
  65. initDictData() {
  66. //优先从缓存中读取字典配置
  67. if(getDictItemsFromCache(this.dictCode)){
  68. this.dictOptions = getDictItemsFromCache(this.dictCode);
  69. return
  70. }
  71. //根据字典Code, 初始化字典数组
  72. ajaxGetDictItems(this.dictCode, null).then((res) => {
  73. if (res.success) {
  74. // console.log(res.result);
  75. this.dictOptions = res.result;
  76. }
  77. })
  78. },
  79. handleInput(e='') {
  80. let val;
  81. if(Object.keys(e).includes('target')){
  82. val = e.target.value
  83. }else{
  84. val = e
  85. }
  86. console.log(val);
  87. this.$emit('change', val);
  88. },
  89. setCurrentDictOptions(dictOptions){
  90. this.dictOptions = dictOptions
  91. },
  92. getCurrentDictOptions(){
  93. return this.dictOptions
  94. }
  95. },
  96. model:{
  97. prop: 'value',
  98. event: 'change'
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. </style>