addResourceStoreSpecification.vue
4.79 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
<template>
<el-dialog :title="$t('resourceStoreSpecificationManage.addSpec')" :visible.sync="visible" width="50%"
@close="handleClose">
<el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
<el-form-item :label="$t('resourceStoreSpecificationManage.specName')" prop="specName">
<el-input v-model="form.specName" :placeholder="$t('resourceStoreSpecificationManage.specNamePlaceholder')">
</el-input>
</el-form-item>
<el-form-item :label="$t('resourceStoreSpecificationManage.itemType')" prop="parentRstId"
class="item-type-form-item">
<el-col :span="11">
<el-select v-model="form.parentRstId" :placeholder="$t('resourceStoreSpecificationManage.selectItemType')"
@change="handleParentTypeChange" style="width:100%">
<el-option v-for="item in resourceStoreTypes" :key="item.rstId" :label="item.name" :value="item.rstId">
</el-option>
</el-select>
</el-col>
<el-col :span="11" :offset="2">
<el-select v-model="form.rstId" :placeholder="$t('resourceStoreSpecificationManage.selectSubCategory')"
style="width:100%">
<el-option v-for="item in sonResourceStoreTypes" :key="item.rstId" :label="item.name" :value="item.rstId">
</el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item :label="$t('resourceStoreSpecificationManage.description')" prop="description">
<el-input type="textarea" v-model="form.description"
:placeholder="$t('resourceStoreSpecificationManage.descriptionPlaceholder')" :rows="3">
</el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="visible = false">
{{ $t('resourceStoreSpecificationManage.cancel') }}
</el-button>
<el-button type="primary" @click="submitForm">
{{ $t('resourceStoreSpecificationManage.save') }}
</el-button>
</div>
</el-dialog>
</template>
<script>
import { saveResourceStoreSpecification, listResourceStoreTypes } from '@/api/resource/resourceStoreSpecificationManageApi'
export default {
name: 'AddResourceStoreSpecification',
data() {
return {
visible: false,
form: {
specName: '',
parentRstId: '',
rstId: '',
description: ''
},
resourceStoreTypes: [],
sonResourceStoreTypes: [],
rules: {
specName: [
{ required: true, message: this.$t('common.requiredField'), trigger: 'blur' },
{ max: 255, message: this.$t('common.maxLength', { num: 255 }), trigger: 'blur' }
],
parentRstId: [
{ required: true, message: this.$t('common.requiredField'), trigger: 'change' }
],
rstId: [
{ required: true, message: this.$t('common.requiredField'), trigger: 'change' }
],
description: [
{ max: 512, message: this.$t('common.maxLength', { num: 512 }), trigger: 'blur' }
]
}
}
},
methods: {
open() {
this.visible = true
this.getResourceStoreTypes()
},
async getResourceStoreTypes() {
try {
const params = {
page: 1,
row: 100,
parentId: '0'
}
const res = await listResourceStoreTypes(params)
this.resourceStoreTypes = res.data
} catch (error) {
console.error('Failed to get item types:', error)
}
},
async getResourceStoreSonTypes(parentRstId) {
try {
const params = {
page: 1,
row: 100,
rstId: parentRstId,
flag: "0"
}
const res = await listResourceStoreTypes(params)
this.sonResourceStoreTypes = res.data
} catch (error) {
console.error('Failed to get sub item types:', error)
}
},
handleParentTypeChange(val) {
this.form.rstId = ''
if (!val) {
this.sonResourceStoreTypes = []
return
}
this.getResourceStoreSonTypes(val)
},
submitForm() {
this.$refs.formRef.validate(async valid => {
if (valid) {
try {
await saveResourceStoreSpecification(this.form)
this.$message.success(this.$t('common.operationSuccess'))
this.visible = false
this.$emit('success')
} catch (error) {
console.error('Failed to add specification:', error)
this.$message.error(this.$t('common.saveFailed'))
}
}
})
},
handleClose() {
this.$refs.formRef.resetFields()
this.form = {
specName: '',
parentRstId: '',
rstId: '',
description: ''
}
this.sonResourceStoreTypes = []
}
}
}
</script>
<style scoped>
.item-type-form-item {
margin-bottom: 22px;
}
</style>