detail.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view class="container" v-if="wish">
  3. <!-- 心愿详情卡片 -->
  4. <view class="wish-card" :class="wish.status">
  5. <view class="wish-header">
  6. <text class="wish-title">{{ wish.title }}</text>
  7. <text class="wish-status" :class="wish.status">{{ wish.statusText }}</text>
  8. </view>
  9. <!-- 分类 -->
  10. <view class="wish-category" v-if="wish.category">
  11. <text class="category-tag">{{ wish.category }}</text>
  12. </view>
  13. <!-- 描述 -->
  14. <view class="wish-desc" v-if="wish.description">
  15. <text>{{ wish.description }}</text>
  16. </view>
  17. <!-- 积分信息 -->
  18. <view class="points-section" v-if="wish.pointsRequired">
  19. <view class="points-label">所需积分</view>
  20. <view class="points-value">
  21. <text class="points-num">{{ wish.pointsRequired }}</text>
  22. <text class="points-unit">分</text>
  23. </view>
  24. <!-- 进度条 -->
  25. <view class="progress-section" v-if="wish.status === 'active'">
  26. <view class="progress-bar">
  27. <view class="progress-fill" :style="{ width: wish.progress + '%' }"></view>
  28. </view>
  29. <text class="progress-text">
  30. 当前积分: {{ currentPoints }}分
  31. </text>
  32. </view>
  33. </view>
  34. <!-- 时间信息 -->
  35. <view class="time-info">
  36. <text class="time-text">创建于 {{ wish.createdAt }}</text>
  37. </view>
  38. </view>
  39. <!-- 操作按钮区 -->
  40. <view class="action-section">
  41. <!-- 积攒中:积分足够可申请兑换 -->
  42. <button
  43. v-if="wish.status === 'active' && currentPoints >= wish.pointsRequired"
  44. class="btn-primary"
  45. @click="requestExchange"
  46. >
  47. 申请兑换 ({{ wish.pointsRequired }}积分)
  48. </button>
  49. <!-- 积攒中:积分不足 -->
  50. <button
  51. v-if="wish.status === 'active' && currentPoints < wish.pointsRequired"
  52. class="btn-disabled"
  53. disabled
  54. >
  55. 还差{{ wish.pointsRequired - currentPoints }}积分可兑换
  56. </button>
  57. <!-- 待审批 -->
  58. <view v-if="wish.status === 'pending_exchange'" class="waiting-box">
  59. <text class="waiting-icon">⏳</text>
  60. <text class="waiting-text">等待家长审批中...</text>
  61. </view>
  62. <!-- 已批准,等待兑现 -->
  63. <view v-if="wish.status === 'approved'" class="waiting-box">
  64. <text class="waiting-icon">📦</text>
  65. <text class="waiting-text">家长正在准备中,请耐心等待</text>
  66. </view>
  67. <!-- 待收货:确认收货按钮 -->
  68. <button
  69. v-if="wish.status === 'exchanging'"
  70. class="btn-primary"
  71. @click="confirmReceived"
  72. >
  73. 确认收货
  74. </button>
  75. <!-- 已完成 -->
  76. <view v-if="wish.status === 'fulfilled'" class="fulfilled-box">
  77. <text class="fulfilled-icon">🎉</text>
  78. <text class="fulfilled-text">心愿已完成!</text>
  79. <text class="fulfilled-time">{{ wish.fulfilledAt }}</text>
  80. </view>
  81. <!-- 待定价 -->
  82. <view v-if="wish.status === 'draft'" class="waiting-box">
  83. <text class="waiting-icon">📝</text>
  84. <text class="waiting-text">等待家长定价中...</text>
  85. </view>
  86. <!-- 取消按钮(draft或active状态可取消) -->
  87. <button
  88. v-if="wish.status === 'draft' || wish.status === 'active'"
  89. class="btn-cancel"
  90. @click="cancelWish"
  91. >
  92. 取消心愿
  93. </button>
  94. </view>
  95. </view>
  96. <!-- 加载中 -->
  97. <view class="loading" v-else>
  98. <text>加载中...</text>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. getWishById,
  104. requestWishExchange,
  105. confirmWishReceived,
  106. cancelWish as cancelWishApi,
  107. getPointsBalance
  108. } from '../../utils/api.js'
  109. export default {
  110. data() {
  111. return {
  112. wishId: null,
  113. wish: null,
  114. currentPoints: 0,
  115. memberId: ''
  116. }
  117. },
  118. onLoad(options) {
  119. this.wishId = options.id
  120. this.loadData()
  121. },
  122. methods: {
  123. async loadData() {
  124. try {
  125. // 获取心愿详情
  126. const res = await getWishById(this.wishId)
  127. this.wish = res.data
  128. // 获取当前积分
  129. this.memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('userId')
  130. const balanceRes = await getPointsBalance(this.memberId)
  131. this.currentPoints = (balanceRes.data && balanceRes.data.balance) || 0
  132. } catch (e) {
  133. console.error('加载心愿详情失败', e)
  134. uni.showToast({ title: '加载失败', icon: 'none' })
  135. }
  136. },
  137. async requestExchange() {
  138. uni.showModal({
  139. title: '申请兑换',
  140. content: `确定要兑换"${this.wish.title}"吗?\n将消耗${this.wish.pointsRequired}积分`,
  141. success: async (res) => {
  142. if (res.confirm) {
  143. try {
  144. await requestWishExchange(this.wishId)
  145. uni.showToast({ title: '已提交申请', icon: 'success' })
  146. this.loadData()
  147. } catch (e) {
  148. uni.showToast({ title: e.message || '申请失败', icon: 'none' })
  149. }
  150. }
  151. }
  152. })
  153. },
  154. async confirmReceived() {
  155. uni.showModal({
  156. title: '确认收货',
  157. content: `确定已收到"${this.wish.title}"吗?`,
  158. success: async (res) => {
  159. if (res.confirm) {
  160. try {
  161. await confirmWishReceived(this.wishId)
  162. uni.showToast({ title: '心愿已完成!', icon: 'success' })
  163. this.loadData()
  164. } catch (e) {
  165. uni.showToast({ title: '确认失败', icon: 'none' })
  166. }
  167. }
  168. }
  169. })
  170. },
  171. async cancelWish() {
  172. uni.showModal({
  173. title: '取消心愿',
  174. content: `确定要取消"${this.wish.title}"吗?`,
  175. success: async (res) => {
  176. if (res.confirm) {
  177. try {
  178. await cancelWishApi(this.wishId, '不想兑换了')
  179. uni.showToast({ title: '已取消', icon: 'success' })
  180. setTimeout(() => {
  181. uni.navigateBack()
  182. }, 1500)
  183. } catch (e) {
  184. uni.showToast({ title: '取消失败', icon: 'none' })
  185. }
  186. }
  187. }
  188. })
  189. }
  190. }
  191. }
  192. </script>
  193. <style scoped>
  194. .container {
  195. padding: 30rpx;
  196. min-height: 100vh;
  197. background: #f5f5f5;
  198. }
  199. .wish-card {
  200. background: #fff;
  201. border-radius: 20rpx;
  202. padding: 40rpx;
  203. margin-bottom: 30rpx;
  204. }
  205. .wish-card.draft { border-left: 8rpx solid #999; }
  206. .wish-card.active { border-left: 8rpx solid #10B981; }
  207. .wish-card.pending_exchange { border-left: 8rpx solid #F59E0B; }
  208. .wish-card.approved,
  209. .wish-card.exchanging { border-left: 8rpx solid #3B82F6; }
  210. .wish-card.fulfilled { border-left: 8rpx solid #8B5CF6; }
  211. .wish-header {
  212. display: flex;
  213. justify-content: space-between;
  214. align-items: flex-start;
  215. margin-bottom: 20rpx;
  216. }
  217. .wish-title {
  218. font-size: 36rpx;
  219. font-weight: bold;
  220. color: #333;
  221. flex: 1;
  222. }
  223. .wish-status {
  224. font-size: 24rpx;
  225. padding: 8rpx 20rpx;
  226. border-radius: 20rpx;
  227. background: #f0f0f0;
  228. color: #666;
  229. }
  230. .wish-status.active { background: #D1FAE5; color: #059669; }
  231. .wish-status.pending_exchange { background: #FEF3C7; color: #D97706; }
  232. .wish-status.exchanging { background: #DBEAFE; color: #2563EB; }
  233. .wish-status.fulfilled { background: #EDE9FE; color: #7C3AED; }
  234. .category-tag {
  235. font-size: 24rpx;
  236. color: #666;
  237. background: #f5f5f5;
  238. padding: 6rpx 16rpx;
  239. border-radius: 12rpx;
  240. display: inline-block;
  241. margin-bottom: 20rpx;
  242. }
  243. .wish-desc {
  244. font-size: 28rpx;
  245. color: #666;
  246. line-height: 1.6;
  247. margin-bottom: 20rpx;
  248. padding: 20rpx;
  249. background: #f9f9f9;
  250. border-radius: 12rpx;
  251. }
  252. .points-section {
  253. background: linear-gradient(135deg, #F97316, #FB923C);
  254. border-radius: 15rpx;
  255. padding: 25rpx;
  256. color: #fff;
  257. margin-bottom: 20rpx;
  258. }
  259. .points-label {
  260. font-size: 24rpx;
  261. opacity: 0.9;
  262. }
  263. .points-value {
  264. margin-top: 10rpx;
  265. }
  266. .points-num {
  267. font-size: 48rpx;
  268. font-weight: bold;
  269. }
  270. .points-unit {
  271. font-size: 24rpx;
  272. margin-left: 5rpx;
  273. }
  274. .progress-section {
  275. margin-top: 20rpx;
  276. }
  277. .progress-bar {
  278. height: 12rpx;
  279. background: rgba(255,255,255,0.3);
  280. border-radius: 6rpx;
  281. overflow: hidden;
  282. }
  283. .progress-fill {
  284. height: 100%;
  285. background: #fff;
  286. border-radius: 6rpx;
  287. }
  288. .progress-text {
  289. font-size: 22rpx;
  290. margin-top: 10rpx;
  291. display: block;
  292. }
  293. .time-info {
  294. margin-top: 20rpx;
  295. }
  296. .time-text {
  297. font-size: 24rpx;
  298. color: #999;
  299. }
  300. /* 操作区域 */
  301. .action-section {
  302. padding: 20rpx;
  303. }
  304. .btn-primary {
  305. background: linear-gradient(135deg, #F97316, #FB923C);
  306. color: #fff;
  307. font-size: 32rpx;
  308. padding: 24rpx;
  309. border-radius: 50rpx;
  310. margin-bottom: 20rpx;
  311. }
  312. .btn-disabled {
  313. background: #e5e7eb;
  314. color: #9ca3af;
  315. font-size: 32rpx;
  316. padding: 24rpx;
  317. border-radius: 50rpx;
  318. margin-bottom: 20rpx;
  319. }
  320. .btn-cancel {
  321. background: #fff;
  322. color: #999;
  323. font-size: 28rpx;
  324. padding: 20rpx;
  325. border-radius: 40rpx;
  326. border: 1rpx solid #ddd;
  327. }
  328. .waiting-box,
  329. .fulfilled-box {
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. padding: 40rpx;
  334. background: #fff;
  335. border-radius: 20rpx;
  336. margin-bottom: 20rpx;
  337. }
  338. .waiting-icon,
  339. .fulfilled-icon {
  340. font-size: 80rpx;
  341. margin-bottom: 20rpx;
  342. }
  343. .waiting-text,
  344. .fulfilled-text {
  345. font-size: 30rpx;
  346. color: #333;
  347. margin-bottom: 10rpx;
  348. }
  349. .fulfilled-time {
  350. font-size: 24rpx;
  351. color: #8B5CF6;
  352. }
  353. .loading {
  354. display: flex;
  355. justify-content: center;
  356. align-items: center;
  357. height: 100vh;
  358. color: #999;
  359. }
  360. </style>