create.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="form-card">
  4. <!-- 活动标题 -->
  5. <view class="form-item">
  6. <text class="form-label">活动标题 *</text>
  7. <input class="form-input" v-model="form.title" placeholder="请输入活动标题" maxlength="50" />
  8. </view>
  9. <!-- 活动类型 -->
  10. <view class="form-item">
  11. <text class="form-label">活动类型 *</text>
  12. <picker class="form-picker" :value="typeIdx" :range="typeOptions" range-key="label" @change="onTypeChange">
  13. <text class="picker-text">{{ form.activityType ? typeLabel(form.activityType) : '请选择类型' }}</text>
  14. </picker>
  15. </view>
  16. <!-- 开始时间 -->
  17. <view class="form-item">
  18. <text class="form-label">开始时间 *</text>
  19. <picker class="form-picker" mode="date" :value="datePart" @change="onStartDateChange">
  20. <text class="picker-text">{{ datePart || '选择日期' }}</text>
  21. </picker>
  22. <picker class="form-picker" mode="time" :value="timePart" @change="onStartTimeChange" style="margin-top: 16rpx;">
  23. <text class="picker-text">{{ timePart || '选择时间' }}</text>
  24. </picker>
  25. <text class="picker-hint">以 5 分钟为一个单元(如 14:00、14:05)</text>
  26. </view>
  27. <!-- 结束时间 -->
  28. <view class="form-item">
  29. <text class="form-label">结束时间</text>
  30. <picker class="form-picker" mode="date" :value="endDatePart" @change="onEndDateChange">
  31. <text class="picker-text">{{ endDatePart || '选择日期(可选)' }}</text>
  32. </picker>
  33. <picker class="form-picker" mode="time" :value="endTimePart" @change="onEndTimeChange" style="margin-top: 16rpx;">
  34. <text class="picker-text">{{ endTimePart || '选择时间(可选)' }}</text>
  35. </picker>
  36. <text class="picker-hint">以 5 分钟为一个单元(如 14:00、14:05)</text>
  37. </view>
  38. <!-- 报名截止时间 -->
  39. <view class="form-item">
  40. <text class="form-label">报名截止时间</text>
  41. <picker class="form-picker" mode="date" :value="regDatePart" @change="onRegDateChange">
  42. <text class="picker-text">{{ regDatePart || '选择日期(不填=活动开始前)' }}</text>
  43. </picker>
  44. <picker class="form-picker" mode="time" :value="regTimePart" @change="onRegTimeChange" style="margin-top: 16rpx;">
  45. <text class="picker-text">{{ regTimePart || '选择时间' }}</text>
  46. </picker>
  47. <text class="picker-hint">以 5 分钟为一个单元(如 14:00、14:05)</text>
  48. </view>
  49. <!-- 活动地点 -->
  50. <view class="form-item">
  51. <text class="form-label">活动地点</text>
  52. <input class="form-input" v-model="form.location" placeholder="请输入活动地点" maxlength="100" />
  53. </view>
  54. <!-- 人数 + 价格 -->
  55. <view class="form-item-row">
  56. <view class="form-item half">
  57. <text class="form-label">最大人数</text>
  58. <input class="form-input" type="number" v-model="maxParticipantsStr" placeholder="0=不限" />
  59. </view>
  60. <view class="form-item half">
  61. <text class="form-label">孩子费用(元)</text>
  62. <input class="form-input" type="digit" v-model="childFeeYuan" placeholder="0=免费" />
  63. </view>
  64. </view>
  65. <view class="form-item-row">
  66. <view class="form-item half">
  67. <text class="form-label">孩子会员费(元)</text>
  68. <input class="form-input" type="digit" v-model="childMemberFeeYuan" placeholder="0=免费" />
  69. </view>
  70. <view class="form-item half">
  71. <text class="form-label">家长费用(元)</text>
  72. <input class="form-input" type="digit" v-model="parentFeeYuan" placeholder="0=免费" />
  73. </view>
  74. </view>
  75. <view class="form-item">
  76. <text class="form-label">家长会员费(元)</text>
  77. <input class="form-input" type="digit" v-model="parentMemberFeeYuan" placeholder="0=免费" />
  78. </view>
  79. <!-- 主办方 -->
  80. <view class="form-item">
  81. <text class="form-label">主办方</text>
  82. <input class="form-input" v-model="form.vendorName" placeholder="请输入主办方名称(可选)" maxlength="50" />
  83. </view>
  84. <!-- 封面图片 -->
  85. <view class="form-item">
  86. <text class="form-label">封面图片</text>
  87. <view class="cover-upload" @click="chooseImage">
  88. <image v-if="form.coverImage" class="preview-img" :src="getCoverUrl(form.coverImage)" mode="aspectFill" @click.stop lazy-load />
  89. <view v-else class="upload-placeholder">
  90. <text class="upload-icon">📷</text>
  91. <text class="upload-text">点击上传封面图</text>
  92. </view>
  93. </view>
  94. <view class="cover-actions" v-if="form.coverImage">
  95. <text class="cover-action" @click="chooseImage">重新选择</text>
  96. <text class="cover-action-danger" @click="removeCover">移除</text>
  97. </view>
  98. </view>
  99. <!-- 活动简介(列表卡片与分享海报优先展示,一句到两句为宜) -->
  100. <view class="form-item">
  101. <text class="form-label">活动简介</text>
  102. <textarea class="form-textarea" v-model="form.intro" placeholder="一句话说明这个活动是什么(可选,建议不超过 60 字)" maxlength="100"
  103. auto-height />
  104. </view>
  105. <!-- 活动描述 -->
  106. <view class="form-item">
  107. <text class="form-label">活动描述</text>
  108. <textarea class="form-textarea" v-model="form.description" placeholder="请输入活动详细介绍" maxlength="500"
  109. auto-height />
  110. </view>
  111. <!-- 操作按钮 -->
  112. <view class="form-actions">
  113. <view class="btn-save" @click="handleSave">
  114. <text>保存为草稿</text>
  115. </view>
  116. <view class="btn-publish" @click="handlePublish">
  117. <text>{{ isAdmin ? '保存并发布' : '保存并提交审核' }}</text>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- 海报模板选择 + 预览 -->
  122. <view class="form-card" v-if="posterTemplates.length > 0">
  123. <view class="form-title">活动海报模板(可选)</view>
  124. <view class="poster-tpl-list">
  125. <view
  126. v-for="tpl in posterTemplates"
  127. :key="tpl.id"
  128. class="poster-tpl-card"
  129. :class="{ 'poster-tpl-active': form.posterTemplateId === tpl.id }"
  130. @click="selectPosterTemplate(tpl)"
  131. >
  132. <view class="tpl-colors">
  133. <view class="tpl-dot tpl-main" :style="{ background: tpl.mainColor || BrandColors.primary }"></view>
  134. <view class="tpl-dot tpl-dark" :style="{ background: tpl.darkColor || BrandColors.orangeDeep }"></view>
  135. <view class="tpl-dot tpl-light" :style="{ background: tpl.lightColor || paleColor }"></view>
  136. </view>
  137. <text class="tpl-name">{{ tpl.name }}</text>
  138. </view>
  139. </view>
  140. <view class="poster-preview-row" v-if="form.posterTemplateId">
  141. <text class="poster-preview-hint">已选择海报模板,点击「预览」查看效果</text>
  142. <view class="btn-preview" @click="openPosterPreview">预览</view>
  143. </view>
  144. </view>
  145. <!-- 海报预览弹层 -->
  146. <content-share-poster
  147. v-if="showPosterPreview"
  148. :show="showPosterPreview"
  149. :title="form.title || '活动海报'"
  150. :cover-image="form.coverImage"
  151. :dimension-code="form.dimensionCode"
  152. :template="previewTemplateKey"
  153. :templates="posterTemplates"
  154. :poster-qr-code="''"
  155. @close="showPosterPreview = false"
  156. @update:template="previewTemplateKey = $event"
  157. @update:bgColor="previewBgColor = $event"
  158. ></content-share-poster>
  159. <view class="loading" v-if="loading">
  160. <view class="loading-spinner"></view>
  161. <text>加载中...</text>
  162. </view>
  163. </view>
  164. </template>
  165. <script>
  166. import { BrandColors } from '../../utils/brand-colors.js'
  167. import { adminCreateActivity, adminUpdateActivity, adminPublishActivity, submitActivityForReview, getActivityDetail, getPosterTemplates } from '../../utils/api.js'
  168. import config from '../../config.js'
  169. import { parseDate } from '../../utils/format.js'
  170. import { hasActivityManageRole } from '../../utils/activity-role.js'
  171. import { pickImage } from '../../utils/image-picker.js'
  172. import ContentSharePoster from '../../components/ContentSharePoster.vue'
  173. var BASE_URL = config.api('')
  174. import fontScaleMixin from '@/mixins/font-scale.js'
  175. export default {
  176. mixins: [fontScaleMixin],
  177. components: { ContentSharePoster },
  178. computed: {
  179. // 后台活动管理员可直接发布;服务商账号只能保存后提交审核
  180. isAdmin: function() {
  181. return hasActivityManageRole()
  182. }
  183. },
  184. data() {
  185. return {
  186. paleColor: BrandColors.primaryPale,
  187. isNew: true,
  188. activityId: null,
  189. loading: false,
  190. memberId: '',
  191. form: {
  192. title: '',
  193. intro: '',
  194. description: '',
  195. intro: '',
  196. coverImage: '',
  197. dimensionCode: '',
  198. activityType: '',
  199. status: 'draft',
  200. startTime: null,
  201. endTime: null,
  202. registrationDeadline: null,
  203. location: '',
  204. maxParticipants: 0,
  205. childFee: 0,
  206. childMemberFee: 0,
  207. parentFee: 0,
  208. parentMemberFee: 0,
  209. visibility: 'public',
  210. requireRegistration: 1,
  211. requireCheckinReview: 0,
  212. checkinPoints: 0
  213. },
  214. childFeeYuan: '0',
  215. childMemberFeeYuan: '0',
  216. parentFeeYuan: '0',
  217. parentMemberFeeYuan: '0',
  218. maxParticipantsStr: '0',
  219. datePart: '',
  220. timePart: '',
  221. endDatePart: '',
  222. endTimePart: '',
  223. regDatePart: '',
  224. regTimePart: '',
  225. typeIdx: 0,
  226. typeOptions: [
  227. { key: 'offline', label: '线下活动' },
  228. { key: 'online', label: '线上活动' },
  229. { key: 'campaign', label: '营销活动' }
  230. ],
  231. // 海报模板
  232. posterTemplates: [],
  233. selectedPosterTemplate: null,
  234. showPosterPreview: false,
  235. previewTemplateKey: 'gradient',
  236. previewBgColor: ''
  237. }
  238. },
  239. onLoad(options) {
  240. if (options.id) {
  241. this.activityId = parseInt(options.id)
  242. this.isNew = false
  243. uni.setNavigationBarTitle({ title: '编辑活动' })
  244. this.loadDetail()
  245. } else {
  246. uni.setNavigationBarTitle({ title: '创建活动' })
  247. }
  248. // 加载海报模板列表(未登录也会返回空列表,不阻塞创建)
  249. this.loadPosterTemplates()
  250. },
  251. methods: {
  252. loadDetail() {
  253. var self = this
  254. self.loading = true
  255. getActivityDetail(self.activityId).then(function(res) {
  256. self.loading = false
  257. if (res && res.code === 200 && res.data) {
  258. var d = res.data
  259. self.form.title = d.title || ''
  260. self.form.intro = d.intro || ''
  261. self.form.description = d.description || ''
  262. self.form.intro = d.intro || ''
  263. self.form.coverImage = d.coverImage || ''
  264. self.form.vendorName = d.vendorName || ''
  265. self.form.posterTemplateId = d.posterTemplateId || null
  266. self.form.dimensionCode = d.dimensionCode || ''
  267. self.form.activityType = d.activityType || ''
  268. self.form.location = d.location || ''
  269. self.form.maxParticipants = d.maxParticipants || 0
  270. self.form.childFee = d.childFee || 0
  271. self.form.childMemberFee = d.childMemberFee || 0
  272. self.form.parentFee = d.parentFee || 0
  273. self.form.parentMemberFee = d.parentMemberFee || 0
  274. self.form.status = d.status || 'draft'
  275. self.form.visibility = d.visibility || 'public'
  276. self.maxParticipantsStr = String(self.form.maxParticipants)
  277. self.childFeeYuan = self.form.childFee ? (self.form.childFee / 100).toString() : '0'
  278. self.childMemberFeeYuan = self.form.childMemberFee ? (self.form.childMemberFee / 100).toString() : '0'
  279. self.parentFeeYuan = self.form.parentFee ? (self.form.parentFee / 100).toString() : '0'
  280. self.parentMemberFeeYuan = self.form.parentMemberFee ? (self.form.parentMemberFee / 100).toString() : '0'
  281. if (d.startTime) {
  282. var sd = parseDate(d.startTime)
  283. if (sd) {
  284. self.datePart = self.fmtDate(sd)
  285. self.timePart = self.fmtTime(sd)
  286. // 走 sync 统一组装:timePart 已被 fmtTime 收敛到 5 的倍数,保证"显示即提交"
  287. self.syncStartTime()
  288. }
  289. }
  290. if (d.endTime) {
  291. var ed = parseDate(d.endTime)
  292. if (ed) {
  293. self.endDatePart = self.fmtDate(ed)
  294. self.endTimePart = self.fmtTime(ed)
  295. self.syncEndTime()
  296. }
  297. }
  298. if (d.registrationDeadline) {
  299. var rd = parseDate(d.registrationDeadline)
  300. if (rd) {
  301. self.regDatePart = self.fmtDate(rd)
  302. self.regTimePart = self.fmtTime(rd)
  303. self.syncRegDeadline()
  304. }
  305. }
  306. // sync type picker
  307. for (var j = 0; j < self.typeOptions.length; j++) {
  308. if (self.typeOptions[j].key === self.form.activityType) self.typeIdx = j
  309. }
  310. }
  311. }).catch(function() { self.loading = false })
  312. },
  313. onTypeChange(e) {
  314. this.typeIdx = e.detail.value
  315. this.form.activityType = this.typeOptions[this.typeIdx].key
  316. },
  317. onStartDateChange(e) {
  318. this.datePart = e.detail.value
  319. this.syncStartTime()
  320. },
  321. onStartTimeChange(e) {
  322. // 小程序原生 time picker 不支持步长,选中后把分钟向下取整到 5 的整数倍(14:07 → 14:05、14:08 → 14:05)
  323. this.timePart = this.normalizeTimeTo5Min(e.detail.value)
  324. this.syncStartTime()
  325. },
  326. onEndDateChange(e) {
  327. this.endDatePart = e.detail.value
  328. this.syncEndTime()
  329. },
  330. onEndTimeChange(e) {
  331. // 同上:结束时间分钟同样收敛到 5 的整数倍
  332. this.endTimePart = this.normalizeTimeTo5Min(e.detail.value)
  333. this.syncEndTime()
  334. },
  335. onRegDateChange(e) {
  336. this.regDatePart = e.detail.value
  337. this.syncRegDeadline()
  338. },
  339. onRegTimeChange(e) {
  340. // 同上:报名截止时间分钟同样收敛到 5 的整数倍
  341. this.regTimePart = this.normalizeTimeTo5Min(e.detail.value)
  342. this.syncRegDeadline()
  343. },
  344. // 活动时间统一为 5 分钟粒度:分钟向下取整到 5 的倍数(14:07 → 14:05、14:59 → 14:55)
  345. normalizeTimeTo5Min: function(t) {
  346. if (!t) return t
  347. var parts = String(t).split(':')
  348. if (parts.length < 2) return t
  349. var h = parseInt(parts[0], 10)
  350. var mi = parseInt(parts[1], 10)
  351. if (isNaN(h) || isNaN(mi)) return t
  352. mi = Math.floor(mi / 5) * 5
  353. return ('0' + h).slice(-2) + ':' + ('0' + mi).slice(-2)
  354. },
  355. syncStartTime() {
  356. if (this.datePart && this.timePart) {
  357. this.form.startTime = this.datePart + 'T' + this.timePart + ':00'
  358. }
  359. },
  360. syncEndTime() {
  361. if (this.endDatePart && this.endTimePart) {
  362. this.form.endTime = this.endDatePart + 'T' + this.endTimePart + ':00'
  363. } else {
  364. this.form.endTime = null
  365. }
  366. },
  367. syncRegDeadline() {
  368. if (this.regDatePart && this.regTimePart) {
  369. this.form.registrationDeadline = this.regDatePart + 'T' + this.regTimePart + ':00'
  370. } else {
  371. this.form.registrationDeadline = null
  372. }
  373. },
  374. chooseImage() {
  375. var self = this
  376. pickImage({
  377. count: 1,
  378. sizeType: ['compressed'],
  379. success: function(res) {
  380. self.uploadCover(res.tempFilePaths[0])
  381. }
  382. })
  383. },
  384. uploadCover(filePath) {
  385. var self = this
  386. uni.uploadFile({
  387. url: BASE_URL + '/api/admin/articles/upload/image',
  388. filePath: filePath,
  389. name: 'file',
  390. header: { 'Authorization': 'Bearer ' + (uni.getStorageSync('token') || '') },
  391. success: function(res) {
  392. try {
  393. var data = JSON.parse(res.data)
  394. if (data.code === 200 && data.data) {
  395. self.form.coverImage = data.data
  396. } else {
  397. uni.showToast({ title: '上传失败', icon: 'none' })
  398. }
  399. } catch (e) {
  400. uni.showToast({ title: '上传失败', icon: 'none' })
  401. }
  402. },
  403. fail: function() {
  404. uni.showToast({ title: '上传失败', icon: 'none' })
  405. }
  406. })
  407. },
  408. onImgError() {
  409. this.form.coverImage = ''
  410. },
  411. getCoverUrl(path) {
  412. if (!path) return ''
  413. var s = String(path).trim()
  414. if (!s || s === 'null' || s === '/null') return ''
  415. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  416. return BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  417. },
  418. removeCover() {
  419. this.form.coverImage = ''
  420. },
  421. async loadPosterTemplates() {
  422. try {
  423. var res = await getPosterTemplates()
  424. if (res && res.code === 200) {
  425. this.posterTemplates = res.data || []
  426. }
  427. } catch (e) { /* 模板拉取失败不影响创建 */ }
  428. },
  429. selectPosterTemplate(tpl) {
  430. this.form.posterTemplateId = tpl.id
  431. this.selectedPosterTemplate = tpl
  432. this.previewTemplateKey = tpl.templateKey || 'gradient'
  433. // 默认背景色取模板主色
  434. this.previewBgColor = tpl.mainColor || ''
  435. uni.showToast({ title: '已选择:' + tpl.name, icon: 'none' })
  436. },
  437. openPosterPreview() {
  438. if (!this.form.posterTemplateId) {
  439. uni.showToast({ title: '请先选择海报模板', icon: 'none' })
  440. return
  441. }
  442. this.showPosterPreview = true
  443. },
  444. validate() {
  445. if (!this.form.title) {
  446. uni.showToast({ title: '请输入活动标题', icon: 'none' })
  447. return false
  448. }
  449. if (!this.form.activityType) {
  450. uni.showToast({ title: '请选择活动类型', icon: 'none' })
  451. return false
  452. }
  453. if (!this.datePart || !this.timePart) {
  454. uni.showToast({ title: '请选择开始时间', icon: 'none' })
  455. return false
  456. }
  457. return true
  458. },
  459. buildPayload() {
  460. var payload = Object.assign({}, this.form)
  461. payload.maxParticipants = parseInt(this.maxParticipantsStr) || 0
  462. payload.childFee = Math.round((parseFloat(this.childFeeYuan) || 0) * 100)
  463. payload.childMemberFee = Math.round((parseFloat(this.childMemberFeeYuan) || 0) * 100)
  464. payload.parentFee = Math.round((parseFloat(this.parentFeeYuan) || 0) * 100)
  465. payload.parentMemberFee = Math.round((parseFloat(this.parentMemberFeeYuan) || 0) * 100)
  466. if (this.activityId) payload.id = this.activityId
  467. // 维度由审核时设置,创建/编辑不提交空维度,避免误清空已有维度
  468. if (!payload.dimensionCode) delete payload.dimensionCode
  469. // 主办方和海报模板仅非空时提交
  470. if (!payload.vendorName) delete payload.vendorName
  471. if (!payload.posterTemplateId) delete payload.posterTemplateId
  472. // 简介为空时不提交,保留后端已有值
  473. if (!payload.intro) delete payload.intro
  474. return payload
  475. },
  476. handleSave() {
  477. if (!this.validate()) return
  478. this.submit(false)
  479. },
  480. handlePublish() {
  481. if (!this.validate()) return
  482. this.submit(true)
  483. },
  484. submit(publishAfter) {
  485. var self = this
  486. self.loading = true
  487. var payload = self.buildPayload()
  488. var isAdmin = self.isAdmin
  489. var doPublish = function(id) {
  490. if (isAdmin) {
  491. adminPublishActivity(id).then(function(r) {
  492. self.loading = false
  493. if (r && r.code === 200) {
  494. uni.showToast({ title: '已发布', icon: 'success' })
  495. setTimeout(function() {
  496. uni.navigateBack()
  497. }, 1200)
  498. } else {
  499. uni.showToast({ title: (r && r.message) || '发布失败', icon: 'none' })
  500. }
  501. }).catch(function() {
  502. self.loading = false
  503. uni.showToast({ title: '发布失败', icon: 'none' })
  504. })
  505. } else {
  506. submitActivityForReview(id).then(function(r) {
  507. self.loading = false
  508. if (r && r.code === 200) {
  509. uni.showToast({ title: '已提交审核', icon: 'success' })
  510. setTimeout(function() {
  511. uni.navigateBack()
  512. }, 1200)
  513. } else {
  514. uni.showToast({ title: (r && r.message) || '提交审核失败', icon: 'none' })
  515. }
  516. }).catch(function() {
  517. self.loading = false
  518. uni.showToast({ title: '提交审核失败', icon: 'none' })
  519. })
  520. }
  521. }
  522. if (self.isNew) {
  523. adminCreateActivity(payload).then(function(res) {
  524. if (res && res.code === 200) {
  525. var newId = res.data.id || res.data
  526. if (publishAfter) {
  527. doPublish(newId)
  528. } else {
  529. self.loading = false
  530. uni.showToast({ title: '已保存草稿', icon: 'success' })
  531. setTimeout(function() { uni.navigateBack() }, 1200)
  532. }
  533. } else {
  534. self.loading = false
  535. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  536. }
  537. }).catch(function() {
  538. self.loading = false
  539. uni.showToast({ title: '网络异常', icon: 'none' })
  540. })
  541. } else {
  542. adminUpdateActivity(payload).then(function(res) {
  543. if (res && res.code === 200) {
  544. if (publishAfter && (self.form.status === 'draft' || self.form.status === 'rejected')) {
  545. doPublish(self.activityId)
  546. } else {
  547. self.loading = false
  548. uni.showToast({ title: '已保存', icon: 'success' })
  549. setTimeout(function() { uni.navigateBack() }, 1200)
  550. }
  551. } else {
  552. self.loading = false
  553. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  554. }
  555. }).catch(function() {
  556. self.loading = false
  557. uni.showToast({ title: '网络异常', icon: 'none' })
  558. })
  559. }
  560. },
  561. typeLabel(key) {
  562. for (var i = 0; i < this.typeOptions.length; i++) {
  563. if (this.typeOptions[i].key === key) return this.typeOptions[i].label
  564. }
  565. return '请选择类型'
  566. },
  567. fmtDate(d) {
  568. var y = d.getFullYear()
  569. var m = ('0' + (d.getMonth() + 1)).slice(-2)
  570. var day = ('0' + d.getDate()).slice(-2)
  571. return y + '-' + m + '-' + day
  572. },
  573. fmtTime(d) {
  574. var h = ('0' + d.getHours()).slice(-2)
  575. var mi = ('0' + d.getMinutes()).slice(-2)
  576. // 回填同样收敛到 5 分钟粒度,避免历史非 5 倍数分钟再次保存前产生"选了 7 分却变 5 分"的困惑
  577. return this.normalizeTimeTo5Min(h + ':' + mi)
  578. }
  579. }
  580. }
  581. </script>
  582. <style scoped lang="scss">
  583. .container {
  584. min-height: 100vh;
  585. background: $app-bg;
  586. padding: 24rpx;
  587. }
  588. .form-card {
  589. background: $app-surface;
  590. border-radius: 20rpx;
  591. padding: 32rpx 28rpx;
  592. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  593. }
  594. .form-title {
  595. font-size: calc(36rpx * var(--font-scale, 1));
  596. font-weight: bold;
  597. color: $uni-text-color;
  598. margin-bottom: 24rpx;
  599. }
  600. .form-item {
  601. margin-bottom: 28rpx;
  602. }
  603. .form-item-row {
  604. display: flex;
  605. flex-direction: row;
  606. gap: 20rpx;
  607. margin-bottom: 28rpx;
  608. }
  609. .form-item.half {
  610. flex: 1;
  611. }
  612. .form-label {
  613. font-size: calc(26rpx * var(--font-scale, 1));
  614. color: $facade-text-slate-deep;
  615. font-weight: 600;
  616. margin-bottom: 12rpx;
  617. display: block;
  618. }
  619. .form-input {
  620. width: 100%;
  621. height: 80rpx;
  622. border: 1rpx solid $uni-border-color-light;
  623. border-radius: 12rpx;
  624. padding: 0 20rpx;
  625. font-size: calc(28rpx * var(--font-scale, 1));
  626. color: $uni-text-color;
  627. box-sizing: border-box;
  628. }
  629. .form-picker {
  630. width: 100%;
  631. height: 80rpx;
  632. border: 1rpx solid $uni-border-color-light;
  633. border-radius: 12rpx;
  634. padding: 0 20rpx;
  635. font-size: calc(28rpx * var(--font-scale, 1));
  636. color: $uni-text-color;
  637. box-sizing: border-box;
  638. display: flex;
  639. align-items: center;
  640. }
  641. .picker-text {
  642. font-size: 28rpx;
  643. color: $uni-text-color;
  644. }
  645. /* 时间选择提示:活动时间以 5 分钟为一个单元 */
  646. .picker-hint {
  647. display: block;
  648. margin-top: 4rpx;
  649. font-size: 20rpx;
  650. color: $uni-text-color-secondary;
  651. }
  652. .form-textarea {
  653. width: 100%;
  654. min-height: 160rpx;
  655. border: 1rpx solid $uni-border-color-light;
  656. border-radius: 12rpx;
  657. padding: 16rpx 20rpx;
  658. font-size: calc(28rpx * var(--font-scale, 1));
  659. color: $uni-text-color;
  660. box-sizing: border-box;
  661. }
  662. .cover-upload {
  663. width: 100%;
  664. height: 320rpx;
  665. border: 2rpx dashed $uni-border-color;
  666. border-radius: 12rpx;
  667. display: flex;
  668. align-items: center;
  669. justify-content: center;
  670. overflow: hidden;
  671. }
  672. .preview-img {
  673. width: 100%;
  674. height: 100%;
  675. }
  676. .upload-placeholder {
  677. display: flex;
  678. flex-direction: column;
  679. align-items: center;
  680. }
  681. .upload-icon {
  682. font-size: 64rpx;
  683. color: $app-text-subtle;
  684. }
  685. .upload-text {
  686. font-size: calc(24rpx * var(--font-scale, 1));
  687. color: $app-text-subtle;
  688. margin-top: 8rpx;
  689. }
  690. .cover-actions {
  691. display: flex;
  692. flex-direction: row;
  693. gap: 24rpx;
  694. margin-top: 12rpx;
  695. }
  696. .cover-action {
  697. font-size: calc(24rpx * var(--font-scale, 1));
  698. color: $facade-text-slate-deep;
  699. text-decoration: underline;
  700. }
  701. .cover-action-danger {
  702. font-size: calc(24rpx * var(--font-scale, 1));
  703. color: $status-danger;
  704. text-decoration: underline;
  705. }
  706. /* 海报模板选择 */
  707. .poster-tpl-list {
  708. display: flex;
  709. flex-direction: row;
  710. flex-wrap: wrap;
  711. gap: 16rpx;
  712. margin-top: 20rpx;
  713. }
  714. .poster-tpl-card {
  715. width: 200rpx;
  716. border: 2rpx solid $uni-border-color-light;
  717. border-radius: 12rpx;
  718. padding: 20rpx 16rpx;
  719. display: flex;
  720. flex-direction: column;
  721. align-items: center;
  722. background: $app-surface;
  723. }
  724. .poster-tpl-active {
  725. border-color: $brand-primary;
  726. background: $uni-primary-pale;
  727. }
  728. .tpl-colors {
  729. display: flex;
  730. flex-direction: row;
  731. gap: 8rpx;
  732. margin-bottom: 12rpx;
  733. }
  734. .tpl-dot {
  735. width: 32rpx;
  736. height: 32rpx;
  737. border-radius: 50%;
  738. }
  739. .tpl-name {
  740. font-size: calc(24rpx * var(--font-scale, 1));
  741. color: $uni-text-color;
  742. text-align: center;
  743. }
  744. .poster-preview-row {
  745. display: flex;
  746. flex-direction: row;
  747. align-items: center;
  748. justify-content: space-between;
  749. margin-top: 20rpx;
  750. }
  751. .poster-preview-hint {
  752. font-size: calc(24rpx * var(--font-scale, 1));
  753. color: $uni-text-color-secondary;
  754. }
  755. .btn-preview {
  756. padding: 12rpx 32rpx;
  757. border-radius: 32rpx;
  758. background: $brand-primary;
  759. color: $app-surface;
  760. font-size: 26rpx;
  761. }
  762. .form-actions {
  763. display: flex;
  764. flex-direction: row;
  765. gap: 20rpx;
  766. margin-top: 40rpx;
  767. }
  768. .btn-save,
  769. .btn-publish {
  770. flex: 1;
  771. height: 88rpx;
  772. border-radius: 44rpx;
  773. display: flex;
  774. align-items: center;
  775. justify-content: center;
  776. font-size: 30rpx;
  777. font-weight: 600;
  778. }
  779. .btn-save {
  780. background: $app-surface;
  781. color: $brand-primary;
  782. border: 2rpx solid $brand-primary;
  783. }
  784. .btn-publish {
  785. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  786. color: $app-surface;
  787. }
  788. .loading {
  789. position: fixed;
  790. top: 0;
  791. left: 0;
  792. right: 0;
  793. bottom: 0;
  794. background: rgba(255, 255, 255, 0.6);
  795. display: flex;
  796. flex-direction: column;
  797. align-items: center;
  798. justify-content: center;
  799. z-index: 999;
  800. }
  801. .loading-spinner {
  802. width: 60rpx;
  803. height: 60rpx;
  804. border: 4rpx solid $brand-primary-light-2;
  805. border-top: 4rpx solid $brand-primary;
  806. border-radius: 50%;
  807. animation: spin 0.8s linear infinite;
  808. margin-bottom: 16rpx;
  809. }
  810. @keyframes spin {
  811. to { transform: rotate(360deg); }
  812. }
  813. </style>