提交 | 用户 | age
|
c95579
|
1 |
<!-- 服务标签 --> |
L |
2 |
<template> |
|
3 |
<div class="serveLabel"> |
|
4 |
<el-tag |
|
5 |
v-for="tag in labelList" |
|
6 |
:key="tag" |
|
7 |
closable |
|
8 |
:disable-transitions="false" |
|
9 |
@close="labelCloseHandle(tag)" |
|
10 |
> |
|
11 |
{{ tag }} |
|
12 |
</el-tag> |
|
13 |
<el-input |
|
14 |
v-if="labelInputVisible" |
|
15 |
ref="saveTagInput" |
|
16 |
v-model="labelValue" |
|
17 |
class="input-new-tag" |
|
18 |
size="small" |
|
19 |
placeholder="输入标签,回车分隔" |
|
20 |
@keyup.enter.native="handleInputConfirm" |
|
21 |
@blur="handleInputConfirm" |
|
22 |
/> |
|
23 |
<el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加{{ text||'标签' }}</el-button> |
|
24 |
</div> |
|
25 |
</template> |
|
26 |
|
|
27 |
<script> |
|
28 |
export default { |
|
29 |
name: 'ServeLabels', |
|
30 |
model: { |
|
31 |
prop: 'param_labelList', // 使用 v-model |
|
32 |
event: 'change' // 绑定change事件 |
|
33 |
}, |
|
34 |
props: [ |
|
35 |
'param_labelList', // 标签 |
|
36 |
'text' |
|
37 |
], |
|
38 |
data() { |
|
39 |
return { |
|
40 |
// 标签输入 |
|
41 |
labelValue: '', |
|
42 |
// 是否显示标签输入框 |
|
43 |
labelInputVisible: false, |
|
44 |
// 标签数组 |
|
45 |
labelList: [] |
|
46 |
} |
|
47 |
}, |
|
48 |
watch: { |
|
49 |
// 监听shopId,并触发change事件 |
|
50 |
labelList(value) { |
|
51 |
this.$emit('change', value) |
|
52 |
}, |
|
53 |
param_labelList(value) { |
|
54 |
this.labelList = value |
|
55 |
} |
|
56 |
}, |
|
57 |
mounted() { |
|
58 |
this.init() |
|
59 |
}, |
|
60 |
methods: { |
|
61 |
init() { |
|
62 |
this.labelList = this.param_labelList || [] |
|
63 |
}, |
|
64 |
|
|
65 |
// 删除标签 |
|
66 |
labelCloseHandle(tag) { |
|
67 |
this.labelList.splice(this.labelList.indexOf(tag), 1) |
|
68 |
}, |
|
69 |
// 显示输入框 |
|
70 |
showInput() { |
|
71 |
this.labelInputVisible = true |
|
72 |
this.$nextTick(() => { |
|
73 |
this.$refs.saveTagInput.$refs.input.focus() |
|
74 |
}) |
|
75 |
}, |
|
76 |
// 输入标签完成 |
|
77 |
handleInputConfirm() { |
|
78 |
const inputValue = this.labelValue |
|
79 |
|
|
80 |
if (this.labelList.indexOf(inputValue) > -1) { |
|
81 |
this.$messageError('请勿重复输入标签') |
|
82 |
} else { |
|
83 |
if (inputValue) { |
|
84 |
this.labelList.push(inputValue) |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
// 隐藏输入框 |
|
89 |
this.labelInputVisible = false |
|
90 |
// 清空输入内容 |
|
91 |
this.labelValue = '' |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
</script> |
|
96 |
|
|
97 |
<style> |
|
98 |
.serveLabel .el-tag { |
|
99 |
margin-right: 10px; |
|
100 |
margin-bottom: 10px; |
|
101 |
font-size: 14px; |
|
102 |
} |
|
103 |
.button-new-tag { |
|
104 |
height: 32px; |
|
105 |
line-height: 30px; |
|
106 |
padding-top: 0; |
|
107 |
padding-bottom: 0; |
|
108 |
font-size: 14px !important; |
|
109 |
} |
|
110 |
.input-new-tag { |
|
111 |
width: 160px; |
|
112 |
vertical-align: bottom; |
|
113 |
} |
|
114 |
.input-new-tag .el-input__inner{ |
|
115 |
font-size: 14px; |
|
116 |
} |
|
117 |
</style> |