addCommunityPublicityList.vue
4.44 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
<template>
<el-card class="add-publicity-container">
<div slot="header" class="flex justify-between">
<span>{{ $t('addCommunityPublicity.title') }}</span>
<el-button style="float: right; padding: 3px 0" type="text" @click="goBack">
<i class="el-icon-close"></i>{{ $t('addCommunityPublicity.back') }}
</el-button>
</div>
<el-form ref="form" :model="formData" label-width="120px">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item :label="$t('addCommunityPublicity.pubTitle')" prop="title"
:rules="[{ required: true, message: $t('addCommunityPublicity.requiredTitle'), trigger: 'blur' }]">
<el-input v-model="formData.title" :placeholder="$t('addCommunityPublicity.requiredTitle')" clearable>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('addCommunityPublicity.pubType')" prop="pubType"
:rules="[{ required: true, message: $t('addCommunityPublicity.requiredType'), trigger: 'change' }]">
<el-select v-model="formData.pubType" :placeholder="$t('addCommunityPublicity.requiredType')"
style="width: 100%">
<el-option v-for="item in pubTypes" :key="item.statusCd" :label="item.name" :value="item.statusCd">
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item :label="$t('addCommunityPublicity.headerPhoto')" prop="headerImg"
:rules="[{ required: true, message: $t('addCommunityPublicity.requiredHeaderPhoto'), trigger: 'change' }]">
<upload-image-url ref="uploadImage" :image-count="1" @notifyUploadCoverImage="handleImageUpload">
</upload-image-url>
</el-form-item>
<el-form-item :label="$t('addCommunityPublicity.activityContent')" prop="context"
:rules="[{ required: true, message: $t('addCommunityPublicity.requiredContent'), trigger: 'blur' }]">
<rich-text-editor v-model="formData.context" :height="300"
:placeholder="$t('addCommunityPublicity.requiredContent')">
</rich-text-editor>
</el-form-item>
<el-form-item class="text-right">
<el-button @click="goBack">{{ $t('addCommunityPublicity.back') }}</el-button>
<el-button type="primary" @click="submitForm">{{ $t('addCommunityPublicity.submit') }}</el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
import UploadImageUrl from '@/components/upload/UploadImageUrl'
import { saveCommunityPublicity } from '@/api/community/addCommunityPublicityApi'
import { getCommunityId, getDict } from '@/api/community/communityApi'
import richTextEditor from '@/components/editor/RichTextEditor'
export default {
name: 'AddCommunityPublicity',
components: {
UploadImageUrl,
richTextEditor
},
data() {
return {
formData: {
title: '',
pubType: '',
headerImg: '',
context: ''
},
pubTypes: []
}
},
created() {
this.getPublicityTypes()
},
methods: {
async getPublicityTypes() {
try {
const data = await getDict('community_publicity', 'pub_type')
this.pubTypes = data
} catch (error) {
console.error('Failed to get publicity types:', error)
this.$message.error(this.$t('addCommunityPublicity.fetchTypesFailed'))
}
},
handleImageUpload(images) {
if (images.length > 0) {
this.formData.headerImg = images[0] || images[0]
} else {
this.formData.headerImg = ''
}
},
submitForm() {
this.$refs.form.validate(valid => {
if (valid) {
this.savePublicity()
} else {
return false
}
})
},
async savePublicity() {
try {
this.formData.communityId = getCommunityId()
const response = await saveCommunityPublicity(this.formData)
if (response.code === 0) {
this.$message.success(this.$t('common.operationSuccess'))
this.goBack()
} else {
this.$message.error(response.msg || this.$t('addCommunityPublicity.saveFailed'))
}
} catch (error) {
console.error('Save publicity error:', error)
this.$message.error(this.$t('addCommunityPublicity.saveFailed'))
}
},
goBack() {
this.$router.go(-1)
}
}
}
</script>
<style scoped>
.add-publicity-container {
margin: 20px;
}
.text-right {
text-align: right;
}
</style>