detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 编辑模式 -->
  4. <view class="edit-section" v-if="!readonly">
  5. <view class="form-card">
  6. <view class="form-title">活动信息</view>
  7. <view class="form-item">
  8. <text class="form-label">活动标题 *</text>
  9. <input class="form-input" v-model="form.title" placeholder="请输入活动标题" :disabled="readonly" />
  10. </view>
  11. <view class="form-item">
  12. <text class="form-label">活动分类</text>
  13. <picker class="form-picker" :value="categoryIdx" :range="categoryOptions" range-key="label"
  14. @change="onCategoryChange">
  15. <text class="picker-text">{{ form.category ? categoryLabel(form.category) : '请选择分类' }}</text>
  16. </picker>
  17. </view>
  18. <view class="form-item">
  19. <text class="form-label">活动日期时间 *</text>
  20. <view class="form-date-picker" @click="showDatePicker">
  21. <text class="picker-text">{{ form.activityDate ? formatDate(form.activityDate) : '请选择日期和时间' }}</text>
  22. </view>
  23. </view>
  24. <view class="form-item">
  25. <text class="form-label">活动地点</text>
  26. <input class="form-input" v-model="form.location" placeholder="请输入活动地点" />
  27. </view>
  28. <view class="form-item-row">
  29. <view class="form-item half">
  30. <text class="form-label">最大人数</text>
  31. <input class="form-input" type="number" v-model="form.maxParticipants" placeholder="20" />
  32. </view>
  33. <view class="form-item half">
  34. <text class="form-label">价格(元)</text>
  35. <input class="form-input" type="digit" v-model="priceYuan" placeholder="0表示免费" />
  36. </view>
  37. </view>
  38. <view class="form-item">
  39. <text class="form-label">封面图片URL</text>
  40. <input class="form-input" v-model="form.coverImage" placeholder="输入图片URL" />
  41. <view class="cover-preview" v-if="form.coverImage">
  42. <image class="preview-img" :src="getImageUrl(form.coverImage)" mode="aspectFill" @error="onImgError" />
  43. </view>
  44. </view>
  45. <view class="form-item">
  46. <text class="form-label">活动描述</text>
  47. <textarea class="form-textarea" v-model="form.description" placeholder="请输入活动详细介绍" />
  48. </view>
  49. <view class="form-actions">
  50. <view class="btn-save" @click="handleSave">
  51. <text>保存</text>
  52. </view>
  53. <view class="btn-publish" v-if="form.status === 'draft'" @click="handlePublish">
  54. <text>保存并发布</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 只读模式(已发布/已取消/已完成) -->
  60. <view class="detail-section" v-else>
  61. <view class="detail-cover" v-if="form.coverImage">
  62. <image class="cover-img" :src="getImageUrl(form.coverImage)" mode="aspectFill" />
  63. </view>
  64. <view class="detail-cover placeholder" v-else>
  65. <text class="placeholder-icon">{{ categoryIcon(form.category) }}</text>
  66. </view>
  67. <view class="detail-card">
  68. <view class="detail-header">
  69. <text class="detail-title">{{ form.title }}</text>
  70. <text class="detail-status" :class="'status-' + form.status">{{ statusText(form.status) }}</text>
  71. </view>
  72. <view class="detail-meta-row">
  73. <view class="meta-item">
  74. <text class="meta-icon">&#x1F4C5;</text>
  75. <text class="meta-text">{{ form.activityDate ? formatDate(form.activityDate) : '待定' }}</text>
  76. </view>
  77. <view class="meta-item" v-if="form.location">
  78. <text class="meta-icon">&#x1F4CD;</text>
  79. <text class="meta-text">{{ form.location }}</text>
  80. </view>
  81. </view>
  82. <view class="detail-stats">
  83. <view class="stat-box">
  84. <text class="stat-val">{{ form.currentParticipants || 0 }}</text>
  85. <text class="stat-label">已报名</text>
  86. </view>
  87. <view class="stat-box">
  88. <text class="stat-val">{{ form.maxParticipants || 20 }}</text>
  89. <text class="stat-label">最大人数</text>
  90. </view>
  91. <view class="stat-box">
  92. <text class="stat-val">{{ form.price > 0 ? (form.price / 100 + '元') : '免费' }}</text>
  93. <text class="stat-label">价格</text>
  94. </view>
  95. </view>
  96. <view class="detail-desc" v-if="form.description">
  97. <text class="section-title">活动介绍</text>
  98. <text class="desc-text">{{ form.description }}</text>
  99. </view>
  100. <view class="detail-actions" v-if="form.status === 'draft'">
  101. <view class="btn-edit" @click="readonly = false">
  102. <text>编辑</text>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="loading" v-if="loading"><text class="loading-text">加载中...</text></view>
  108. </view>
  109. </template>
  110. <script>
  111. import { getGuideActivityDetail, createActivity, updateActivity, publishActivity } from '../../../utils/api.js'
  112. import config from '@/config.js'
  113. import { parseDate } from '../../../utils/format.js'
  114. import fontScaleMixin from '@/mixins/font-scale.js'
  115. export default {
  116. mixins: [fontScaleMixin],
  117. data() {
  118. return {
  119. activityId: null,
  120. isNew: false,
  121. readonly: false,
  122. loading: false,
  123. form: {
  124. title: '',
  125. description: '',
  126. coverImage: '',
  127. category: '',
  128. location: '',
  129. activityDate: null,
  130. maxParticipants: 20,
  131. price: 0,
  132. status: 'draft'
  133. },
  134. priceYuan: '0',
  135. categoryIdx: 0,
  136. categoryOptions: [
  137. { key: 'outdoor', label: '&#x26F5; 户外运动' },
  138. { key: 'nature', label: '&#x1F33F; 自然探索' },
  139. { key: 'culture', label: '&#x1F3A8; 文化体验' },
  140. { key: 'sports', label: '&#x26BD; 体育竞技' },
  141. { key: 'other', label: '&#x1F3E0; 其他' }
  142. ]
  143. }
  144. },
  145. onLoad(options) {
  146. this.activityId = options.activityId ? parseInt(options.activityId) : null
  147. if (!this.activityId || this.activityId === 0) {
  148. this.isNew = true
  149. this.readonly = false
  150. uni.setNavigationBarTitle({ title: '创建活动' })
  151. } else {
  152. this.loadDetail()
  153. }
  154. },
  155. methods: {
  156. loadDetail() {
  157. var self = this
  158. self.loading = true
  159. getGuideActivityDetail(self.activityId).then(function(res) {
  160. self.loading = false
  161. if (res.code === 200 && res.data) {
  162. self.form = res.data
  163. self.priceYuan = self.form.price ? (self.form.price / 100).toString() : '0'
  164. self.readonly = self.form.status !== 'draft'
  165. uni.setNavigationBarTitle({ title: self.readonly ? '活动详情' : '编辑活动' })
  166. }
  167. }).catch(function() { self.loading = false })
  168. },
  169. onCategoryChange(e) {
  170. this.categoryIdx = e.detail.value
  171. this.form.category = this.categoryOptions[this.categoryIdx].key
  172. },
  173. showDatePicker() {
  174. var self = this
  175. uni.showDatePicker({
  176. mode: 'date',
  177. success: function(res) {
  178. var date = res.value
  179. uni.showTimePicker({
  180. mode: 'time',
  181. success: function(res2) {
  182. var time = res2.value
  183. var d = parseDate(date)
  184. if (!d) return
  185. var parts = time.split(':')
  186. d.setHours(parseInt(parts[0]), parseInt(parts[1]))
  187. self.form.activityDate = d
  188. }
  189. })
  190. }
  191. })
  192. },
  193. handleSave() {
  194. if (!this.form.title) {
  195. uni.showToast({ title: '请输入活动标题', icon: 'none' })
  196. return
  197. }
  198. this.save(false)
  199. },
  200. handlePublish() {
  201. if (!this.form.title) {
  202. uni.showToast({ title: '请输入活动标题', icon: 'none' })
  203. return
  204. }
  205. this.save(true)
  206. },
  207. save(publishAfterSave) {
  208. var self = this
  209. var payload = Object.assign({}, self.form)
  210. if (self.priceYuan) {
  211. payload.price = Math.round(parseFloat(self.priceYuan) * 100)
  212. }
  213. var done = function() {
  214. if (publishAfterSave && self.form.status === 'draft') {
  215. publishActivity(self.form.id || self.activityId).then(function(r) {
  216. if (r.code === 200) {
  217. uni.showToast({ title: '已发布', icon: 'success' })
  218. setTimeout(function() {
  219. uni.redirectTo({ url: '/pages/guide/activities/index' })
  220. }, 1000)
  221. } else {
  222. uni.showToast({ title: '发布失败', icon: 'none' })
  223. }
  224. })
  225. } else {
  226. uni.showToast({ title: '保存成功', icon: 'success' })
  227. setTimeout(function() {
  228. uni.navigateBack()
  229. }, 1000)
  230. }
  231. }
  232. if (self.isNew || !self.form.id) {
  233. createActivity(payload).then(function(res) {
  234. if (res.code === 200) {
  235. self.form.id = res.data
  236. self.isNew = false
  237. if (publishAfterSave) {
  238. publishActivity(res.data).then(function(r) {
  239. if (r.code === 200) {
  240. uni.showToast({ title: '已发布', icon: 'success' })
  241. setTimeout(function() {
  242. uni.redirectTo({ url: '/pages/guide/activities/index' })
  243. }, 1000)
  244. }
  245. })
  246. } else {
  247. done()
  248. }
  249. } else {
  250. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  251. }
  252. }).catch(function() {
  253. uni.showToast({ title: '网络异常', icon: 'none' })
  254. })
  255. } else {
  256. payload.id = self.form.id || self.activityId
  257. updateActivity(payload).then(function(res) {
  258. if (res.code === 200) {
  259. if (publishAfterSave) {
  260. publishActivity(payload.id).then(function(r) {
  261. if (r.code === 200) {
  262. uni.showToast({ title: '已发布', icon: 'success' })
  263. setTimeout(function() {
  264. uni.redirectTo({ url: '/pages/guide/activities/index' })
  265. }, 1000)
  266. }
  267. })
  268. } else {
  269. done()
  270. }
  271. } else {
  272. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  273. }
  274. }).catch(function() {
  275. uni.showToast({ title: '网络异常', icon: 'none' })
  276. })
  277. }
  278. },
  279. onImgError() {
  280. this.form.coverImage = ''
  281. },
  282. categoryLabel(key) {
  283. var map = { outdoor: '户外运动', nature: '自然探索', culture: '文化体验', sports: '体育竞技', other: '其他' }
  284. return map[key] || '其他'
  285. },
  286. categoryIcon(category) {
  287. var map = { outdoor: '&#x26F5;', nature: '&#x1F33F;', culture: '&#x1F3A8;', sports: '&#x26BD;', other: '&#x1F3E0;' }
  288. return map[category] || '&#x1F3E0;'
  289. },
  290. statusText(status) {
  291. var map = { draft: '草稿', published: '已发布', cancelled: '已取消', completed: '已完成' }
  292. return map[status] || status || '草稿'
  293. },
  294. formatDate(dateStr) {
  295. if (!dateStr) return ''
  296. var d = parseDate(dateStr)
  297. if (!d) return ''
  298. var y = d.getFullYear()
  299. var m = ('0' + (d.getMonth() + 1)).slice(-2)
  300. var day = ('0' + d.getDate()).slice(-2)
  301. var h = ('0' + d.getHours()).slice(-2)
  302. var mi = ('0' + d.getMinutes()).slice(-2)
  303. return y + '-' + m + '-' + day + ' ' + h + ':' + mi
  304. },getImageUrl: function(path) {
  305. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  306. var s = String(path).trim()
  307. if (!s || s === 'null' || s === '/null') return ''
  308. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  309. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  310. }
  311. }
  312. }
  313. </script>
  314. <style scoped lang="scss">
  315. .container {
  316. min-height: 100vh;
  317. background: $app-bg;
  318. padding-bottom: 60rpx;
  319. }
  320. /* ===== 编辑表单 ===== */
  321. .edit-section {
  322. padding: 20rpx $uni-space-page;
  323. }
  324. .form-card {
  325. background: $app-surface;
  326. border-radius: 24rpx;
  327. padding: 28rpx;
  328. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  329. }
  330. .form-title {
  331. font-size: calc(30rpx * var(--font-scale, 1));
  332. font-weight: bold;
  333. color: $facade-text-strong;
  334. margin-bottom: 24rpx;
  335. padding-bottom: 16rpx;
  336. border-bottom: 1rpx solid $facade-fill;
  337. }
  338. .form-item {
  339. margin-bottom: 24rpx;
  340. }
  341. .form-item:last-child {
  342. margin-bottom: 0;
  343. }
  344. .form-item-row {
  345. display: flex;
  346. flex-direction: row;
  347. gap: 16rpx;
  348. }
  349. .form-item.half {
  350. flex: 1;
  351. }
  352. .form-label {
  353. font-size: calc(26rpx * var(--font-scale, 1));
  354. color: $facade-text-faint;
  355. display: block;
  356. margin-bottom: 8rpx;
  357. }
  358. .form-input {
  359. width: 100%;
  360. height: 80rpx;
  361. background: $facade-fill-gray-50;
  362. border: 1rpx solid $facade-gray-200;
  363. border-radius: 16rpx;
  364. padding: 0 20rpx;
  365. font-size: calc(28rpx * var(--font-scale, 1));
  366. color: $facade-text-strong;
  367. box-sizing: border-box;
  368. }
  369. .form-picker, .form-date-picker {
  370. width: 100%;
  371. min-height: 80rpx;
  372. background: $facade-fill-gray-50;
  373. border: 1rpx solid $facade-gray-200;
  374. border-radius: 16rpx;
  375. padding: 20rpx;
  376. box-sizing: border-box;
  377. }
  378. .picker-text {
  379. font-size: calc(28rpx * var(--font-scale, 1));
  380. color: $facade-text-strong;
  381. }
  382. .form-textarea {
  383. width: 100%;
  384. background: $facade-fill-gray-50;
  385. border: 1rpx solid $facade-gray-200;
  386. border-radius: 16rpx;
  387. padding: 16rpx 20rpx;
  388. font-size: calc(28rpx * var(--font-scale, 1));
  389. color: $facade-text-strong;
  390. box-sizing: border-box;
  391. min-height: 160rpx;
  392. display: block;
  393. }
  394. .cover-preview {
  395. margin-top: 12rpx;
  396. border-radius: 16rpx;
  397. overflow: hidden;
  398. height: 200rpx;
  399. }
  400. .preview-img {
  401. width: 100%;
  402. height: 200rpx;
  403. }
  404. .form-actions {
  405. display: flex;
  406. flex-direction: row;
  407. gap: 16rpx;
  408. justify-content: center;
  409. margin-top: 32rpx;
  410. padding-top: 24rpx;
  411. border-top: 1rpx solid $facade-fill;
  412. }
  413. .btn-save, .btn-publish {
  414. padding: 18rpx 48rpx;
  415. border-radius: 24rpx;
  416. font-size: calc(28rpx * var(--font-scale, 1));
  417. font-weight: 500;
  418. }
  419. .btn-save {
  420. background: linear-gradient(135deg, $status-success, $status-success-deep);
  421. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  422. }
  423. .btn-publish {
  424. background: $app-surface;
  425. border: 2rpx solid $status-success;
  426. color: $status-success;
  427. }
  428. .btn-save:active, .btn-publish:active { opacity: 0.8; }
  429. .btn-save text, .btn-publish text {
  430. font-weight: 500;
  431. }
  432. /* ===== 详情模式 ===== */
  433. .detail-section {
  434. padding: 0;
  435. }
  436. .detail-cover {
  437. width: 100%;
  438. height: 400rpx;
  439. background: linear-gradient(135deg, $status-success 0%, $status-success-deep 100%);
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. }
  444. .cover-img {
  445. width: 100%;
  446. height: 100%;
  447. }
  448. .placeholder-icon {
  449. font-size: calc(120rpx * var(--font-scale, 1));
  450. color: rgba(255,255,255,0.8);
  451. }
  452. .detail-card {
  453. background: $app-surface;
  454. margin: -40rpx $uni-space-lg 0;
  455. border-radius: 24rpx;
  456. padding: 32rpx;
  457. box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.08);
  458. position: relative;
  459. }
  460. .detail-header {
  461. display: flex;
  462. flex-direction: row;
  463. justify-content: space-between;
  464. align-items: flex-start;
  465. margin-bottom: 20rpx;
  466. }
  467. .detail-title {
  468. font-size: calc(36rpx * var(--font-scale, 1));
  469. font-weight: bold;
  470. color: $facade-text-strong;
  471. flex: 1;
  472. margin-right: 16rpx;
  473. }
  474. .detail-status {
  475. font-size: calc(24rpx * var(--font-scale, 1));
  476. padding: 6rpx 18rpx;
  477. border-radius: 16rpx;
  478. flex-shrink: 0;
  479. }
  480. .status-draft { background: $facade-fill-gray-100; color: $facade-text-body; }
  481. .status-published { background: $status-success-soft; color: $status-success-deep; }
  482. .status-cancelled { background: $status-danger-soft; color: $status-danger-deep; }
  483. .status-completed { background: $status-info-soft; color: $status-info-deep; }
  484. .detail-meta-row {
  485. display: flex;
  486. flex-direction: row;
  487. gap: 24rpx;
  488. margin-bottom: 24rpx;
  489. padding-bottom: 20rpx;
  490. border-bottom: 1rpx solid $facade-fill;
  491. }
  492. .meta-item {
  493. display: flex;
  494. flex-direction: row;
  495. align-items: center;
  496. gap: 6rpx;
  497. }
  498. .meta-icon {
  499. font-size: calc(26rpx * var(--font-scale, 1));
  500. }
  501. .meta-text {
  502. font-size: calc(26rpx * var(--font-scale, 1));
  503. color: $facade-text-body;
  504. }
  505. .detail-stats {
  506. display: flex;
  507. flex-direction: row;
  508. gap: 20rpx;
  509. margin-bottom: 24rpx;
  510. padding-bottom: 20rpx;
  511. border-bottom: 1rpx solid $facade-fill;
  512. }
  513. .stat-box {
  514. flex: 1;
  515. background: $facade-fill-gray-50;
  516. border-radius: 16rpx;
  517. padding: 20rpx;
  518. text-align: center;
  519. }
  520. .stat-val {
  521. font-size: calc(36rpx * var(--font-scale, 1));
  522. font-weight: bold;
  523. color: $status-success;
  524. display: block;
  525. }
  526. .stat-label {
  527. font-size: calc(22rpx * var(--font-scale, 1));
  528. color: $facade-text-faint;
  529. display: block;
  530. margin-top: 4rpx;
  531. }
  532. .section-title {
  533. font-size: calc(28rpx * var(--font-scale, 1));
  534. font-weight: bold;
  535. color: $facade-text-strong;
  536. display: block;
  537. margin-bottom: 12rpx;
  538. }
  539. .desc-text {
  540. font-size: calc(28rpx * var(--font-scale, 1));
  541. color: $facade-text-body;
  542. line-height: 1.7;
  543. display: block;
  544. }
  545. .detail-desc {
  546. margin-bottom: 24rpx;
  547. }
  548. .detail-actions {
  549. display: flex;
  550. flex-direction: row;
  551. justify-content: center;
  552. margin-top: 24rpx;
  553. }
  554. .btn-edit {
  555. background: linear-gradient(135deg, $status-success, $status-success-deep);
  556. padding: 18rpx 64rpx;
  557. border-radius: 24rpx;
  558. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  559. }
  560. .btn-edit:active { opacity: 0.8; }
  561. .btn-edit text {
  562. color: $app-surface;
  563. font-size: calc(28rpx * var(--font-scale, 1));
  564. font-weight: bold;
  565. }
  566. .loading {
  567. display: flex;
  568. align-items: center;
  569. justify-content: center;
  570. padding: 80rpx;
  571. }
  572. .loading-text {
  573. font-size: calc(28rpx * var(--font-scale, 1));
  574. color: $facade-text-muted;
  575. }
  576. </style>