1a1840ed24f77af2d1d6316edc1745d166721a00.svn-base 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <a-checkbox-group v-if="tagType=='checkbox'" @change="onChange" :value="arrayValue" :disabled="disabled">
  3. <a-checkbox v-for="(item, key) in dictOptions" :key="key" :value="item.value">{{ item.text || item.label }}</a-checkbox>
  4. </a-checkbox-group>
  5. <a-select
  6. v-else-if="tagType=='select'"
  7. :value="arrayValue"
  8. @change="onChange"
  9. :disabled="disabled"
  10. mode="multiple"
  11. :placeholder="placeholder"
  12. :getPopupContainer="getParentContainer"
  13. optionFilterProp="children"
  14. :filterOption="filterOption"
  15. allowClear>
  16. <a-select-option
  17. v-for="(item,index) in dictOptions"
  18. :key="index"
  19. :value="item.value">
  20. <span style="display: inline-block;width: 100%" :title=" item.text || item.label ">
  21. {{ item.text || item.label }}
  22. </span>
  23. </a-select-option>
  24. </a-select>
  25. </template>
  26. <script>
  27. import {ajaxGetDictItems,getDictItemsFromCache} from '@/api/api'
  28. export default {
  29. name: 'JMultiSelectTag',
  30. props: {
  31. dictCode: String,
  32. placeholder: String,
  33. disabled: Boolean,
  34. value: String,
  35. type: String,
  36. options:Array,
  37. spliter:{
  38. type: String,
  39. required: false,
  40. default: ','
  41. },
  42. popContainer:{
  43. type:String,
  44. default:'',
  45. required:false
  46. },
  47. },
  48. data() {
  49. return {
  50. dictOptions: [],
  51. tagType:"",
  52. arrayValue:!this.value?[]:this.value.split(this.spliter)
  53. }
  54. },
  55. created() {
  56. if(!this.type || this.type==="list_multi"){
  57. this.tagType = "select"
  58. }else{
  59. this.tagType = this.type
  60. }
  61. //获取字典数据
  62. //this.initDictData();
  63. },
  64. watch:{
  65. options: function(val){
  66. this.setCurrentDictOptions(val);
  67. },
  68. dictCode:{
  69. immediate:true,
  70. handler() {
  71. this.initDictData()
  72. },
  73. },
  74. value (val) {
  75. if(!val){
  76. this.arrayValue = []
  77. }else{
  78. this.arrayValue = this.value.split(this.spliter)
  79. }
  80. }
  81. },
  82. methods: {
  83. initDictData() {
  84. if(this.options && this.options.length>0){
  85. this.dictOptions = [...this.options]
  86. }else{
  87. //优先从缓存中读取字典配置
  88. let cacheOption = getDictItemsFromCache(this.dictCode)
  89. if(cacheOption && cacheOption.length>0){
  90. this.dictOptions = cacheOption
  91. return
  92. }
  93. //根据字典Code, 初始化字典数组
  94. ajaxGetDictItems(this.dictCode, null).then((res) => {
  95. if (res.success) {
  96. this.dictOptions = res.result;
  97. }
  98. })
  99. }
  100. },
  101. onChange (selectedValue) {
  102. this.$emit('change', selectedValue.join(this.spliter));
  103. },
  104. setCurrentDictOptions(dictOptions){
  105. this.dictOptions = dictOptions
  106. },
  107. getCurrentDictOptions(){
  108. return this.dictOptions
  109. },
  110. getParentContainer(node){
  111. if(!this.popContainer){
  112. return node.parentNode
  113. }else{
  114. return document.querySelector(this.popContainer)
  115. }
  116. },
  117. // update--begin--autor:lvdandan-----date:20201120------for:LOWCOD-1086 下拉多选框,搜索时只字典code进行搜索不能通过字典text搜索
  118. filterOption(input, option) {
  119. return option.componentOptions.children[0].children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  120. }
  121. // update--end--autor:lvdandan-----date:20201120------for:LOWCOD-1086 下拉多选框,搜索时只字典code进行搜索不能通过字典text搜索
  122. },
  123. model: {
  124. prop: 'value',
  125. event: 'change'
  126. }
  127. }
  128. </script>