editCommunityPublicityList.vue
6.41 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
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
<template>
<div class="edit-community-publicity-container">
<el-card>
<div slot="header" class="flex justify-between">
<span>{{ $t('editCommunityPublicity.title') }}</span>
<el-button
style="float: right; padding: 3px 0"
type="text"
@click="_goBack"
>
<i class="el-icon-close"></i>{{ $t('common.back') }}
</el-button>
</div>
<el-form ref="form" :model="editCommunityPublicityInfo" label-width="120px" label-position="right">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item
:label="$t('editCommunityPublicity.publicityTitle')"
prop="title"
:rules="[{ required: true, message: $t('editCommunityPublicity.validate.titleRequired'), trigger: 'blur' }]">
<el-input
v-model="editCommunityPublicityInfo.title"
:placeholder="$t('editCommunityPublicity.publicityTitlePlaceholder')"
clearable>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item
:label="$t('editCommunityPublicity.publicityType')"
prop="pubType"
:rules="[{ required: true, message: $t('editCommunityPublicity.validate.typeRequired'), trigger: 'change' }]">
<el-select
v-model="editCommunityPublicityInfo.pubType"
style="width:100%"
:placeholder="$t('editCommunityPublicity.publicityTypePlaceholder')">
<el-option
v-for="item in editCommunityPublicityInfo.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('editCommunityPublicity.headerImage')"
prop="headerImg"
:rules="[{ required: true, message: $t('editCommunityPublicity.validate.imageRequired'), trigger: 'change' }]">
<upload-image-url
ref="uploadImage"
:image-count="1"
@notifyUploadCoverImage="handleUploadImage">
</upload-image-url>
</el-form-item>
<el-form-item
:label="$t('editCommunityPublicity.activityContent')"
prop="context"
:rules="[{ required: true, message: $t('editCommunityPublicity.validate.contentRequired'), trigger: 'blur' }]">
<rich-text-editor
v-model="editCommunityPublicityInfo.context"
ref="richTextEditor"
:height="300"
:placeholder="$t('editCommunityPublicity.activityContentPlaceholder')">
</rich-text-editor>
</el-form-item>
<el-form-item class="text-right">
<el-button @click="_goBack">{{ $t('common.back') }}</el-button>
<el-button type="primary" @click="saveCommunityPublicityInfo">
<i class="el-icon-check"></i>{{ $t('common.submit') }}
</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
import UploadImageUrl from '@/components/upload/UploadImageUrl'
import richTextEditor from '@/components/editor/RichTextEditor'
import { updateCommunityPublicity, listCommunityPublicity } from '@/api/community/editCommunityPublicityApi'
import { getDict } from '@/api/community/communityApi'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'EditCommunityPublicity',
components: {
UploadImageUrl,
richTextEditor
},
data() {
return {
editCommunityPublicityInfo: {
pubId: '',
title: '',
pubType: '',
pubTypes: [],
headerImg: '',
context: ''
}
}
},
created() {
this._initData()
},
methods: {
async _initData() {
this.editCommunityPublicityInfo.pubId = this.$route.query.pubId
this.communityId = await getCommunityId()
await this._loadCommunityPublicity()
await this._loadDictData()
},
async _loadDictData() {
try {
const data = await getDict('community_publicity', 'pub_type')
this.editCommunityPublicityInfo.pubTypes = data
} catch (error) {
console.error('获取字典数据失败:', error)
}
},
async _loadCommunityPublicity() {
try {
const params = {
page: 1,
row: 1,
communityId: this.communityId,
pubId: this.editCommunityPublicityInfo.pubId
}
const { data } = await listCommunityPublicity(params)
if (data && data.length > 0) {
Object.assign(this.editCommunityPublicityInfo, data[0])
// 设置图片,如果有的话
if (this.editCommunityPublicityInfo.headerImg) {
this.$refs.uploadImage.setImages([this.editCommunityPublicityInfo.headerImg])
}
this.$refs.richTextEditor.setContent(this.editCommunityPublicityInfo.context)
}
} catch (error) {
console.error('加载公示信息失败:', error)
}
},
handleUploadImage(images) {
if (images.length > 0) {
this.editCommunityPublicityInfo.headerImg = images[0]
} else {
this.editCommunityPublicityInfo.headerImg = ''
}
},
async saveCommunityPublicityInfo() {
this.$refs.form.validate(valid => {
if (valid) {
this._saveData()
} else {
return false
}
})
},
async _saveData() {
try {
const data = {
...this.editCommunityPublicityInfo,
communityId: this.communityId
}
const res = await updateCommunityPublicity(data)
if (res.code === 0) {
this.$message.success(this.$t('common.operationSuccess'))
this._goBack()
} else {
this.$message.error(res.msg || this.$t('editCommunityPublicity.message.updateFailed'))
}
} catch (error) {
console.error('保存公示信息失败:', error)
this.$message.error(this.$t('editCommunityPublicity.message.updateFailed'))
}
},
_goBack() {
this.$router.go(-1)
}
}
}
</script>
<style lang="scss" scoped>
.edit-community-publicity-container {
padding: 20px;
.el-card {
width: 100%;
}
.el-form-item {
margin-bottom: 22px;
}
.text-right {
text-align: right;
}
}
</style>