EipFlowSelector.vue
4.64 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<template>
<div class="inputs">
<div
:style="{width: inputWidth}"
style="min-width: 180px"
class="el-select"
@click="showDialog"
>
<div
ref="tagSpans"
style="width: calc(100% - 50px)"
:class="{
'el-select__tags_readonly': !inputWriteable,
'el-select__tags': inputWriteable,
}"
>
<span>
<span
class="el-tag el-tag--info el-tag--small"
@click.stop
v-for="(item, index) in selectors"
:key="index"
>
<span class="el-select__tags-text">{{ item.name }}</span>
<i
v-if="inputWriteable"
class="el-tag__close el-icon-close"
@click="handleRemove(item)"
></i>
</span>
</span>
</div>
<div v-if="inputWriteable">
<ht-input
:name="inputName"
type="text"
ref="inputEl"
v-model="name"
@clear="clear"
:class="{'has-value': name}"
:placeholder="placeholder"
:validate="inputValidate"
:style="{height: inputSuffixHeight + 'px'}"
style="width: 100%"
>
<el-button slot="append" icon="icon-biaodan2"></el-button>
</ht-input>
</div>
</div>
<!--表单选择器-->
<eip-flow-dialog
ref="eipFlowDialog"
name="eipFlowDialog"
@onConfirm="handleDialogSure"
:single="true"
append-to-body
/>
</div>
</template>
<script>
import utils from '@/hotent-ui-util.js'
const eipFlowDialog = () => import('@/components/dialog/EipFlowDialog.vue')
export default {
name: 'eip-form-selector',
props: {
validate: [String, Object],
value: [String, Object, Array],
placeholder: {
type: String,
default: '请输入内容',
},
permission: {
type: String,
default: 'w',
validator: function (value) {
return ['b', 'w', 'r', 'n'].indexOf(value) !== -1
},
},
single: {
type: Boolean,
default: false,
},
config: Object,
data: {
type: Array,
default: () => {
return []
},
},
appendToBody: {
type: Boolean,
default: false,
},
inputWidth: {
type: String,
default: '100%',
},
},
components: {
eipFlowDialog,
},
data() {
return {
inputName: null,
inputSuffixHeight: 30,
name: '',
selectors: [],
dialogVisible: false,
currentDemension: null,
}
},
computed: {
inputWriteable: function () {
return utils.getWriteable(this.permission)
},
inputValidate: function () {
return utils.addRequiredOrNot(this.permission, this.validate, this)
},
},
watch: {
// 当所选择的数据发生变化时,同步到v-model中
selectors: function (newVal) {
if (newVal && newVal.length >= 0 && newVal[0] && newVal[0].name) {
this.name = newVal[0].name
} else {
this.name = ''
}
},
value: function (newVal) {
if (this.value && JSON.stringify(newVal) != '{}') {
if (this.selectors.length > 0) {
this.selectors = []
}
this.selectors.push(newVal)
} else {
this.selectors = []
}
},
},
mounted() {
// 组件第一次挂载时,同步value到当前所选数据中
if (this.value && JSON.stringify(this.value) != '{}') {
this.selectors.push(this.value)
} else {
this.selectors = []
}
},
created() {
this.inputName = this.name ? this.name : utils.getName()
this.$validator = this.$root.$validator
},
methods: {
showDialog() {
if (!this.inputWriteable) {
return
}
this.$refs.eipFlowDialog.showDialog(this.selectors)
},
handleDialogSure(data) {
this.selectors = data
this.$emit('input', this.selectors[0])
},
handleRemove(item) {
this.selectors.remove(item)
this.$emit('input', {})
},
clear() {
this.selectors = []
},
// 更新当前输入框的高度来适配已选数据的高度
calacInputSuffixHeight() {
if (!this.$refs.tagSpans) return
if (this.$refs.tagSpans.offsetHeight) {
this.inputSuffixHeight = this.$refs.tagSpans.offsetHeight + 5
} else {
this.inputSuffixHeight = 30
}
},
},
}
</script>
<style lang="scss" scoped>
.inputs {
display: block;
}
.el-input__inner[aria-invalid='true'] {
border-color: #f56c6c;
}
.has-value {
::v-deep {
div[aria-invalid='true'] .el-input__inner {
border-color: #dcdfe6;
}
.el-form-item__error {
display: none;
}
}
}
</style>