ActivityEdit.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. <template>
  2. <div class="activity-edit admin-page">
  3. <el-card>
  4. <PageHeader slot="header" :title="readonly && activityStatus !== 'rejected' ? '活动详情' : (isEdit ? '编辑活动' : '创建活动')">
  5. <div class="admin-page-actions">
  6. <el-button @click="$router.push('/activities')">返回列表</el-button>
  7. <template v-if="!readonly && activityStatus !== 'rejected'">
  8. <el-button type="primary" @click="saveActivity(false)" :loading="saving">{{ activityStatus === 'published' ? '保存修改' : '保存草稿' }}</el-button>
  9. <el-button v-if="isEdit && activityStatus !== 'published'" type="success" @click="handleSubmitReview" :loading="reviewLoading">提交审核</el-button>
  10. </template>
  11. <template v-if="activityStatus === 'rejected'">
  12. <el-button type="primary" @click="handleReDraft" :loading="reDraftLoading">保存到草稿箱重新编辑</el-button>
  13. </template>
  14. <template v-if="readonly && activityStatus === 'draft' && !isEdit">
  15. <el-button type="primary" size="mini" @click="editFromReadonly">编辑</el-button>
  16. </template>
  17. </div>
  18. </PageHeader>
  19. <!-- 状态横幅 -->
  20. <el-alert
  21. v-if="statusLabel"
  22. :title="statusLabel"
  23. :type="statusType"
  24. :description="statusDescription"
  25. show-icon
  26. :closable="false"
  27. class="mb-16"
  28. />
  29. <!-- 报名名册(T03:仅需报名的活动展示,详情页/编辑页均可查看) -->
  30. <el-card v-if="showRosterCard" class="roster-card" shadow="never">
  31. <div slot="header" class="roster-card-header">
  32. <span>报名名册</span>
  33. <div class="roster-card-actions">
  34. <el-button size="mini" :loading="rosterLoading" @click="loadRoster">刷新</el-button>
  35. <el-button size="mini" type="primary" :disabled="!rosterRegistrants.length" @click="exportRosterCsv">导出 CSV</el-button>
  36. </div>
  37. </div>
  38. <div v-loading="rosterLoading" class="roster-body">
  39. <el-row :gutter="12" class="roster-stats">
  40. <el-col :span="8">
  41. <div class="stat-box">
  42. <div class="stat-num">{{ roster.approvedCount != null ? roster.approvedCount : '-' }}</div>
  43. <div class="stat-label">已通过报名</div>
  44. </div>
  45. </el-col>
  46. <el-col :span="8">
  47. <div class="stat-box">
  48. <div class="stat-num">{{ roster.pendingCount != null ? roster.pendingCount : '-' }}</div>
  49. <div class="stat-label">待审核</div>
  50. </div>
  51. </el-col>
  52. <el-col :span="8">
  53. <div class="stat-box">
  54. <div class="stat-num" :class="{ 'stat-danger': roster.remaining != null && roster.remaining <= 0 }">
  55. {{ roster.remaining != null ? roster.remaining : '不限' }}
  56. </div>
  57. <div class="stat-label">剩余名额</div>
  58. </div>
  59. </el-col>
  60. </el-row>
  61. <div class="roster-list">
  62. <div class="roster-list-title">最近报名人({{ rosterRegistrants.length }})</div>
  63. <div v-if="rosterRegistrants.length" class="roster-list-body">
  64. <div v-for="(r, idx) in rosterRegistrants" :key="'roster-' + idx" class="roster-item">
  65. <span class="roster-name">{{ r.name }}</span>
  66. <span class="roster-time">{{ formatTime(r.registeredAt) }}</span>
  67. </div>
  68. </div>
  69. <div v-else class="roster-empty">还没有人报名,快来抢占第一个名额吧</div>
  70. </div>
  71. </div>
  72. </el-card>
  73. <div class="activity-edit-form-wrap">
  74. <el-form label-width="120px" v-loading="loading" :model="form" :rules="formRules" ref="form">
  75. <el-form-item label="活动标题" prop="title">
  76. <el-input v-model="form.title" placeholder="请输入活动标题" :disabled="readonly" />
  77. </el-form-item>
  78. <el-form-item label="活动简介">
  79. <el-input v-model="form.intro" placeholder="一句话介绍活动,将展示在活动列表卡片上" maxlength="200" show-word-limit :disabled="readonly" />
  80. </el-form-item>
  81. <el-form-item label="活动类型" prop="activityType">
  82. <el-select v-model="form.activityType" placeholder="请选择活动类型" class="full-width" :disabled="readonly">
  83. <el-option label="线下活动" value="offline" />
  84. <el-option label="线上活动" value="online" />
  85. <el-option label="主题活动" value="campaign" />
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item label="活动描述" prop="description">
  89. <div class="rich-editor" :class="{ 'is-disabled': readonly }">
  90. <div v-if="!readonly" class="editor-extra-row">
  91. <el-button size="mini" plain icon="el-icon-picture-outline" @click="openAssetPicker('image')">从素材库选择图片</el-button>
  92. <el-button size="mini" plain icon="el-icon-video-camera" @click="openAssetPicker('video')">从素材库选择视频</el-button>
  93. </div>
  94. <Toolbar :editor="editorInstance" :defaultConfig="toolbarConfig" />
  95. <Editor :defaultConfig="editorConfig" v-model="form.description" @onCreated="handleEditorCreated" :disabled="readonly" class="editor-body" />
  96. </div>
  97. </el-form-item>
  98. <el-form-item label="封面图片">
  99. <template v-if="!readonly">
  100. <el-upload
  101. :action="uploadActionUrl"
  102. :headers="uploadHeaders"
  103. :data="{ category: 'activities' }"
  104. :on-success="handleUploadSuccess"
  105. :on-error="handleUploadError"
  106. :before-upload="beforeUpload"
  107. :show-file-list="false"
  108. accept="image/jpeg,image/png,image/gif,image/webp"
  109. >
  110. <img v-if="form.coverImage" :src="form.coverImage" class="cover-preview" />
  111. <el-button v-else type="primary" plain>+ 上传封面</el-button>
  112. </el-upload>
  113. <el-button size="mini" plain icon="el-icon-picture-outline" class="ml-10" @click="openCoverAssetPicker">从素材库选择</el-button>
  114. <el-button v-if="form.coverImage" size="mini" type="text" class="ml-10" @click="form.coverImage = ''">清除</el-button>
  115. </template>
  116. <img v-else-if="form.coverImage" :src="form.coverImage" class="cover-preview" />
  117. <span v-else class="text-muted">无封面</span>
  118. </el-form-item>
  119. <el-form-item label="五维权重">
  120. <dimension-weight-picker v-model="form.dimensionWeights" :show-presets="true" :readonly="readonly" />
  121. </el-form-item>
  122. <el-form-item v-if="$route.query.id" label="维度阈值显隐">
  123. <content-dimension-threshold-editor content-type="ACTIVITY" :content-id="$route.query.id" />
  124. </el-form-item>
  125. <el-form-item label="活动标签">
  126. <el-input v-model="form.tags" :disabled="readonly" placeholder="多个标签用逗号分隔;留空则在提交审核时自动生成" />
  127. </el-form-item>
  128. <el-form-item label="活动地点">
  129. <el-input v-model="form.location" placeholder="请输入活动地点" :disabled="readonly" />
  130. </el-form-item>
  131. <el-row :gutter="16">
  132. <el-col :span="12">
  133. <el-form-item label="最大人数">
  134. <el-input-number v-model="form.maxParticipants" :min="0" :max="99999" placeholder="0表示不限" class="full-width" :disabled="readonly" />
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="12">
  138. <el-form-item label="价格(元)">
  139. <el-input-number v-model="form.priceYuan" :min="0" :precision="2" :step="0.01" placeholder="0表示免费" class="full-width" :disabled="readonly" />
  140. </el-form-item>
  141. </el-col>
  142. </el-row>
  143. <el-row :gutter="16">
  144. <el-col :span="12">
  145. <el-form-item label="会员价(元)">
  146. <el-input-number v-model="form.memberPriceYuan" :min="0" :precision="2" :step="0.01" placeholder="留空等于普通价" class="full-width" :disabled="readonly" />
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row :gutter="16">
  151. <el-col :span="12">
  152. <el-form-item label="适用人群">
  153. <el-radio-group v-model="form.audienceScope" :disabled="readonly">
  154. <el-radio label="all">全部用户</el-radio>
  155. <el-radio label="member_only">仅会员参加</el-radio>
  156. </el-radio-group>
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="12">
  160. <el-form-item label="参与人群">
  161. <el-checkbox-group v-model="form.audienceTypeList" :disabled="readonly">
  162. <el-checkbox label="adult" disabled>成人</el-checkbox>
  163. <el-checkbox label="child">含儿童</el-checkbox>
  164. <el-checkbox label="elder">含长者</el-checkbox>
  165. </el-checkbox-group>
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. <el-row :gutter="16" v-if="form.audienceTypeList && form.audienceTypeList.indexOf('child') >= 0">
  170. <el-col :span="12">
  171. <el-form-item label="儿童价格(元)">
  172. <el-input-number v-model="form.childFeeYuan" :min="0" :precision="2" :step="0.01" placeholder="0表示免费" class="full-width" :disabled="readonly" />
  173. </el-form-item>
  174. </el-col>
  175. <el-col :span="12">
  176. <el-form-item label="儿童会员价(元)">
  177. <el-input-number v-model="form.childMemberFeeYuan" :min="0" :precision="2" :step="0.01" placeholder="留空等于儿童普通价" class="full-width" :disabled="readonly" />
  178. </el-form-item>
  179. </el-col>
  180. </el-row>
  181. <div class="audience-hint" v-if="form.audienceTypeList && form.audienceTypeList.indexOf('child') >= 0">取消勾选「含儿童」后保存,儿童两档费用会写 0(与小程序口径一致)</div>
  182. <el-row :gutter="16">
  183. <el-col :span="12">
  184. <el-form-item label="开始时间" prop="startTime">
  185. <el-date-picker
  186. v-model="form.startTime"
  187. type="datetime"
  188. placeholder="选择开始时间(以 5 分钟为单元)"
  189. class="full-width"
  190. :disabled="readonly"
  191. format="yyyy-MM-dd HH:mm"
  192. @change="onStartTimeChange" />
  193. </el-form-item>
  194. </el-col>
  195. <el-col :span="12">
  196. <el-form-item label="结束时间" prop="endTime">
  197. <el-date-picker
  198. v-model="form.endTime"
  199. type="datetime"
  200. placeholder="选择结束时间(以 5 分钟为单元)"
  201. class="full-width"
  202. :disabled="readonly"
  203. format="yyyy-MM-dd HH:mm"
  204. @change="onEndTimeChange" />
  205. </el-form-item>
  206. </el-col>
  207. </el-row>
  208. <el-row :gutter="16">
  209. <el-col :span="12">
  210. <el-form-item label="可见范围">
  211. <el-select v-model="form.visibility" placeholder="请选择可见范围" class="full-width" :disabled="readonly">
  212. <el-option label="公开" value="public" />
  213. <el-option label="受限" value="restricted" />
  214. <el-option label="全体" value="all" />
  215. <el-option label="会员" value="member" />
  216. </el-select>
  217. </el-form-item>
  218. </el-col>
  219. <el-col :span="12">
  220. <el-form-item label="可见对象">
  221. <el-select v-model="form.visibleScope" placeholder="请选择可见对象类型" class="full-width" :disabled="readonly">
  222. <el-option label="不限" value="" />
  223. <el-option label="家庭" value="family" />
  224. <el-option label="角色" value="role" />
  225. <el-option label="用户" value="user" />
  226. </el-select>
  227. </el-form-item>
  228. </el-col>
  229. </el-row>
  230. <el-form-item label="可见对象ID" v-if="form.visibleScope">
  231. <el-input v-model="form.visibleTo" placeholder="多个用逗号分隔,如: family_1,family_2" :disabled="readonly" />
  232. </el-form-item>
  233. <el-form-item label="签到积分">
  234. <el-input-number v-model="form.checkinPoints" :min="0" :max="9999" placeholder="0使用系统默认" class="w-200" :disabled="readonly" />
  235. <span class="form-hint">0表示使用系统默认积分</span>
  236. </el-form-item>
  237. </el-form>
  238. </div>
  239. </el-card>
  240. <!-- 创建成功弹窗 -->
  241. <el-dialog title="创建成功" :visible.sync="successDialogVisible" width="420px" :close-on-click-modal="false" :show-close="false">
  242. <div class="success-body">
  243. <i class="el-icon-circle-check success-icon"></i>
  244. <p class="success-text">活动「{{ form.title }}」已创建成功</p>
  245. </div>
  246. <div slot="footer" class="success-footer">
  247. <el-button @click="handleContinueAdd">继续添加</el-button>
  248. <el-button @click="$router.push('/activities')">返回列表</el-button>
  249. <el-button type="primary" @click="handlePublishAndBack" :loading="publishing">直接发布</el-button>
  250. </div>
  251. </el-dialog>
  252. <!-- 素材库选择器 -->
  253. <AssetPicker
  254. :visible.sync="assetPickerVisible"
  255. mode="single"
  256. :asset-type="assetPickerType"
  257. category="activities"
  258. @select="onAssetPicked"
  259. />
  260. </div>
  261. </template>
  262. <script>
  263. import DimensionWeightPicker from '@/components/DimensionWeightPicker.vue'
  264. import ContentDimensionThresholdEditor from '@/components/ContentDimensionThresholdEditor.vue'
  265. import { getActivityDetail, createActivity, updateActivity, publishActivity, submitActivityReview, reDraftActivity, getRegistrationRoster } from '@/api/activity'
  266. import { saveDimensionWeights, getDimensionWeights } from '@/api/dimension-weight.js'
  267. import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
  268. import '@wangeditor/editor/dist/css/style.css'
  269. import AssetPicker from '@/components/AssetPicker.vue'
  270. import { buildEditorAssetMenuConf, insertAssetIntoEditor, getEditorCustomAlert, registerAssetLibraryMenu, setAssetMenuHandler, buildAssetToolbarConfig } from '@/utils/editorAssetUpload'
  271. export default {
  272. name: 'ActivityEdit',
  273. components: { DimensionWeightPicker, ContentDimensionThresholdEditor, Editor, Toolbar, AssetPicker },
  274. data() {
  275. return {
  276. isEdit: false,
  277. loading: false,
  278. saving: false,
  279. publishing: false,
  280. readonly: false,
  281. activityStatus: '',
  282. auditReason: '',
  283. reviewLoading: false,
  284. reDraftLoading: false,
  285. successDialogVisible: false,
  286. createdActivityId: null,
  287. form: {
  288. title: '',
  289. intro: '',
  290. coverImage: '',
  291. activityType: '',
  292. description: '',
  293. dimensionCode: '',
  294. dimensionWeights: [],
  295. tags: '',
  296. location: '',
  297. maxParticipants: null,
  298. priceYuan: null,
  299. memberPriceYuan: null,
  300. // A3:适用人群(字段名与取值对齐 A2 的 ActivityDTO)
  301. audienceScope: 'all',
  302. audienceTypeList: ['adult'],
  303. childFeeYuan: null,
  304. childMemberFeeYuan: null,
  305. startTime: null,
  306. endTime: null,
  307. visibility: 'public',
  308. visibleScope: '',
  309. visibleTo: '',
  310. checkinPoints: 0
  311. },
  312. formRules: {
  313. title: [
  314. { required: true, message: '请填写活动标题', trigger: 'blur' }
  315. ],
  316. activityType: [
  317. { required: true, message: '请选择活动类型', trigger: 'change' }
  318. ],
  319. description: [
  320. { required: true, message: '请填写活动描述', trigger: 'blur' }
  321. ],
  322. startTime: [
  323. { required: true, message: '请选择开始时间', trigger: 'change' }
  324. ],
  325. endTime: [
  326. { required: true, message: '请选择结束时间', trigger: 'change' }
  327. ]
  328. },
  329. editorConfig: null,
  330. toolbarConfig: buildAssetToolbarConfig(),
  331. editorInstance: null,
  332. assetPickerVisible: false,
  333. assetPickerType: 'image',
  334. assetPickerTarget: 'content',
  335. // T03 报名名册
  336. roster: { approvedCount: 0, pendingCount: 0, remaining: null },
  337. rosterRegistrants: [],
  338. rosterLoading: false
  339. }
  340. },
  341. computed: {
  342. showRosterCard() {
  343. // 仅需报名的活动,在详情页(readonly)或编辑已发布活动页显示报名名册
  344. return this.readonly && this.form.requireRegistration === 1
  345. },
  346. statusLabel() {
  347. const map = { draft: '当前状态:草稿箱', pending: '当前状态:待审核(等待管理员审核)', rejected: '当前状态:已驳回', published: '当前状态:发布中', withdrawn: '当前状态:已撤回' }
  348. return map[this.activityStatus] || ''
  349. },
  350. statusType() {
  351. const map = { draft: 'info', pending: 'warning', rejected: 'error', published: 'success', withdrawn: 'info' }
  352. return map[this.activityStatus] || 'info'
  353. },
  354. statusDescription() {
  355. if (this.activityStatus === 'rejected' && this.auditReason) return '原因:' + this.auditReason
  356. return ''
  357. },
  358. uploadActionUrl() {
  359. const baseURL = process.env.VUE_APP_BASE_API || ''
  360. return baseURL + '/api/admin/file-record/upload'
  361. },
  362. uploadHeaders() {
  363. const token = localStorage.getItem('token')
  364. return token ? { Authorization: 'Bearer ' + token } : {}
  365. }
  366. },
  367. created() {
  368. registerAssetLibraryMenu()
  369. setAssetMenuHandler(() => {
  370. this.assetPickerTarget = 'content'
  371. this.assetPickerType = 'image'
  372. this.assetPickerVisible = true
  373. })
  374. this.initEditorConfig()
  375. const id = this.$route.query.id
  376. this.readonly = this.$route.query.readonly === '1'
  377. if (id) {
  378. this.isEdit = true
  379. this.loadDetail(id)
  380. }
  381. },
  382. methods: {
  383. initEditorConfig() {
  384. // 上传统一写入素材库(file_record),并修复旧 customInsert 的 baseURL 双前缀问题
  385. this.editorConfig = {
  386. // wangEditor 从编辑器顶层 config.customAlert 读取(不是 MENU_CONF.uploadImage.customAlert)
  387. customAlert: getEditorCustomAlert(),
  388. MENU_CONF: buildEditorAssetMenuConf({ category: 'activities' })
  389. }
  390. },
  391. handleEditorCreated(editor) {
  392. // Vue 2 必须 seal,否则会把 editor 做成响应式,内部 WeakMap 取不到实例
  393. this.editorInstance = Object.seal(editor)
  394. },
  395. // ===== 素材库 =====
  396. openAssetPicker(type) {
  397. this.assetPickerTarget = 'content'
  398. this.assetPickerType = type || 'image'
  399. this.assetPickerVisible = true
  400. },
  401. openCoverAssetPicker() {
  402. this.assetPickerTarget = 'cover'
  403. this.assetPickerType = 'image'
  404. this.assetPickerVisible = true
  405. },
  406. onAssetPicked(records) {
  407. const record = records && records[0]
  408. if (!record) return
  409. if (this.assetPickerTarget === 'cover') {
  410. this.form.coverImage = record.url
  411. this.$message.success('已选择封面')
  412. return
  413. }
  414. if (!this.editorInstance) {
  415. this.$message.warning('编辑器尚未初始化完成')
  416. return
  417. }
  418. insertAssetIntoEditor(this.editorInstance, record, this.assetPickerType)
  419. },
  420. // 活动时间收敛到 5 分钟粒度:分钟向下取整到 5 的倍数、秒清零(14:07 → 14:05)。
  421. // Date 入参返回 Date(与 v-model 类型保持一致,提交时仍由 axios 序列化为带秒的 ISO 串);
  422. // 字符串入参(详情回填)返回 ISO 串,均不改变后端既有解析契约。
  423. floorTo5Minutes(value) {
  424. if (!value) return value
  425. const isDateObj = value instanceof Date
  426. const d = isDateObj ? new Date(value.getTime()) : new Date(value)
  427. if (isNaN(d.getTime())) return value
  428. d.setMinutes(Math.floor(d.getMinutes() / 5) * 5, 0, 0)
  429. return isDateObj ? d : d.toISOString()
  430. },
  431. // 选择后兜底:输入框可手动输入,非 5 倍数分钟在此收敛
  432. onStartTimeChange(val) {
  433. this.form.startTime = this.floorTo5Minutes(val)
  434. },
  435. onEndTimeChange(val) {
  436. this.form.endTime = this.floorTo5Minutes(val)
  437. },
  438. // A3:audienceType(单值编码)→ 后台多选勾选数组(成人恒选)
  439. buildAudienceTypeList(type) {
  440. const t = type || 'adult'
  441. const list = ['adult']
  442. if (t === 'include_child' || t === 'include_child_elder') list.push('child')
  443. if (t === 'include_elder' || t === 'include_child_elder') list.push('elder')
  444. return list
  445. },
  446. // A3:后台多选勾选数组 → audienceType(单值编码,字段名对齐 A2 的 ActivityDTO)
  447. encodeAudienceType() {
  448. const list = this.form.audienceTypeList || ['adult']
  449. const hasChild = list.indexOf('child') >= 0
  450. const hasElder = list.indexOf('elder') >= 0
  451. if (hasChild && hasElder) return 'include_child_elder'
  452. if (hasChild) return 'include_child'
  453. if (hasElder) return 'include_elder'
  454. return 'adult'
  455. },
  456. // A3:是否勾选儿童人群(决定儿童两档费用是否显示 / 是否提交)
  457. includeChildAudience() {
  458. const list = this.form.audienceTypeList || []
  459. return list.indexOf('child') >= 0
  460. },
  461. async loadDetail(id) {
  462. this.loading = true
  463. try {
  464. const res = await getActivityDetail({ id })
  465. if (res.data) {
  466. const d = res.data
  467. this.activityStatus = d.status || ''
  468. this.auditReason = d.auditReason || ''
  469. // Set readonly based on workflow status
  470. if (d.status === 'pending' || d.status === 'rejected' || d.status === 'withdrawn') {
  471. this.readonly = true
  472. } else if (this.$route.query.readonly === '1') {
  473. this.readonly = true
  474. } else {
  475. this.readonly = false
  476. }
  477. this.form = {
  478. title: d.title || '',
  479. intro: d.intro || '',
  480. coverImage: d.coverImage || '',
  481. activityType: d.activityType || '',
  482. description: d.description || '',
  483. dimensionCode: d.dimensionCode || '',
  484. dimensionWeights: [],
  485. tags: d.tags || '',
  486. location: d.location || '',
  487. maxParticipants: d.maxParticipants || null,
  488. priceYuan: d.price ? d.price / 100 : null,
  489. memberPriceYuan: d.memberPrice && d.memberPrice > 0 ? d.memberPrice / 100 : null,
  490. // A3:适用人群回显(A2 未合入前 d.audienceScope/d.audienceType 可能缺失,取默认值)
  491. audienceScope: d.audienceScope || 'all',
  492. audienceTypeList: this.buildAudienceTypeList(d.audienceType),
  493. childFeeYuan: d.childFee ? d.childFee / 100 : null,
  494. childMemberFeeYuan: d.childMemberFee && d.childMemberFee > 0 ? d.childMemberFee / 100 : null,
  495. startTime: this.floorTo5Minutes(d.startTime),
  496. endTime: this.floorTo5Minutes(d.endTime),
  497. visibility: d.visibility || 'public',
  498. visibleScope: d.visibleScope || '',
  499. visibleTo: d.visibleTo || '',
  500. checkinPoints: d.checkinPoints || 0,
  501. requireRegistration: d.requireRegistration != null ? d.requireRegistration : 0
  502. }
  503. try {
  504. const dwRes = await getDimensionWeights('activity', d.id)
  505. if (dwRes.data) {
  506. this.form.dimensionWeights = dwRes.data
  507. }
  508. } catch (e) {
  509. }
  510. // T03:需报名的活动自动拉取名册(详情页/编辑页都展示)
  511. if (this.form.requireRegistration === 1) {
  512. this.loadRoster()
  513. }
  514. }
  515. } catch (e) {
  516. this.$message.error('加载活动详情失败')
  517. } finally {
  518. this.loading = false
  519. }
  520. },
  521. // ===== T03 报名名册 =====
  522. // 后端把 java.util.Date 序列化为 UTC 偏移串(如 2026-10-25T01:00:00.000+00:00),
  523. // 统一转 Asia/Shanghai 本地墙钟时间展示,避免比实际时间少 8 小时
  524. formatTime(t) {
  525. if (!t) return '-'
  526. const d = new Date(t)
  527. if (isNaN(d.getTime())) return String(t)
  528. const bj = new Date(d.getTime() + d.getTimezoneOffset() * 60000 + 8 * 3600000)
  529. const pad = n => (n < 10 ? '0' + n : '' + n)
  530. return bj.getFullYear() + '-' + pad(bj.getMonth() + 1) + '-' + pad(bj.getDate()) + ' ' +
  531. pad(bj.getHours()) + ':' + pad(bj.getMinutes()) + ':' + pad(bj.getSeconds())
  532. },
  533. async loadRoster() {
  534. if (!this.$route.query.id) return
  535. this.rosterLoading = true
  536. try {
  537. const res = await getRegistrationRoster(this.$route.query.id)
  538. if (res && res.data) {
  539. this.roster = res.data
  540. this.rosterRegistrants = res.data.registrants || []
  541. }
  542. } catch (e) {
  543. this.$message.error('加载报名名册失败')
  544. } finally {
  545. this.rosterLoading = false
  546. }
  547. },
  548. exportRosterCsv() {
  549. if (!this.rosterRegistrants.length) return
  550. var rows = ['姓名,报名时间']
  551. this.rosterRegistrants.forEach(function(r) {
  552. var name = String(r.name || '').replace(/,/g, ',')
  553. var time = r.registeredAt ? String(r.registeredAt).replace('T', ' ').substring(0, 19) : ''
  554. rows.push(name + ',' + time)
  555. })
  556. // 汇总行(Excel 友好:UTF-8 BOM)
  557. var csv = '\uFEFF' + rows.join('\r\n') + '\r\n'
  558. var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
  559. var link = document.createElement('a')
  560. link.href = URL.createObjectURL(blob)
  561. link.download = '报名名册-' + (this.form.title || '活动') + '.csv'
  562. link.click()
  563. URL.revokeObjectURL(link.href)
  564. this.$message.success('已导出 ' + this.rosterRegistrants.length + ' 条报名记录')
  565. },
  566. beforeUpload(file) {
  567. const isImage = file.type === 'image/jpeg' || file.type === 'image/png' ||
  568. file.type === 'image/gif' || file.type === 'image/webp'
  569. if (!isImage) {
  570. this.$message.error('只能上传 JPG/PNG/GIF/WebP 格式图片')
  571. return false
  572. }
  573. const isLt5M = file.size / 1024 / 1024 < 5
  574. if (!isLt5M) {
  575. this.$message.error('图片大小不能超过 5MB')
  576. return false
  577. }
  578. return true
  579. },
  580. handleUploadSuccess(resp) {
  581. if (resp.code === 0 || resp.code === 200) {
  582. // 存库使用后端返回的原始 URL,避免把代理前缀写入数据库
  583. const url = resp.data && resp.data.url ? resp.data.url : (typeof resp.data === 'string' ? resp.data : '')
  584. this.form.coverImage = url
  585. this.$message.success('封面上传成功')
  586. } else {
  587. this.$message.error((resp && resp.message) || '封面上传失败')
  588. }
  589. },
  590. handleUploadError() {
  591. this.$message.error('封面上传失败,请重试')
  592. },
  593. async saveActivity(publishNow) {
  594. // 表单验证
  595. try {
  596. await this.$refs.form.validate()
  597. } catch (e) {
  598. return
  599. }
  600. if (publishNow) {
  601. this.publishing = true
  602. } else {
  603. this.saving = true
  604. }
  605. try {
  606. const payload = {
  607. title: this.form.title,
  608. intro: this.form.intro,
  609. coverImage: this.form.coverImage,
  610. activityType: this.form.activityType,
  611. description: this.form.description,
  612. dimensionCode: this.form.dimensionCode,
  613. location: this.form.location,
  614. maxParticipants: this.form.maxParticipants,
  615. price: this.form.priceYuan != null ? Math.round(this.form.priceYuan * 100) : 0,
  616. memberPrice: this.form.memberPriceYuan != null && this.form.memberPriceYuan > 0 ? Math.round(this.form.memberPriceYuan * 100) : 0,
  617. // A3:适用人群 + 儿童费用档(字段名对齐 A2 的 ActivityDTO;未勾选儿童时写 0)
  618. audienceScope: this.form.audienceScope || 'all',
  619. audienceType: this.encodeAudienceType(),
  620. childFee: this.includeChildAudience() && this.form.childFeeYuan != null ? Math.round(this.form.childFeeYuan * 100) : 0,
  621. childMemberFee: this.includeChildAudience() && this.form.childMemberFeeYuan != null && this.form.childMemberFeeYuan > 0 ? Math.round(this.form.childMemberFeeYuan * 100) : 0,
  622. startTime: this.form.startTime,
  623. endTime: this.form.endTime,
  624. visibility: this.form.visibility,
  625. visibleScope: this.form.visibleScope,
  626. visibleTo: this.form.visibleTo,
  627. checkinPoints: this.form.checkinPoints || 0,
  628. tags: this.form.tags || ''
  629. }
  630. if (this.isEdit) {
  631. // 编辑模式:保存后直接返回列表
  632. payload.id = this.form._activityId || this.$route.query.id
  633. await updateActivity(payload)
  634. if (this.form.dimensionWeights && this.form.dimensionWeights.length) {
  635. try {
  636. await saveDimensionWeights('activity', payload.id, this.form.dimensionWeights)
  637. } catch (e) {
  638. console.error('保存维度权重失败', e)
  639. }
  640. }
  641. this.$message.success('更新成功')
  642. this.$router.push('/activities')
  643. } else {
  644. // 创建模式:保存后弹窗
  645. const res = await createActivity(payload)
  646. if (res.data && res.data.id) {
  647. this.createdActivityId = res.data.id
  648. }
  649. this.isEdit = true
  650. this.saving = false
  651. this.successDialogVisible = true
  652. }
  653. } catch (e) {
  654. this.$message.error('保存失败')
  655. } finally {
  656. this.saving = false
  657. this.publishing = false
  658. }
  659. },
  660. handleContinueAdd() {
  661. this.successDialogVisible = false
  662. this.form = {
  663. title: '',
  664. intro: '',
  665. coverImage: '',
  666. activityType: '',
  667. description: '',
  668. dimensionCode: '',
  669. dimensionWeights: [],
  670. tags: '',
  671. location: '',
  672. maxParticipants: null,
  673. priceYuan: null,
  674. memberPriceYuan: null,
  675. audienceScope: 'all',
  676. audienceTypeList: ['adult'],
  677. childFeeYuan: null,
  678. childMemberFeeYuan: null,
  679. startTime: null,
  680. endTime: null,
  681. visibility: 'public',
  682. visibleScope: '',
  683. visibleTo: '',
  684. checkinPoints: 0
  685. }
  686. this.isEdit = false
  687. this.createdActivityId = null
  688. this.$refs.form && this.$refs.form.clearValidate()
  689. },
  690. async handlePublishAndBack() {
  691. this.successDialogVisible = false
  692. const activityId = this.createdActivityId
  693. if (!activityId) {
  694. this.$router.push('/activities')
  695. return
  696. }
  697. // 先保存维度权重
  698. if (this.form.dimensionWeights && this.form.dimensionWeights.length) {
  699. try {
  700. await saveDimensionWeights('activity', activityId, this.form.dimensionWeights)
  701. } catch (e) {
  702. console.error('保存维度权重失败', e)
  703. }
  704. }
  705. // 发布
  706. try {
  707. this.publishing = true
  708. await publishActivity(activityId)
  709. this.$message.success('发布成功')
  710. } catch (e) {
  711. this.$message.error('发布失败')
  712. } finally {
  713. this.publishing = false
  714. }
  715. this.$router.push('/activities')
  716. },
  717. editFromReadonly() {
  718. this.readonly = false
  719. },
  720. async handleSubmitReview() {
  721. this.reviewLoading = true
  722. try {
  723. // Save activity first
  724. const payload = {
  725. title: this.form.title,
  726. intro: this.form.intro,
  727. coverImage: this.form.coverImage,
  728. activityType: this.form.activityType,
  729. description: this.form.description,
  730. dimensionCode: this.form.dimensionCode,
  731. location: this.form.location,
  732. maxParticipants: this.form.maxParticipants,
  733. price: this.form.priceYuan != null ? Math.round(this.form.priceYuan * 100) : 0,
  734. memberPrice: this.form.memberPriceYuan != null && this.form.memberPriceYuan > 0 ? Math.round(this.form.memberPriceYuan * 100) : 0,
  735. // A3:适用人群 + 儿童费用档(字段名对齐 A2 的 ActivityDTO;未勾选儿童时写 0)
  736. audienceScope: this.form.audienceScope || 'all',
  737. audienceType: this.encodeAudienceType(),
  738. childFee: this.includeChildAudience() && this.form.childFeeYuan != null ? Math.round(this.form.childFeeYuan * 100) : 0,
  739. childMemberFee: this.includeChildAudience() && this.form.childMemberFeeYuan != null && this.form.childMemberFeeYuan > 0 ? Math.round(this.form.childMemberFeeYuan * 100) : 0,
  740. startTime: this.form.startTime,
  741. endTime: this.form.endTime,
  742. visibility: this.form.visibility,
  743. visibleScope: this.form.visibleScope,
  744. visibleTo: this.form.visibleTo,
  745. checkinPoints: this.form.checkinPoints || 0,
  746. tags: this.form.tags || ''
  747. }
  748. const activityId = this.form._activityId || this.$route.query.id
  749. if (
  750. activityId
  751. ) {
  752. payload.id = activityId
  753. await updateActivity(payload)
  754. } else {
  755. const res = await createActivity(payload)
  756. if (res.data && res.data.id) {
  757. payload.id = res.data.id
  758. this.form._activityId = res.data.id
  759. this.isEdit = true
  760. }
  761. }
  762. if (payload.id && this.form.dimensionWeights && this.form.dimensionWeights.length) {
  763. try { await saveDimensionWeights('activity', payload.id, this.form.dimensionWeights) } catch (e) {}
  764. }
  765. // Submit for review
  766. await submitActivityReview({ id: payload.id })
  767. this.$message.success('已提交审核')
  768. this.$router.push('/activities')
  769. } catch (e) {
  770. this.$message.error(e.message || '提交审核失败')
  771. } finally {
  772. this.reviewLoading = false
  773. }
  774. },
  775. async handleReDraft() {
  776. this.reDraftLoading = true
  777. try {
  778. await reDraftActivity({ id: this.$route.query.id })
  779. this.$message.success('已保存到草稿箱')
  780. this.activityStatus = 'draft'
  781. this.readonly = false
  782. } catch (e) {
  783. this.$message.error(e.message || '操作失败')
  784. } finally {
  785. this.reDraftLoading = false
  786. }
  787. }
  788. }
  789. }
  790. </script>
  791. <style scoped>
  792. /* == C 批内联清理工具类 == */
  793. .mb-16 { margin-bottom: 16px; }
  794. .full-width { width: 100%; }
  795. .w-200 { width: 200px; }
  796. .ml-10 { margin-left: 10px; }
  797. .text-muted { color: var(--adm-text-45); }
  798. .editor-body { min-height: 300px; }
  799. .form-hint { margin-left: 8px; color: var(--adm-text-45); font-size: 12px; }
  800. .audience-hint { margin: -4px 0 16px 2px; color: var(--adm-text-45); font-size: 12px; }
  801. .success-body { text-align: center; padding: 10px 0; }
  802. .success-icon { font-size: 48px; color: var(--adm-success); }
  803. .success-text { font-size: 16px; margin-top: 12px; }
  804. .success-footer { text-align: center; }
  805. .activity-edit {
  806. padding: 24px;
  807. flex: 1;
  808. display: flex;
  809. flex-direction: column;
  810. min-height: 0;
  811. }
  812. .activity-edit > .el-card {
  813. flex: 1;
  814. display: flex;
  815. flex-direction: column;
  816. min-height: 0;
  817. width: 100%;
  818. }
  819. .activity-edit > .el-card /deep/ .el-card__body {
  820. flex: 1;
  821. display: flex;
  822. flex-direction: column;
  823. min-height: 0;
  824. overflow: hidden;
  825. padding: 24px;
  826. width: 100%;
  827. box-sizing: border-box;
  828. }
  829. .activity-edit /deep/ .el-form {
  830. width: 100%;
  831. }
  832. .activity-edit /deep/ .admin-page-actions {
  833. display: flex;
  834. align-items: center;
  835. justify-content: flex-end;
  836. gap: 8px;
  837. flex-wrap: wrap;
  838. margin-left: auto;
  839. }
  840. .cover-preview {
  841. width: 200px;
  842. height: 120px;
  843. object-fit: cover;
  844. border-radius: 4px;
  845. border: 1px solid var(--adm-border-base);
  846. }
  847. .rich-editor {
  848. border: 1px solid var(--adm-border-base);
  849. border-radius: 4px;
  850. }
  851. .editor-extra-row {
  852. display: flex;
  853. gap: 8px;
  854. padding: 6px 8px;
  855. border-bottom: 1px solid var(--adm-border-base);
  856. }
  857. .rich-editor /deep/ .w-e-toolbar {
  858. flex-wrap: wrap;
  859. }
  860. .rich-editor /deep/ .w-e-text-container {
  861. min-height: 300px;
  862. max-height: 500px;
  863. overflow-y: auto;
  864. }
  865. /* 内滚动容器:利用 el-card__body flex column 让表单区域独立滚动 */
  866. .activity-edit-form-wrap {
  867. flex: 1;
  868. min-height: 0;
  869. overflow-y: auto;
  870. overflow-x: hidden;
  871. padding-right: 8px;
  872. margin-right: -8px;
  873. }
  874. /* ===== T03 报名名册 ===== */
  875. .roster-card {
  876. margin-bottom: 16px;
  877. flex-shrink: 0;
  878. }
  879. .roster-card /deep/ .el-card__header {
  880. padding: 10px 24px;
  881. }
  882. .roster-card-header {
  883. display: flex;
  884. align-items: center;
  885. justify-content: space-between;
  886. font-size: 15px;
  887. font-weight: 600;
  888. color: var(--adm-text-88);
  889. }
  890. .roster-card-actions {
  891. display: flex;
  892. gap: 8px;
  893. }
  894. .roster-stats {
  895. margin-bottom: 12px;
  896. }
  897. .stat-box {
  898. padding: 8px 12px;
  899. background: var(--adm-bg-header);
  900. border-radius: 4px;
  901. text-align: center;
  902. }
  903. .stat-num {
  904. font-size: 20px;
  905. font-weight: 700;
  906. color: var(--adm-text-88);
  907. }
  908. .stat-danger {
  909. color: #f56c6c;
  910. }
  911. .stat-label {
  912. font-size: 12px;
  913. color: var(--adm-text-45);
  914. margin-top: 4px;
  915. }
  916. .roster-list {
  917. border-top: 1px solid var(--adm-border-split);
  918. padding-top: 12px;
  919. }
  920. .roster-list-title {
  921. font-size: 14px;
  922. font-weight: 600;
  923. color: var(--adm-text-88);
  924. margin-bottom: 8px;
  925. }
  926. .roster-list-body {
  927. max-height: 200px;
  928. overflow-y: auto;
  929. }
  930. .roster-item {
  931. display: flex;
  932. justify-content: space-between;
  933. padding: 6px 0;
  934. border-bottom: 1px solid var(--adm-border-split);
  935. }
  936. .roster-item:last-child {
  937. border-bottom: none;
  938. }
  939. .roster-name {
  940. font-size: 14px;
  941. color: var(--adm-text-strong);
  942. }
  943. .roster-time {
  944. font-size: 12px;
  945. color: var(--adm-text-45);
  946. }
  947. .roster-empty {
  948. font-size: 12px;
  949. color: var(--adm-text-45);
  950. text-align: center;
  951. padding: 24px 0;
  952. }
  953. </style>