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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* @Description: 工艺资源分类-新增属性类型
* @author wx
* @date 2021/4/07
*/
<template>
<div class="add-prop-com">
<dee-form
ref="editForm"
label-width="120px"
:form="editForm"
:form-data="editFormData"
form-btn-position="center"
:rules="formRules"
:inline="true"
>
<span style="display:flex">
<el-button
type="primary"
class="searchBtn"
@click="handleSubmit"
>确定</el-button>
<el-button
class="searchBtn"
@click="handleClose"
>取消</el-button>
</span>
</dee-form>
</div>
</template>
<script>
import { getAttrtype } from '@/api/modelApi'
import { addResourceProp, editResourceProp } from '@/api/resource'
export default {
name: 'AddProp',
components: { },
props: {
basicData: {
type: Object,
default: () => null
},
resourceAttrs: {
type: Array,
default: () => []
},
units: {
type: Array,
default: () => []
},
item: {
type: Object,
default: () => null
},
enumTypeOptions: {
type: Array,
default: () => []
}
},
data() {
return {
editForm: {},
formRules: {
resourceAttrCategoryCode: [{ required: true, message: '请选择资源类型', trigger: 'change' }],
name: [{ required: true, message: '请填写属性名称', trigger: 'blur' }],
displayName: [{ required: true, message: '请填写属性名称', trigger: 'blur' }],
type: [{ required: true, message: '请选择属性类型', trigger: 'change' }],
dictTypeArr: [{ required: true, message: '请选择字典类型', trigger: 'change' }]
},
attrtypeOptions: []
}
},
computed: {
editFormData: function() {
const editFormData = [
{ data: [
{
key: 'resourceAttrCategoryCode',
title: '资源类型名称',
component: {
name: 'el-select',
options: this.resourceAttrs
}
},
{
key: 'name',
title: '属性名称',
component: {
name: 'el-input'
}
},
{
key: 'displayName',
title: '显示名称',
component: {
name: 'el-input'
}
},
{
key: 'type',
title: '属性类型',
component: {
name: 'el-select',
disabled: this.type === 'look',
options: this.attrtypeOptions
}
},
{
key: 'dictTypeArr',
title: '字典类型',
hidden: this.editForm.type !== 'DictDataVO',
component: {
name: 'el-cascader',
disabled: this.type === 'look',
options: this.enumTypeOptions,
props: { checkStrictly: true },
'change-on-select': true
},
handler: {
'change': (val) => {
// this.changeType(val)
}
}
},
{
key: 'notNull',
title: '非空',
component: {
name: 'el-checkbox',
disabled: this.type === 'look'
}
},
{
key: 'maxLength',
title: '最大长度',
component: {
name: this.type === 'look' ? 'readable' : 'el-input'
},
handler: {
'input': (val) => {
this.$set(this.editForm, 'maxLength', val.replace(/[^\d]/g, ''))
}
}
},
{
key: 'scale',
title: '精度',
component: {
name: this.type === 'look' ? 'readable' : 'el-input',
type: 'number'
}
},
{
key: 'unitCode',
title: '单位',
component: {
name: 'el-select',
disabled: this.type === 'look',
options: this.units
}
},
{
key: 'description',
title: '说明',
component: {
name: this.type === 'look' ? 'readable' : 'el-input',
type: 'textarea',
rows: '2'
}
}
] }
]
editFormData[0].data = editFormData[0].data.filter(r => !r.hidden)
return editFormData
}
},
watch: {
item: {
immediate: true,
deep: true,
handler: function(val) {
if (val) {
this.editForm = JSON.parse(JSON.stringify(val))
this.$set(this.editForm, 'dictTypeArr', val.dictType ? [val.dictType] : [])
}
}
}
},
created() {
getAttrtype().then((res) => {
this.attrtypeOptions = res.items.map(item => {
item.label = item.typeName
item.value = item.typeName
return item
})
})
},
mounted() {
},
methods: {
handleSubmit() {
this.$refs.editForm.$refs.form.validate((valid) => {
if (valid) {
const params = { ...this.editForm }
params.dxResourceClasscificationId = this.basicData.id
params.dxResourceClasscificationIdType = this.basicData.subTypeName
params.dictType = this.editForm.dictTypeArr && this.editForm.dictTypeArr.length ? this.editForm.dictTypeArr[this.editForm.dictTypeArr.length - 1] : ''
delete params.dictTypeArr
const updateFun = this.editForm.id ? editResourceProp : addResourceProp
updateFun(params).then(res => {
this.handleClose()
this.$emit('getTableData')
})
}
})
},
handleEdit() {
},
handleClose() {
this.$emit('handleClose')
}
}
}
</script>
<style lang="scss" >
.add-prop-com{
.dee-table{
height:270px;
.dee-table-body{
height: calc( 100% - 38px);
overflow-y: scroll;
}
}
}
</style>