| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- <template>
- <div class="activity-edit admin-page">
- <el-card>
- <PageHeader slot="header" :title="readonly && activityStatus !== 'rejected' ? '活动详情' : (isEdit ? '编辑活动' : '创建活动')">
-
- <div class="admin-page-actions">
- <el-button @click="$router.push('/activities')">返回列表</el-button>
- <template v-if="!readonly && activityStatus !== 'rejected'">
- <el-button type="primary" @click="saveActivity(false)" :loading="saving">{{ activityStatus === 'published' ? '保存修改' : '保存草稿' }}</el-button>
- <el-button v-if="isEdit && activityStatus !== 'published'" type="success" @click="handleSubmitReview" :loading="reviewLoading">提交审核</el-button>
- </template>
- <template v-if="activityStatus === 'rejected'">
- <el-button type="primary" @click="handleReDraft" :loading="reDraftLoading">保存到草稿箱重新编辑</el-button>
- </template>
- <template v-if="readonly && activityStatus === 'draft' && !isEdit">
- <el-button type="primary" size="mini" @click="editFromReadonly">编辑</el-button>
- </template>
- </div>
-
- </PageHeader>
- <!-- 状态横幅 -->
- <el-alert
- v-if="statusLabel"
- :title="statusLabel"
- :type="statusType"
- :description="statusDescription"
- show-icon
- :closable="false"
- class="mb-16"
- />
- <!-- 报名名册(T03:仅需报名的活动展示,详情页/编辑页均可查看) -->
- <el-card v-if="showRosterCard" class="roster-card" shadow="never">
- <div slot="header" class="roster-card-header">
- <span>报名名册</span>
- <div class="roster-card-actions">
- <el-button size="mini" :loading="rosterLoading" @click="loadRoster">刷新</el-button>
- <el-button size="mini" type="primary" :disabled="!rosterRegistrants.length" @click="exportRosterCsv">导出 CSV</el-button>
- </div>
- </div>
- <div v-loading="rosterLoading" class="roster-body">
- <el-row :gutter="12" class="roster-stats">
- <el-col :span="8">
- <div class="stat-box">
- <div class="stat-num">{{ roster.approvedCount != null ? roster.approvedCount : '-' }}</div>
- <div class="stat-label">已通过报名</div>
- </div>
- </el-col>
- <el-col :span="8">
- <div class="stat-box">
- <div class="stat-num">{{ roster.pendingCount != null ? roster.pendingCount : '-' }}</div>
- <div class="stat-label">待审核</div>
- </div>
- </el-col>
- <el-col :span="8">
- <div class="stat-box">
- <div class="stat-num" :class="{ 'stat-danger': roster.remaining != null && roster.remaining <= 0 }">
- {{ roster.remaining != null ? roster.remaining : '不限' }}
- </div>
- <div class="stat-label">剩余名额</div>
- </div>
- </el-col>
- </el-row>
- <div class="roster-list">
- <div class="roster-list-title">最近报名人({{ rosterRegistrants.length }})</div>
- <div v-if="rosterRegistrants.length" class="roster-list-body">
- <div v-for="(r, idx) in rosterRegistrants" :key="'roster-' + idx" class="roster-item">
- <span class="roster-name">{{ r.name }}</span>
- <span class="roster-time">{{ formatTime(r.registeredAt) }}</span>
- </div>
- </div>
- <div v-else class="roster-empty">还没有人报名,快来抢占第一个名额吧</div>
- </div>
- </div>
- </el-card>
- <div class="activity-edit-form-wrap">
- <el-form label-width="120px" v-loading="loading" :model="form" :rules="formRules" ref="form">
- <el-form-item label="活动标题" prop="title">
- <el-input v-model="form.title" placeholder="请输入活动标题" :disabled="readonly" />
- </el-form-item>
- <el-form-item label="活动简介">
- <el-input v-model="form.intro" placeholder="一句话介绍活动,将展示在活动列表卡片上" maxlength="200" show-word-limit :disabled="readonly" />
- </el-form-item>
- <el-form-item label="活动类型" prop="activityType">
- <el-select v-model="form.activityType" placeholder="请选择活动类型" class="full-width" :disabled="readonly">
- <el-option label="线下活动" value="offline" />
- <el-option label="线上活动" value="online" />
- <el-option label="主题活动" value="campaign" />
- </el-select>
- </el-form-item>
- <el-form-item label="活动描述" prop="description">
- <div class="rich-editor" :class="{ 'is-disabled': readonly }">
- <div v-if="!readonly" class="editor-extra-row">
- <el-button size="mini" plain icon="el-icon-picture-outline" @click="openAssetPicker('image')">从素材库选择图片</el-button>
- <el-button size="mini" plain icon="el-icon-video-camera" @click="openAssetPicker('video')">从素材库选择视频</el-button>
- </div>
- <Toolbar :editor="editorInstance" :defaultConfig="toolbarConfig" />
- <Editor :defaultConfig="editorConfig" v-model="form.description" @onCreated="handleEditorCreated" :disabled="readonly" class="editor-body" />
- </div>
- </el-form-item>
- <el-form-item label="封面图片">
- <template v-if="!readonly">
- <el-upload
- :action="uploadActionUrl"
- :headers="uploadHeaders"
- :data="{ category: 'activities' }"
- :on-success="handleUploadSuccess"
- :on-error="handleUploadError"
- :before-upload="beforeUpload"
- :show-file-list="false"
- accept="image/jpeg,image/png,image/gif,image/webp"
- >
- <img v-if="form.coverImage" :src="form.coverImage" class="cover-preview" />
- <el-button v-else type="primary" plain>+ 上传封面</el-button>
- </el-upload>
- <el-button size="mini" plain icon="el-icon-picture-outline" class="ml-10" @click="openCoverAssetPicker">从素材库选择</el-button>
- <el-button v-if="form.coverImage" size="mini" type="text" class="ml-10" @click="form.coverImage = ''">清除</el-button>
- </template>
- <img v-else-if="form.coverImage" :src="form.coverImage" class="cover-preview" />
- <span v-else class="text-muted">无封面</span>
- </el-form-item>
- <el-form-item label="五维权重">
- <dimension-weight-picker v-model="form.dimensionWeights" :show-presets="true" :readonly="readonly" />
- </el-form-item>
- <el-form-item v-if="$route.query.id" label="维度阈值显隐">
- <content-dimension-threshold-editor content-type="ACTIVITY" :content-id="$route.query.id" />
- </el-form-item>
- <el-form-item label="活动标签">
- <el-input v-model="form.tags" :disabled="readonly" placeholder="多个标签用逗号分隔;留空则在提交审核时自动生成" />
- </el-form-item>
- <el-form-item label="活动地点">
- <el-input v-model="form.location" placeholder="请输入活动地点" :disabled="readonly" />
- </el-form-item>
- <el-row :gutter="16">
- <el-col :span="12">
- <el-form-item label="最大人数">
- <el-input-number v-model="form.maxParticipants" :min="0" :max="99999" placeholder="0表示不限" class="full-width" :disabled="readonly" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="价格(元)">
- <el-input-number v-model="form.priceYuan" :min="0" :precision="2" :step="0.01" placeholder="0表示免费" class="full-width" :disabled="readonly" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="16">
- <el-col :span="12">
- <el-form-item label="会员价(元)">
- <el-input-number v-model="form.memberPriceYuan" :min="0" :precision="2" :step="0.01" placeholder="留空等于普通价" class="full-width" :disabled="readonly" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="16">
- <el-col :span="12">
- <el-form-item label="适用人群">
- <el-radio-group v-model="form.audienceScope" :disabled="readonly">
- <el-radio label="all">全部用户</el-radio>
- <el-radio label="member_only">仅会员参加</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="参与人群">
- <el-checkbox-group v-model="form.audienceTypeList" :disabled="readonly">
- <el-checkbox label="adult" disabled>成人</el-checkbox>
- <el-checkbox label="child">含儿童</el-checkbox>
- <el-checkbox label="elder">含长者</el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="16" v-if="form.audienceTypeList && form.audienceTypeList.indexOf('child') >= 0">
- <el-col :span="12">
- <el-form-item label="儿童价格(元)">
- <el-input-number v-model="form.childFeeYuan" :min="0" :precision="2" :step="0.01" placeholder="0表示免费" class="full-width" :disabled="readonly" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="儿童会员价(元)">
- <el-input-number v-model="form.childMemberFeeYuan" :min="0" :precision="2" :step="0.01" placeholder="留空等于儿童普通价" class="full-width" :disabled="readonly" />
- </el-form-item>
- </el-col>
- </el-row>
- <div class="audience-hint" v-if="form.audienceTypeList && form.audienceTypeList.indexOf('child') >= 0">取消勾选「含儿童」后保存,儿童两档费用会写 0(与小程序口径一致)</div>
- <el-row :gutter="16">
- <el-col :span="12">
- <el-form-item label="开始时间" prop="startTime">
- <el-date-picker
- v-model="form.startTime"
- type="datetime"
- placeholder="选择开始时间(以 5 分钟为单元)"
- class="full-width"
- :disabled="readonly"
- format="yyyy-MM-dd HH:mm"
- @change="onStartTimeChange" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="结束时间" prop="endTime">
- <el-date-picker
- v-model="form.endTime"
- type="datetime"
- placeholder="选择结束时间(以 5 分钟为单元)"
- class="full-width"
- :disabled="readonly"
- format="yyyy-MM-dd HH:mm"
- @change="onEndTimeChange" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="16">
- <el-col :span="12">
- <el-form-item label="可见范围">
- <el-select v-model="form.visibility" placeholder="请选择可见范围" class="full-width" :disabled="readonly">
- <el-option label="公开" value="public" />
- <el-option label="受限" value="restricted" />
- <el-option label="全体" value="all" />
- <el-option label="会员" value="member" />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="可见对象">
- <el-select v-model="form.visibleScope" placeholder="请选择可见对象类型" class="full-width" :disabled="readonly">
- <el-option label="不限" value="" />
- <el-option label="家庭" value="family" />
- <el-option label="角色" value="role" />
- <el-option label="用户" value="user" />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-form-item label="可见对象ID" v-if="form.visibleScope">
- <el-input v-model="form.visibleTo" placeholder="多个用逗号分隔,如: family_1,family_2" :disabled="readonly" />
- </el-form-item>
- <el-form-item label="签到积分">
- <el-input-number v-model="form.checkinPoints" :min="0" :max="9999" placeholder="0使用系统默认" class="w-200" :disabled="readonly" />
- <span class="form-hint">0表示使用系统默认积分</span>
- </el-form-item>
- </el-form>
- </div>
- </el-card>
- <!-- 创建成功弹窗 -->
- <el-dialog title="创建成功" :visible.sync="successDialogVisible" width="420px" :close-on-click-modal="false" :show-close="false">
- <div class="success-body">
- <i class="el-icon-circle-check success-icon"></i>
- <p class="success-text">活动「{{ form.title }}」已创建成功</p>
- </div>
- <div slot="footer" class="success-footer">
- <el-button @click="handleContinueAdd">继续添加</el-button>
- <el-button @click="$router.push('/activities')">返回列表</el-button>
- <el-button type="primary" @click="handlePublishAndBack" :loading="publishing">直接发布</el-button>
- </div>
- </el-dialog>
- <!-- 素材库选择器 -->
- <AssetPicker
- :visible.sync="assetPickerVisible"
- mode="single"
- :asset-type="assetPickerType"
- category="activities"
- @select="onAssetPicked"
- />
- </div>
- </template>
- <script>
- import DimensionWeightPicker from '@/components/DimensionWeightPicker.vue'
- import ContentDimensionThresholdEditor from '@/components/ContentDimensionThresholdEditor.vue'
- import { getActivityDetail, createActivity, updateActivity, publishActivity, submitActivityReview, reDraftActivity, getRegistrationRoster } from '@/api/activity'
- import { saveDimensionWeights, getDimensionWeights } from '@/api/dimension-weight.js'
- import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
- import '@wangeditor/editor/dist/css/style.css'
- import AssetPicker from '@/components/AssetPicker.vue'
- import { buildEditorAssetMenuConf, insertAssetIntoEditor, getEditorCustomAlert, registerAssetLibraryMenu, setAssetMenuHandler, buildAssetToolbarConfig } from '@/utils/editorAssetUpload'
- export default {
- name: 'ActivityEdit',
- components: { DimensionWeightPicker, ContentDimensionThresholdEditor, Editor, Toolbar, AssetPicker },
- data() {
- return {
- isEdit: false,
- loading: false,
- saving: false,
- publishing: false,
- readonly: false,
- activityStatus: '',
- auditReason: '',
- reviewLoading: false,
- reDraftLoading: false,
- successDialogVisible: false,
- createdActivityId: null,
- form: {
- title: '',
- intro: '',
- coverImage: '',
- activityType: '',
- description: '',
- dimensionCode: '',
- dimensionWeights: [],
- tags: '',
- location: '',
- maxParticipants: null,
- priceYuan: null,
- memberPriceYuan: null,
- // A3:适用人群(字段名与取值对齐 A2 的 ActivityDTO)
- audienceScope: 'all',
- audienceTypeList: ['adult'],
- childFeeYuan: null,
- childMemberFeeYuan: null,
- startTime: null,
- endTime: null,
- visibility: 'public',
- visibleScope: '',
- visibleTo: '',
- checkinPoints: 0
- },
- formRules: {
- title: [
- { required: true, message: '请填写活动标题', trigger: 'blur' }
- ],
- activityType: [
- { required: true, message: '请选择活动类型', trigger: 'change' }
- ],
- description: [
- { required: true, message: '请填写活动描述', trigger: 'blur' }
- ],
- startTime: [
- { required: true, message: '请选择开始时间', trigger: 'change' }
- ],
- endTime: [
- { required: true, message: '请选择结束时间', trigger: 'change' }
- ]
- },
- editorConfig: null,
- toolbarConfig: buildAssetToolbarConfig(),
- editorInstance: null,
- assetPickerVisible: false,
- assetPickerType: 'image',
- assetPickerTarget: 'content',
- // T03 报名名册
- roster: { approvedCount: 0, pendingCount: 0, remaining: null },
- rosterRegistrants: [],
- rosterLoading: false
- }
- },
- computed: {
- showRosterCard() {
- // 仅需报名的活动,在详情页(readonly)或编辑已发布活动页显示报名名册
- return this.readonly && this.form.requireRegistration === 1
- },
- statusLabel() {
- const map = { draft: '当前状态:草稿箱', pending: '当前状态:待审核(等待管理员审核)', rejected: '当前状态:已驳回', published: '当前状态:发布中', withdrawn: '当前状态:已撤回' }
- return map[this.activityStatus] || ''
- },
- statusType() {
- const map = { draft: 'info', pending: 'warning', rejected: 'error', published: 'success', withdrawn: 'info' }
- return map[this.activityStatus] || 'info'
- },
- statusDescription() {
- if (this.activityStatus === 'rejected' && this.auditReason) return '原因:' + this.auditReason
- return ''
- },
- uploadActionUrl() {
- const baseURL = process.env.VUE_APP_BASE_API || ''
- return baseURL + '/api/admin/file-record/upload'
- },
- uploadHeaders() {
- const token = localStorage.getItem('token')
- return token ? { Authorization: 'Bearer ' + token } : {}
- }
- },
- created() {
- registerAssetLibraryMenu()
- setAssetMenuHandler(() => {
- this.assetPickerTarget = 'content'
- this.assetPickerType = 'image'
- this.assetPickerVisible = true
- })
- this.initEditorConfig()
- const id = this.$route.query.id
- this.readonly = this.$route.query.readonly === '1'
- if (id) {
- this.isEdit = true
- this.loadDetail(id)
- }
- },
- methods: {
- initEditorConfig() {
- // 上传统一写入素材库(file_record),并修复旧 customInsert 的 baseURL 双前缀问题
- this.editorConfig = {
- // wangEditor 从编辑器顶层 config.customAlert 读取(不是 MENU_CONF.uploadImage.customAlert)
- customAlert: getEditorCustomAlert(),
- MENU_CONF: buildEditorAssetMenuConf({ category: 'activities' })
- }
- },
- handleEditorCreated(editor) {
- // Vue 2 必须 seal,否则会把 editor 做成响应式,内部 WeakMap 取不到实例
- this.editorInstance = Object.seal(editor)
- },
- // ===== 素材库 =====
- openAssetPicker(type) {
- this.assetPickerTarget = 'content'
- this.assetPickerType = type || 'image'
- this.assetPickerVisible = true
- },
- openCoverAssetPicker() {
- this.assetPickerTarget = 'cover'
- this.assetPickerType = 'image'
- this.assetPickerVisible = true
- },
- onAssetPicked(records) {
- const record = records && records[0]
- if (!record) return
- if (this.assetPickerTarget === 'cover') {
- this.form.coverImage = record.url
- this.$message.success('已选择封面')
- return
- }
- if (!this.editorInstance) {
- this.$message.warning('编辑器尚未初始化完成')
- return
- }
- insertAssetIntoEditor(this.editorInstance, record, this.assetPickerType)
- },
- // 活动时间收敛到 5 分钟粒度:分钟向下取整到 5 的倍数、秒清零(14:07 → 14:05)。
- // Date 入参返回 Date(与 v-model 类型保持一致,提交时仍由 axios 序列化为带秒的 ISO 串);
- // 字符串入参(详情回填)返回 ISO 串,均不改变后端既有解析契约。
- floorTo5Minutes(value) {
- if (!value) return value
- const isDateObj = value instanceof Date
- const d = isDateObj ? new Date(value.getTime()) : new Date(value)
- if (isNaN(d.getTime())) return value
- d.setMinutes(Math.floor(d.getMinutes() / 5) * 5, 0, 0)
- return isDateObj ? d : d.toISOString()
- },
- // 选择后兜底:输入框可手动输入,非 5 倍数分钟在此收敛
- onStartTimeChange(val) {
- this.form.startTime = this.floorTo5Minutes(val)
- },
- onEndTimeChange(val) {
- this.form.endTime = this.floorTo5Minutes(val)
- },
- // A3:audienceType(单值编码)→ 后台多选勾选数组(成人恒选)
- buildAudienceTypeList(type) {
- const t = type || 'adult'
- const list = ['adult']
- if (t === 'include_child' || t === 'include_child_elder') list.push('child')
- if (t === 'include_elder' || t === 'include_child_elder') list.push('elder')
- return list
- },
- // A3:后台多选勾选数组 → audienceType(单值编码,字段名对齐 A2 的 ActivityDTO)
- encodeAudienceType() {
- const list = this.form.audienceTypeList || ['adult']
- const hasChild = list.indexOf('child') >= 0
- const hasElder = list.indexOf('elder') >= 0
- if (hasChild && hasElder) return 'include_child_elder'
- if (hasChild) return 'include_child'
- if (hasElder) return 'include_elder'
- return 'adult'
- },
- // A3:是否勾选儿童人群(决定儿童两档费用是否显示 / 是否提交)
- includeChildAudience() {
- const list = this.form.audienceTypeList || []
- return list.indexOf('child') >= 0
- },
- async loadDetail(id) {
- this.loading = true
- try {
- const res = await getActivityDetail({ id })
- if (res.data) {
- const d = res.data
- this.activityStatus = d.status || ''
- this.auditReason = d.auditReason || ''
- // Set readonly based on workflow status
- if (d.status === 'pending' || d.status === 'rejected' || d.status === 'withdrawn') {
- this.readonly = true
- } else if (this.$route.query.readonly === '1') {
- this.readonly = true
- } else {
- this.readonly = false
- }
- this.form = {
- title: d.title || '',
- intro: d.intro || '',
- coverImage: d.coverImage || '',
- activityType: d.activityType || '',
- description: d.description || '',
- dimensionCode: d.dimensionCode || '',
- dimensionWeights: [],
- tags: d.tags || '',
- location: d.location || '',
- maxParticipants: d.maxParticipants || null,
- priceYuan: d.price ? d.price / 100 : null,
- memberPriceYuan: d.memberPrice && d.memberPrice > 0 ? d.memberPrice / 100 : null,
- // A3:适用人群回显(A2 未合入前 d.audienceScope/d.audienceType 可能缺失,取默认值)
- audienceScope: d.audienceScope || 'all',
- audienceTypeList: this.buildAudienceTypeList(d.audienceType),
- childFeeYuan: d.childFee ? d.childFee / 100 : null,
- childMemberFeeYuan: d.childMemberFee && d.childMemberFee > 0 ? d.childMemberFee / 100 : null,
- startTime: this.floorTo5Minutes(d.startTime),
- endTime: this.floorTo5Minutes(d.endTime),
- visibility: d.visibility || 'public',
- visibleScope: d.visibleScope || '',
- visibleTo: d.visibleTo || '',
- checkinPoints: d.checkinPoints || 0,
- requireRegistration: d.requireRegistration != null ? d.requireRegistration : 0
- }
- try {
- const dwRes = await getDimensionWeights('activity', d.id)
- if (dwRes.data) {
- this.form.dimensionWeights = dwRes.data
- }
- } catch (e) {
- }
- // T03:需报名的活动自动拉取名册(详情页/编辑页都展示)
- if (this.form.requireRegistration === 1) {
- this.loadRoster()
- }
- }
- } catch (e) {
- this.$message.error('加载活动详情失败')
- } finally {
- this.loading = false
- }
- },
- // ===== T03 报名名册 =====
- // 后端把 java.util.Date 序列化为 UTC 偏移串(如 2026-10-25T01:00:00.000+00:00),
- // 统一转 Asia/Shanghai 本地墙钟时间展示,避免比实际时间少 8 小时
- formatTime(t) {
- if (!t) return '-'
- const d = new Date(t)
- if (isNaN(d.getTime())) return String(t)
- const bj = new Date(d.getTime() + d.getTimezoneOffset() * 60000 + 8 * 3600000)
- const pad = n => (n < 10 ? '0' + n : '' + n)
- return bj.getFullYear() + '-' + pad(bj.getMonth() + 1) + '-' + pad(bj.getDate()) + ' ' +
- pad(bj.getHours()) + ':' + pad(bj.getMinutes()) + ':' + pad(bj.getSeconds())
- },
- async loadRoster() {
- if (!this.$route.query.id) return
- this.rosterLoading = true
- try {
- const res = await getRegistrationRoster(this.$route.query.id)
- if (res && res.data) {
- this.roster = res.data
- this.rosterRegistrants = res.data.registrants || []
- }
- } catch (e) {
- this.$message.error('加载报名名册失败')
- } finally {
- this.rosterLoading = false
- }
- },
- exportRosterCsv() {
- if (!this.rosterRegistrants.length) return
- var rows = ['姓名,报名时间']
- this.rosterRegistrants.forEach(function(r) {
- var name = String(r.name || '').replace(/,/g, ',')
- var time = r.registeredAt ? String(r.registeredAt).replace('T', ' ').substring(0, 19) : ''
- rows.push(name + ',' + time)
- })
- // 汇总行(Excel 友好:UTF-8 BOM)
- var csv = '\uFEFF' + rows.join('\r\n') + '\r\n'
- var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
- var link = document.createElement('a')
- link.href = URL.createObjectURL(blob)
- link.download = '报名名册-' + (this.form.title || '活动') + '.csv'
- link.click()
- URL.revokeObjectURL(link.href)
- this.$message.success('已导出 ' + this.rosterRegistrants.length + ' 条报名记录')
- },
- beforeUpload(file) {
- const isImage = file.type === 'image/jpeg' || file.type === 'image/png' ||
- file.type === 'image/gif' || file.type === 'image/webp'
- if (!isImage) {
- this.$message.error('只能上传 JPG/PNG/GIF/WebP 格式图片')
- return false
- }
- const isLt5M = file.size / 1024 / 1024 < 5
- if (!isLt5M) {
- this.$message.error('图片大小不能超过 5MB')
- return false
- }
- return true
- },
- handleUploadSuccess(resp) {
- if (resp.code === 0 || resp.code === 200) {
- // 存库使用后端返回的原始 URL,避免把代理前缀写入数据库
- const url = resp.data && resp.data.url ? resp.data.url : (typeof resp.data === 'string' ? resp.data : '')
- this.form.coverImage = url
- this.$message.success('封面上传成功')
- } else {
- this.$message.error((resp && resp.message) || '封面上传失败')
- }
- },
- handleUploadError() {
- this.$message.error('封面上传失败,请重试')
- },
- async saveActivity(publishNow) {
- // 表单验证
- try {
- await this.$refs.form.validate()
- } catch (e) {
- return
- }
- if (publishNow) {
- this.publishing = true
- } else {
- this.saving = true
- }
- try {
- const payload = {
- title: this.form.title,
- intro: this.form.intro,
- coverImage: this.form.coverImage,
- activityType: this.form.activityType,
- description: this.form.description,
- dimensionCode: this.form.dimensionCode,
- location: this.form.location,
- maxParticipants: this.form.maxParticipants,
- price: this.form.priceYuan != null ? Math.round(this.form.priceYuan * 100) : 0,
- memberPrice: this.form.memberPriceYuan != null && this.form.memberPriceYuan > 0 ? Math.round(this.form.memberPriceYuan * 100) : 0,
- // A3:适用人群 + 儿童费用档(字段名对齐 A2 的 ActivityDTO;未勾选儿童时写 0)
- audienceScope: this.form.audienceScope || 'all',
- audienceType: this.encodeAudienceType(),
- childFee: this.includeChildAudience() && this.form.childFeeYuan != null ? Math.round(this.form.childFeeYuan * 100) : 0,
- childMemberFee: this.includeChildAudience() && this.form.childMemberFeeYuan != null && this.form.childMemberFeeYuan > 0 ? Math.round(this.form.childMemberFeeYuan * 100) : 0,
- startTime: this.form.startTime,
- endTime: this.form.endTime,
- visibility: this.form.visibility,
- visibleScope: this.form.visibleScope,
- visibleTo: this.form.visibleTo,
- checkinPoints: this.form.checkinPoints || 0,
- tags: this.form.tags || ''
- }
- if (this.isEdit) {
- // 编辑模式:保存后直接返回列表
- payload.id = this.form._activityId || this.$route.query.id
- await updateActivity(payload)
- if (this.form.dimensionWeights && this.form.dimensionWeights.length) {
- try {
- await saveDimensionWeights('activity', payload.id, this.form.dimensionWeights)
- } catch (e) {
- console.error('保存维度权重失败', e)
- }
- }
- this.$message.success('更新成功')
- this.$router.push('/activities')
- } else {
- // 创建模式:保存后弹窗
- const res = await createActivity(payload)
- if (res.data && res.data.id) {
- this.createdActivityId = res.data.id
- }
- this.isEdit = true
- this.saving = false
- this.successDialogVisible = true
- }
- } catch (e) {
- this.$message.error('保存失败')
- } finally {
- this.saving = false
- this.publishing = false
- }
- },
- handleContinueAdd() {
- this.successDialogVisible = false
- this.form = {
- title: '',
- intro: '',
- coverImage: '',
- activityType: '',
- description: '',
- dimensionCode: '',
- dimensionWeights: [],
- tags: '',
- location: '',
- maxParticipants: null,
- priceYuan: null,
- memberPriceYuan: null,
- audienceScope: 'all',
- audienceTypeList: ['adult'],
- childFeeYuan: null,
- childMemberFeeYuan: null,
- startTime: null,
- endTime: null,
- visibility: 'public',
- visibleScope: '',
- visibleTo: '',
- checkinPoints: 0
- }
- this.isEdit = false
- this.createdActivityId = null
- this.$refs.form && this.$refs.form.clearValidate()
- },
- async handlePublishAndBack() {
- this.successDialogVisible = false
- const activityId = this.createdActivityId
- if (!activityId) {
- this.$router.push('/activities')
- return
- }
- // 先保存维度权重
- if (this.form.dimensionWeights && this.form.dimensionWeights.length) {
- try {
- await saveDimensionWeights('activity', activityId, this.form.dimensionWeights)
- } catch (e) {
- console.error('保存维度权重失败', e)
- }
- }
- // 发布
- try {
- this.publishing = true
- await publishActivity(activityId)
- this.$message.success('发布成功')
- } catch (e) {
- this.$message.error('发布失败')
- } finally {
- this.publishing = false
- }
- this.$router.push('/activities')
- },
- editFromReadonly() {
- this.readonly = false
- },
- async handleSubmitReview() {
- this.reviewLoading = true
- try {
- // Save activity first
- const payload = {
- title: this.form.title,
- intro: this.form.intro,
- coverImage: this.form.coverImage,
- activityType: this.form.activityType,
- description: this.form.description,
- dimensionCode: this.form.dimensionCode,
- location: this.form.location,
- maxParticipants: this.form.maxParticipants,
- price: this.form.priceYuan != null ? Math.round(this.form.priceYuan * 100) : 0,
- memberPrice: this.form.memberPriceYuan != null && this.form.memberPriceYuan > 0 ? Math.round(this.form.memberPriceYuan * 100) : 0,
- // A3:适用人群 + 儿童费用档(字段名对齐 A2 的 ActivityDTO;未勾选儿童时写 0)
- audienceScope: this.form.audienceScope || 'all',
- audienceType: this.encodeAudienceType(),
- childFee: this.includeChildAudience() && this.form.childFeeYuan != null ? Math.round(this.form.childFeeYuan * 100) : 0,
- childMemberFee: this.includeChildAudience() && this.form.childMemberFeeYuan != null && this.form.childMemberFeeYuan > 0 ? Math.round(this.form.childMemberFeeYuan * 100) : 0,
- startTime: this.form.startTime,
- endTime: this.form.endTime,
- visibility: this.form.visibility,
- visibleScope: this.form.visibleScope,
- visibleTo: this.form.visibleTo,
- checkinPoints: this.form.checkinPoints || 0,
- tags: this.form.tags || ''
- }
- const activityId = this.form._activityId || this.$route.query.id
- if (
- activityId
- ) {
- payload.id = activityId
- await updateActivity(payload)
- } else {
- const res = await createActivity(payload)
- if (res.data && res.data.id) {
- payload.id = res.data.id
- this.form._activityId = res.data.id
- this.isEdit = true
- }
- }
- if (payload.id && this.form.dimensionWeights && this.form.dimensionWeights.length) {
- try { await saveDimensionWeights('activity', payload.id, this.form.dimensionWeights) } catch (e) {}
- }
- // Submit for review
- await submitActivityReview({ id: payload.id })
- this.$message.success('已提交审核')
- this.$router.push('/activities')
- } catch (e) {
- this.$message.error(e.message || '提交审核失败')
- } finally {
- this.reviewLoading = false
- }
- },
- async handleReDraft() {
- this.reDraftLoading = true
- try {
- await reDraftActivity({ id: this.$route.query.id })
- this.$message.success('已保存到草稿箱')
- this.activityStatus = 'draft'
- this.readonly = false
- } catch (e) {
- this.$message.error(e.message || '操作失败')
- } finally {
- this.reDraftLoading = false
- }
- }
- }
- }
- </script>
- <style scoped>
- /* == C 批内联清理工具类 == */
- .mb-16 { margin-bottom: 16px; }
- .full-width { width: 100%; }
- .w-200 { width: 200px; }
- .ml-10 { margin-left: 10px; }
- .text-muted { color: var(--adm-text-45); }
- .editor-body { min-height: 300px; }
- .form-hint { margin-left: 8px; color: var(--adm-text-45); font-size: 12px; }
- .audience-hint { margin: -4px 0 16px 2px; color: var(--adm-text-45); font-size: 12px; }
- .success-body { text-align: center; padding: 10px 0; }
- .success-icon { font-size: 48px; color: var(--adm-success); }
- .success-text { font-size: 16px; margin-top: 12px; }
- .success-footer { text-align: center; }
- .activity-edit {
- padding: 24px;
- flex: 1;
- display: flex;
- flex-direction: column;
- min-height: 0;
- }
- .activity-edit > .el-card {
- flex: 1;
- display: flex;
- flex-direction: column;
- min-height: 0;
- width: 100%;
- }
- .activity-edit > .el-card /deep/ .el-card__body {
- flex: 1;
- display: flex;
- flex-direction: column;
- min-height: 0;
- overflow: hidden;
- padding: 24px;
- width: 100%;
- box-sizing: border-box;
- }
- .activity-edit /deep/ .el-form {
- width: 100%;
- }
- .activity-edit /deep/ .admin-page-actions {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- gap: 8px;
- flex-wrap: wrap;
- margin-left: auto;
- }
- .cover-preview {
- width: 200px;
- height: 120px;
- object-fit: cover;
- border-radius: 4px;
- border: 1px solid var(--adm-border-base);
- }
- .rich-editor {
- border: 1px solid var(--adm-border-base);
- border-radius: 4px;
- }
- .editor-extra-row {
- display: flex;
- gap: 8px;
- padding: 6px 8px;
- border-bottom: 1px solid var(--adm-border-base);
- }
- .rich-editor /deep/ .w-e-toolbar {
- flex-wrap: wrap;
- }
- .rich-editor /deep/ .w-e-text-container {
- min-height: 300px;
- max-height: 500px;
- overflow-y: auto;
- }
- /* 内滚动容器:利用 el-card__body flex column 让表单区域独立滚动 */
- .activity-edit-form-wrap {
- flex: 1;
- min-height: 0;
- overflow-y: auto;
- overflow-x: hidden;
- padding-right: 8px;
- margin-right: -8px;
- }
- /* ===== T03 报名名册 ===== */
- .roster-card {
- margin-bottom: 16px;
- flex-shrink: 0;
- }
- .roster-card /deep/ .el-card__header {
- padding: 10px 24px;
- }
- .roster-card-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: 15px;
- font-weight: 600;
- color: var(--adm-text-88);
- }
- .roster-card-actions {
- display: flex;
- gap: 8px;
- }
- .roster-stats {
- margin-bottom: 12px;
- }
- .stat-box {
- padding: 8px 12px;
- background: var(--adm-bg-header);
- border-radius: 4px;
- text-align: center;
- }
- .stat-num {
- font-size: 20px;
- font-weight: 700;
- color: var(--adm-text-88);
- }
- .stat-danger {
- color: #f56c6c;
- }
- .stat-label {
- font-size: 12px;
- color: var(--adm-text-45);
- margin-top: 4px;
- }
- .roster-list {
- border-top: 1px solid var(--adm-border-split);
- padding-top: 12px;
- }
- .roster-list-title {
- font-size: 14px;
- font-weight: 600;
- color: var(--adm-text-88);
- margin-bottom: 8px;
- }
- .roster-list-body {
- max-height: 200px;
- overflow-y: auto;
- }
- .roster-item {
- display: flex;
- justify-content: space-between;
- padding: 6px 0;
- border-bottom: 1px solid var(--adm-border-split);
- }
- .roster-item:last-child {
- border-bottom: none;
- }
- .roster-name {
- font-size: 14px;
- color: var(--adm-text-strong);
- }
- .roster-time {
- font-size: 12px;
- color: var(--adm-text-45);
- }
- .roster-empty {
- font-size: 12px;
- color: var(--adm-text-45);
- text-align: center;
- padding: 24px 0;
- }
- </style>
|