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
| <template>
| <div>
| <el-form label-width="120px" ref="form" class="propForm">
| <el-form-item label="属性名称:">{{form.propName}}</el-form-item>
| <el-form-item label="属性值类型:">{{getLabel(propValueTypeArray,form.propValueType)}}</el-form-item>
| <el-form-item>
| <el-tag class="propValueCheckExplain" type="warning">{{form.propValueCheckExplain}}</el-tag>
| </el-form-item>
| <el-form-item label="属性值单位:">{{form.propUnit ? form.propUnit : '-'}}</el-form-item>
| <el-form-item label="属性描述:">{{form.propDesc ? form.propDesc : '-'}}</el-form-item>
| <el-form-item label="属性值:" class="propValue">
| <el-tooltip class="item" effect="dark" :key="tag.propValueId" v-for="(tag) in form.list" :content="tag.propValue" placement="top-start">
| <el-tag :closable="form.tag === 2 && form.list.length !== 1" :disable-transitions="false" @close="handleClose(tag)"> {{tag.propValue}}</el-tag>
| </el-tooltip>
| <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small" @keyup.enter.native="handleInputConfirm()" @blur="handleInputConfirm()">
| </el-input>
| <el-button v-if="!inputVisible && form.tag === 2" class="button-new-tag" size="small" type="success" @click="showInput">新增属性值</el-button>
| </el-form-item>
| </el-form>
| </div>
| </template>
| <script>
| import productPropMetaValueApi from '@/api/productmanagement/productPropMetaValue'
|
| export default {
| props: ['propForm'],
| data () {
| return {
| form: {},
| inputVisible: false,
| inputValue: '',
| propValueTypeArray: [
| {
| name: '字符类型',
| id: 0
| },
| {
| name: '数字类型',
| id: 1
| },
| {
| name: '时间类型',
| id: 2
| },
| {
| name: '日期类型',
| id: 3
| },
| {
| name: '日期时间型',
| id: 4
| }
| ],
| flag: 0
| }
| },
| methods: {
| /**
| * 获取数组的label
| */
| getLabel (array, id) {
| var lableText = array.find((item) => {
| return item.id === id
| })
| if (lableText) {
| return lableText.name
| }
| return ''
| },
| /**
| *删除属性值
| */
| handleClose (tag) {
| this.$confirm('确认删除数据吗?', '删除', {
| confirmButtonText: '确定',
| cancelButtonText: '取消',
| type: 'warning'
| }).then(() => {
| productPropMetaValueApi.deleteItem({ propValueId: tag.propValueId }).then(res => {
| if (res.data) {
| this.getList()
| this.flag = 1
| }
| })
| }).catch(() => {})
| },
| /** ]
| * 获取属性列表
| */
| getList () {
| productPropMetaValueApi.getList({ propId: this.form.propId, pageSize: 0 }, false).then(res => {
| if (res.data) {
| this.form.list = res.data.list
| }
| })
| },
| /**
| * 输入框获取焦点
| */
| showInput () {
| this.inputVisible = true
| this.$nextTick(_ => {
| this.$refs.saveTagInput.$refs.input.focus()
| })
| },
| /**
| * 输入框失去焦点时触发
| */
| handleInputConfirm () {
| const inputValue = this.inputValue
|
| if (!inputValue) {
| this.inputVisible = false
| return
| }
| if (inputValue.length > 128) {
| this.$message({
| message: '属性值不能超过 128 个字',
| type: 'warning'
| })
| return
| }
| productPropMetaValueApi.addInfo({ propId: this.form.propId, propValue: this.inputValue }).then(res => {
| if (res.data) {
| this.getList()
| this.inputVisible = false
| this.inputValue = ''
| this.flag = 1
| }
| })
| }
| },
| created () {
| this.form = JSON.parse(JSON.stringify(this.propForm))
| this.flag = 0
| }
| }
| </script>
| <style lang="scss">
| .propForm{
| .propValue .el-tag{
| position: relative;
| max-width:300px;
| text-overflow:ellipsis;
| white-space: nowrap;
| overflow:hidden;
| padding-right:20px;
| vertical-align: middle;
| .el-icon-close{
| position: absolute;
| top: 6px;
| right: 3px;
| }
| }
| .el-tag + .el-tag {
| margin-left: 10px;
| }
| .button-new-tag {
| margin-left: 10px;
| height: 32px;
| line-height: 30px;
| padding-top: 0;
| padding-bottom: 0;
| }
| .input-new-tag {
| width: 100px;
| margin-left: 10px;
| }
| .propValueCheckExplain {
| word-break: break-all;
| word-wrap: break-word;
| white-space: normal;
| height: auto;
| }
| }
| </style>
|
|