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