detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="container" v-if="wish" :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  110. export default {
  111. mixins: [fontScaleMixin],
  112. data() {
  113. return {
  114. wishId: null,
  115. wish: null,
  116. currentPoints: 0,
  117. memberId: ''
  118. }
  119. },
  120. onLoad(options) {
  121. this.wishId = options.id
  122. this.loadData()
  123. },
  124. methods: {
  125. async loadData() {
  126. try {
  127. // 获取心愿详情
  128. const res = await getWishById(this.wishId)
  129. this.wish = res.data
  130. // 获取当前积分
  131. this.memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('userId')
  132. const balanceRes = await getPointsBalance(this.memberId)
  133. this.currentPoints = (balanceRes.data && balanceRes.data.balance) || 0
  134. } catch (e) {
  135. console.error('加载心愿详情失败', e)
  136. uni.showToast({ title: '加载失败', icon: 'none' })
  137. }
  138. },
  139. async requestExchange() {
  140. uni.showModal({
  141. title: '申请兑换',
  142. content: `确定要兑换"${this.wish.title}"吗?\n将消耗${this.wish.pointsRequired}积分`,
  143. success: async (res) => {
  144. if (res.confirm) {
  145. try {
  146. await requestWishExchange(this.wishId)
  147. uni.showToast({ title: '已提交申请', icon: 'success' })
  148. this.loadData()
  149. } catch (e) {
  150. uni.showToast({ title: e.message || '申请失败', icon: 'none' })
  151. }
  152. }
  153. }
  154. })
  155. },
  156. async confirmReceived() {
  157. uni.showModal({
  158. title: '确认收货',
  159. content: `确定已收到"${this.wish.title}"吗?`,
  160. success: async (res) => {
  161. if (res.confirm) {
  162. try {
  163. await confirmWishReceived(this.wishId)
  164. uni.showToast({ title: '心愿已完成!', icon: 'success' })
  165. this.loadData()
  166. } catch (e) {
  167. uni.showToast({ title: '确认失败', icon: 'none' })
  168. }
  169. }
  170. }
  171. })
  172. },
  173. async cancelWish() {
  174. uni.showModal({
  175. title: '取消心愿',
  176. content: `确定要取消"${this.wish.title}"吗?`,
  177. success: async (res) => {
  178. if (res.confirm) {
  179. try {
  180. await cancelWishApi(this.wishId, '不想兑换了')
  181. uni.showToast({ title: '已取消', icon: 'success' })
  182. setTimeout(() => {
  183. uni.navigateBack()
  184. }, 1500)
  185. } catch (e) {
  186. uni.showToast({ title: '取消失败', icon: 'none' })
  187. }
  188. }
  189. }
  190. })
  191. }
  192. }
  193. }
  194. </script>
  195. <style scoped lang="scss">
  196. .container {
  197. padding: $uni-space-page;
  198. min-height: 100vh;
  199. background: $facade-fill-2;
  200. }
  201. .wish-card {
  202. background: $app-surface;
  203. border-radius: 24rpx;
  204. padding: 40rpx;
  205. margin-bottom: $uni-space-lg;
  206. }
  207. .wish-card.draft { border-left: 8rpx solid $facade-text-muted; }
  208. .wish-card.active { border-left: 8rpx solid $status-success; }
  209. .wish-card.pending_exchange { border-left: 8rpx solid $dim-wealth; }
  210. .wish-card.approved,
  211. .wish-card.exchanging { border-left: 8rpx solid $status-info; }
  212. .wish-card.fulfilled { border-left: 8rpx solid $facade-violet; }
  213. .wish-header {
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: flex-start;
  217. margin-bottom: 20rpx;
  218. }
  219. .wish-title {
  220. font-size: calc(36rpx * var(--font-scale, 1));
  221. font-weight: bold;
  222. color: $facade-text-strong;
  223. flex: 1;
  224. }
  225. .wish-status {
  226. font-size: calc(24rpx * var(--font-scale, 1));
  227. padding: 8rpx 20rpx;
  228. border-radius: 24rpx;
  229. background: $facade-fill;
  230. color: $facade-text-body;
  231. }
  232. .wish-status.active { background: $status-success-soft; color: $status-success-deep; }
  233. .wish-status.pending_exchange { background: $status-warning-soft; color: $status-warning-deep; }
  234. .wish-status.exchanging { background: $status-info-soft; color: $status-info-deep; }
  235. .wish-status.fulfilled { background: $violet-tint-100; color: $facade-violet-deep; }
  236. .category-tag {
  237. font-size: calc(24rpx * var(--font-scale, 1));
  238. color: $facade-text-body;
  239. background: $facade-fill-2;
  240. padding: 6rpx 16rpx;
  241. border-radius: 16rpx;
  242. display: inline-block;
  243. margin-bottom: 20rpx;
  244. }
  245. .wish-desc {
  246. font-size: calc(28rpx * var(--font-scale, 1));
  247. color: $facade-text-body;
  248. line-height: 1.6;
  249. margin-bottom: 20rpx;
  250. padding: 20rpx;
  251. background: $facade-fill-ghost-2;
  252. border-radius: 16rpx;
  253. }
  254. .points-section {
  255. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  256. border-radius: 16rpx;
  257. padding: 25rpx;
  258. color: $app-surface;
  259. margin-bottom: 20rpx;
  260. }
  261. .points-label {
  262. font-size: calc(24rpx * var(--font-scale, 1));
  263. opacity: 0.9;
  264. }
  265. .points-value {
  266. margin-top: 10rpx;
  267. }
  268. .points-num {
  269. font-size: calc(48rpx * var(--font-scale, 1));
  270. font-weight: bold;
  271. }
  272. .points-unit {
  273. font-size: calc(24rpx * var(--font-scale, 1));
  274. margin-left: 5rpx;
  275. }
  276. .progress-section {
  277. margin-top: 20rpx;
  278. }
  279. .progress-bar {
  280. height: 12rpx;
  281. background: rgba(255,255,255,0.3);
  282. border-radius: 8rpx;
  283. overflow: hidden;
  284. }
  285. .progress-fill {
  286. height: 100%;
  287. background: $app-surface;
  288. border-radius: 8rpx;
  289. }
  290. .progress-text {
  291. font-size: calc(22rpx * var(--font-scale, 1));
  292. margin-top: 10rpx;
  293. display: block;
  294. }
  295. .time-info {
  296. margin-top: 20rpx;
  297. }
  298. .time-text {
  299. font-size: calc(24rpx * var(--font-scale, 1));
  300. color: $facade-text-muted;
  301. }
  302. /* 操作区域 */
  303. .action-section {
  304. padding: 20rpx;
  305. }
  306. .btn-primary {
  307. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  308. color: $app-surface;
  309. font-size: calc(32rpx * var(--font-scale, 1));
  310. padding: 24rpx;
  311. border-radius: 24rpx;
  312. margin-bottom: 20rpx;
  313. }
  314. .btn-disabled {
  315. background: $facade-gray-200;
  316. color: $facade-text-gray-400;
  317. font-size: calc(32rpx * var(--font-scale, 1));
  318. padding: 24rpx;
  319. border-radius: 24rpx;
  320. margin-bottom: 20rpx;
  321. }
  322. .btn-cancel {
  323. background: $app-surface;
  324. color: $facade-text-muted;
  325. font-size: calc(28rpx * var(--font-scale, 1));
  326. padding: 20rpx;
  327. border-radius: 24rpx;
  328. border: 1rpx solid $facade-border-soft;
  329. }
  330. .waiting-box,
  331. .fulfilled-box {
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. padding: 40rpx;
  336. background: $app-surface;
  337. border-radius: 24rpx;
  338. margin-bottom: 20rpx;
  339. }
  340. .waiting-icon,
  341. .fulfilled-icon {
  342. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  343. margin-bottom: 20rpx;
  344. }
  345. .waiting-text,
  346. .fulfilled-text {
  347. font-size: calc(30rpx * var(--font-scale, 1));
  348. color: $facade-text-strong;
  349. margin-bottom: 10rpx;
  350. }
  351. .fulfilled-time {
  352. font-size: calc(24rpx * var(--font-scale, 1));
  353. color: $facade-violet;
  354. }
  355. .loading {
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. height: 100vh;
  360. color: $facade-text-muted;
  361. }
  362. </style>