detail.vue 16 KB

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