AddMenuGroupCatalog.vue
2.84 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
<template>
<el-dialog :title="$t('menuGroupCatalog.dialog.addTitle')" :visible.sync="dialogVisible" width="500px"
@close="handleClose">
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item :label="$t('menuGroupCatalog.form.gId')" prop="gId">
<el-select v-model="form.gId" style="width: 100%" placeholder="请选择">
<el-option :label="item.name" :value="item.gId" v-for="(item, index) in groups" :key="index" />
</el-select>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClose">{{ $t('menuGroupCatalog.dialog.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('menuGroupCatalog.dialog.confirm') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { addMenuGroupCatalog } from '@/api/dev/menuGroupCatalogApi'
import { getMenuGroupList } from '@/api/dev/menuGroupApi'
export default {
name: 'AddMenuGroupCatalog',
props: {
visible: {
type: Boolean,
default: false
},
caId: {
type: String,
default: ''
},
storeType: {
type: String,
default: ''
}
},
created() {
this.getList()
},
data() {
return {
dialogVisible: false,
form: {
gId: '',
storeType: '',
createTime: '',
},
groups: [],
rules: {
caId: [
{ required: true, message: this.$t('menuGroupCatalog.validate.caId'), trigger: 'blur' }
],
gId: [
{ required: true, message: this.$t('menuGroupCatalog.validate.gId'), trigger: 'blur' }
]
}
}
},
watch: {
visible: {
handler(val) {
this.dialogVisible = val
},
immediate: true
},
dialogVisible(val) {
this.$emit('update:visible', val)
}
},
methods: {
async getList() {
try {
this.loading = true
const params = {
page: 1,
row: 500,
storeType: this.storeType
}
const { menuGroups } = await getMenuGroupList(params)
this.groups = menuGroups
} catch (error) {
this.$message.error(this.$t('menuGroup.fetchError'))
} finally {
this.loading = false
}
},
handleClose() {
this.dialogVisible = false
this.$refs.form && this.$refs.form.resetFields()
},
async handleSubmit() {
try {
await addMenuGroupCatalog({
gId: this.form.gId,
caId: this.caId,
storeType: this.storeType,
})
this.$message.success(this.$t('common.operationSuccess'))
this.handleClose()
this.$emit('success')
} catch (error) {
console.error('添加失败:', error)
}
}
}
}
</script>
<style lang="scss" scoped>
.dialog-footer {
text-align: right;
}
</style>