detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <view class="container">
  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. export default {
  114. data() {
  115. return {
  116. activityId: null,
  117. isNew: false,
  118. readonly: false,
  119. loading: false,
  120. form: {
  121. title: '',
  122. description: '',
  123. coverImage: '',
  124. category: '',
  125. location: '',
  126. activityDate: null,
  127. maxParticipants: 20,
  128. price: 0,
  129. status: 'draft'
  130. },
  131. priceYuan: '0',
  132. categoryIdx: 0,
  133. categoryOptions: [
  134. { key: 'outdoor', label: '&#x26F5; 户外运动' },
  135. { key: 'nature', label: '&#x1F33F; 自然探索' },
  136. { key: 'culture', label: '&#x1F3A8; 文化体验' },
  137. { key: 'sports', label: '&#x26BD; 体育竞技' },
  138. { key: 'other', label: '&#x1F3E0; 其他' }
  139. ]
  140. }
  141. },
  142. onLoad(options) {
  143. this.activityId = options.activityId ? parseInt(options.activityId) : null
  144. if (!this.activityId || this.activityId === 0) {
  145. this.isNew = true
  146. this.readonly = false
  147. uni.setNavigationBarTitle({ title: '创建活动' })
  148. } else {
  149. this.loadDetail()
  150. }
  151. },
  152. methods: {
  153. loadDetail() {
  154. var self = this
  155. self.loading = true
  156. getGuideActivityDetail(self.activityId).then(function(res) {
  157. self.loading = false
  158. if (res.code === 200 && res.data) {
  159. self.form = res.data
  160. self.priceYuan = self.form.price ? (self.form.price / 100).toString() : '0'
  161. self.readonly = self.form.status !== 'draft'
  162. uni.setNavigationBarTitle({ title: self.readonly ? '活动详情' : '编辑活动' })
  163. }
  164. }).catch(function() { self.loading = false })
  165. },
  166. onCategoryChange(e) {
  167. this.categoryIdx = e.detail.value
  168. this.form.category = this.categoryOptions[this.categoryIdx].key
  169. },
  170. showDatePicker() {
  171. var self = this
  172. uni.showDatePicker({
  173. mode: 'date',
  174. success: function(res) {
  175. var date = res.value
  176. uni.showTimePicker({
  177. mode: 'time',
  178. success: function(res2) {
  179. var time = res2.value
  180. var d = new Date(date)
  181. var parts = time.split(':')
  182. d.setHours(parseInt(parts[0]), parseInt(parts[1]))
  183. self.form.activityDate = d
  184. }
  185. })
  186. }
  187. })
  188. },
  189. handleSave() {
  190. if (!this.form.title) {
  191. uni.showToast({ title: '请输入活动标题', icon: 'none' })
  192. return
  193. }
  194. this.save(false)
  195. },
  196. handlePublish() {
  197. if (!this.form.title) {
  198. uni.showToast({ title: '请输入活动标题', icon: 'none' })
  199. return
  200. }
  201. this.save(true)
  202. },
  203. save(publishAfterSave) {
  204. var self = this
  205. var payload = Object.assign({}, self.form)
  206. if (self.priceYuan) {
  207. payload.price = Math.round(parseFloat(self.priceYuan) * 100)
  208. }
  209. var done = function() {
  210. if (publishAfterSave && self.form.status === 'draft') {
  211. publishActivity(self.form.id || self.activityId).then(function(r) {
  212. if (r.code === 200) {
  213. uni.showToast({ title: '已发布', icon: 'success' })
  214. setTimeout(function() {
  215. uni.redirectTo({ url: '/pages/guide/activities/index' })
  216. }, 1000)
  217. } else {
  218. uni.showToast({ title: '发布失败', icon: 'none' })
  219. }
  220. })
  221. } else {
  222. uni.showToast({ title: '保存成功', icon: 'success' })
  223. setTimeout(function() {
  224. uni.navigateBack()
  225. }, 1000)
  226. }
  227. }
  228. if (self.isNew || !self.form.id) {
  229. createActivity(payload).then(function(res) {
  230. if (res.code === 200) {
  231. self.form.id = res.data
  232. self.isNew = false
  233. if (publishAfterSave) {
  234. publishActivity(res.data).then(function(r) {
  235. if (r.code === 200) {
  236. uni.showToast({ title: '已发布', icon: 'success' })
  237. setTimeout(function() {
  238. uni.redirectTo({ url: '/pages/guide/activities/index' })
  239. }, 1000)
  240. }
  241. })
  242. } else {
  243. done()
  244. }
  245. } else {
  246. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  247. }
  248. }).catch(function() {
  249. uni.showToast({ title: '网络异常', icon: 'none' })
  250. })
  251. } else {
  252. payload.id = self.form.id || self.activityId
  253. updateActivity(payload).then(function(res) {
  254. if (res.code === 200) {
  255. if (publishAfterSave) {
  256. publishActivity(payload.id).then(function(r) {
  257. if (r.code === 200) {
  258. uni.showToast({ title: '已发布', icon: 'success' })
  259. setTimeout(function() {
  260. uni.redirectTo({ url: '/pages/guide/activities/index' })
  261. }, 1000)
  262. }
  263. })
  264. } else {
  265. done()
  266. }
  267. } else {
  268. uni.showToast({ title: res.message || '保存失败', icon: 'none' })
  269. }
  270. }).catch(function() {
  271. uni.showToast({ title: '网络异常', icon: 'none' })
  272. })
  273. }
  274. },
  275. onImgError() {
  276. this.form.coverImage = ''
  277. },
  278. categoryLabel(key) {
  279. var map = { outdoor: '户外运动', nature: '自然探索', culture: '文化体验', sports: '体育竞技', other: '其他' }
  280. return map[key] || '其他'
  281. },
  282. categoryIcon(category) {
  283. var map = { outdoor: '&#x26F5;', nature: '&#x1F33F;', culture: '&#x1F3A8;', sports: '&#x26BD;', other: '&#x1F3E0;' }
  284. return map[category] || '&#x1F3E0;'
  285. },
  286. statusText(status) {
  287. var map = { draft: '草稿', published: '已发布', cancelled: '已取消', completed: '已完成' }
  288. return map[status] || status || '草稿'
  289. },
  290. formatDate(dateStr) {
  291. if (!dateStr) return ''
  292. var d = new Date(dateStr)
  293. var y = d.getFullYear()
  294. var m = ('0' + (d.getMonth() + 1)).slice(-2)
  295. var day = ('0' + d.getDate()).slice(-2)
  296. var h = ('0' + d.getHours()).slice(-2)
  297. var mi = ('0' + d.getMinutes()).slice(-2)
  298. return y + '-' + m + '-' + day + ' ' + h + ':' + mi
  299. },
  300. getImageUrl: function(path) {
  301. return config.API_BASE_URL + path
  302. }
  303. }
  304. }
  305. </script>
  306. <style scoped>
  307. .container {
  308. min-height: 100vh;
  309. background: #f5f7fa;
  310. padding-bottom: 60rpx;
  311. }
  312. /* ===== 编辑表单 ===== */
  313. .edit-section {
  314. padding: 20rpx 30rpx;
  315. }
  316. .form-card {
  317. background: #fff;
  318. border-radius: 20rpx;
  319. padding: 28rpx;
  320. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  321. }
  322. .form-title {
  323. font-size: 30rpx;
  324. font-weight: bold;
  325. color: #333;
  326. margin-bottom: 24rpx;
  327. padding-bottom: 16rpx;
  328. border-bottom: 1rpx solid #f0f0f0;
  329. }
  330. .form-item {
  331. margin-bottom: 24rpx;
  332. }
  333. .form-item:last-child {
  334. margin-bottom: 0;
  335. }
  336. .form-item-row {
  337. display: flex;
  338. flex-direction: row;
  339. gap: 16rpx;
  340. }
  341. .form-item.half {
  342. flex: 1;
  343. }
  344. .form-label {
  345. font-size: 26rpx;
  346. color: #888;
  347. display: block;
  348. margin-bottom: 8rpx;
  349. }
  350. .form-input {
  351. width: 100%;
  352. height: 80rpx;
  353. background: #f9fafb;
  354. border: 1rpx solid #e5e7eb;
  355. border-radius: 12rpx;
  356. padding: 0 20rpx;
  357. font-size: 28rpx;
  358. color: #333;
  359. box-sizing: border-box;
  360. }
  361. .form-picker, .form-date-picker {
  362. width: 100%;
  363. min-height: 80rpx;
  364. background: #f9fafb;
  365. border: 1rpx solid #e5e7eb;
  366. border-radius: 12rpx;
  367. padding: 20rpx;
  368. box-sizing: border-box;
  369. }
  370. .picker-text {
  371. font-size: 28rpx;
  372. color: #333;
  373. }
  374. .form-textarea {
  375. width: 100%;
  376. background: #f9fafb;
  377. border: 1rpx solid #e5e7eb;
  378. border-radius: 12rpx;
  379. padding: 16rpx 20rpx;
  380. font-size: 28rpx;
  381. color: #333;
  382. box-sizing: border-box;
  383. min-height: 160rpx;
  384. display: block;
  385. }
  386. .cover-preview {
  387. margin-top: 12rpx;
  388. border-radius: 12rpx;
  389. overflow: hidden;
  390. height: 200rpx;
  391. }
  392. .preview-img {
  393. width: 100%;
  394. height: 200rpx;
  395. }
  396. .form-actions {
  397. display: flex;
  398. flex-direction: row;
  399. gap: 16rpx;
  400. justify-content: center;
  401. margin-top: 32rpx;
  402. padding-top: 24rpx;
  403. border-top: 1rpx solid #f0f0f0;
  404. }
  405. .btn-save, .btn-publish {
  406. padding: 18rpx 48rpx;
  407. border-radius: 40rpx;
  408. font-size: 28rpx;
  409. font-weight: 500;
  410. }
  411. .btn-save {
  412. background: linear-gradient(135deg, #10B981, #059669);
  413. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  414. }
  415. .btn-publish {
  416. background: #fff;
  417. border: 2rpx solid #10B981;
  418. color: #10B981;
  419. }
  420. .btn-save:active, .btn-publish:active { opacity: 0.8; }
  421. .btn-save text, .btn-publish text {
  422. font-weight: 500;
  423. }
  424. /* ===== 详情模式 ===== */
  425. .detail-section {
  426. padding: 0;
  427. }
  428. .detail-cover {
  429. width: 100%;
  430. height: 400rpx;
  431. background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  432. display: flex;
  433. align-items: center;
  434. justify-content: center;
  435. }
  436. .cover-img {
  437. width: 100%;
  438. height: 100%;
  439. }
  440. .placeholder-icon {
  441. font-size: 120rpx;
  442. color: rgba(255,255,255,0.8);
  443. }
  444. .detail-card {
  445. background: #fff;
  446. margin: -40rpx 30rpx 0;
  447. border-radius: 24rpx;
  448. padding: 32rpx;
  449. box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.08);
  450. position: relative;
  451. }
  452. .detail-header {
  453. display: flex;
  454. flex-direction: row;
  455. justify-content: space-between;
  456. align-items: flex-start;
  457. margin-bottom: 20rpx;
  458. }
  459. .detail-title {
  460. font-size: 36rpx;
  461. font-weight: bold;
  462. color: #333;
  463. flex: 1;
  464. margin-right: 16rpx;
  465. }
  466. .detail-status {
  467. font-size: 24rpx;
  468. padding: 6rpx 18rpx;
  469. border-radius: 16rpx;
  470. flex-shrink: 0;
  471. }
  472. .status-draft { background: #f3f4f6; color: #666; }
  473. .status-published { background: #d1fae5; color: #059669; }
  474. .status-cancelled { background: #fee2e2; color: #dc2626; }
  475. .status-completed { background: #dbeafe; color: #2563eb; }
  476. .detail-meta-row {
  477. display: flex;
  478. flex-direction: row;
  479. gap: 24rpx;
  480. margin-bottom: 24rpx;
  481. padding-bottom: 20rpx;
  482. border-bottom: 1rpx solid #f0f0f0;
  483. }
  484. .meta-item {
  485. display: flex;
  486. flex-direction: row;
  487. align-items: center;
  488. gap: 6rpx;
  489. }
  490. .meta-icon {
  491. font-size: 26rpx;
  492. }
  493. .meta-text {
  494. font-size: 26rpx;
  495. color: #666;
  496. }
  497. .detail-stats {
  498. display: flex;
  499. flex-direction: row;
  500. gap: 20rpx;
  501. margin-bottom: 24rpx;
  502. padding-bottom: 20rpx;
  503. border-bottom: 1rpx solid #f0f0f0;
  504. }
  505. .stat-box {
  506. flex: 1;
  507. background: #f9fafb;
  508. border-radius: 16rpx;
  509. padding: 20rpx;
  510. text-align: center;
  511. }
  512. .stat-val {
  513. font-size: 36rpx;
  514. font-weight: bold;
  515. color: #10B981;
  516. display: block;
  517. }
  518. .stat-label {
  519. font-size: 22rpx;
  520. color: #888;
  521. display: block;
  522. margin-top: 4rpx;
  523. }
  524. .section-title {
  525. font-size: 28rpx;
  526. font-weight: bold;
  527. color: #333;
  528. display: block;
  529. margin-bottom: 12rpx;
  530. }
  531. .desc-text {
  532. font-size: 28rpx;
  533. color: #666;
  534. line-height: 1.7;
  535. display: block;
  536. }
  537. .detail-desc {
  538. margin-bottom: 24rpx;
  539. }
  540. .detail-actions {
  541. display: flex;
  542. flex-direction: row;
  543. justify-content: center;
  544. margin-top: 24rpx;
  545. }
  546. .btn-edit {
  547. background: linear-gradient(135deg, #10B981, #059669);
  548. padding: 18rpx 64rpx;
  549. border-radius: 40rpx;
  550. box-shadow: 0 4rpx 16rpx rgba(16, 185, 129, 0.3);
  551. }
  552. .btn-edit:active { opacity: 0.8; }
  553. .btn-edit text {
  554. color: #fff;
  555. font-size: 28rpx;
  556. font-weight: bold;
  557. }
  558. .loading {
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. padding: 80rpx;
  563. }
  564. .loading-text {
  565. font-size: 28rpx;
  566. color: #999;
  567. }
  568. </style>