index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view class="container">
  3. <view v-if="hasFamily">
  4. <!-- 标签页切换 -->
  5. <view class="tabs">
  6. <view
  7. class="tab-item"
  8. :class="{ active: activeTab === 'pending' }"
  9. @click="activeTab = 'pending'"
  10. >
  11. 待处理
  12. <text class="badge" v-if="pendingCount > 0">{{ pendingCount }}</text>
  13. </view>
  14. <view
  15. class="tab-item"
  16. :class="{ active: activeTab === 'all' }"
  17. @click="activeTab = 'all'"
  18. >
  19. 全部心愿
  20. </view>
  21. </view>
  22. <!-- 待处理列表 -->
  23. <view class="wish-list" v-if="activeTab === 'pending'">
  24. <!-- 待定价 -->
  25. <view class="section" v-if="draftWishes.length > 0">
  26. <view class="section-title">📝 待定价</view>
  27. <view
  28. v-for="wish in draftWishes"
  29. :key="wish.id"
  30. class="wish-card"
  31. >
  32. <view class="wish-info">
  33. <text class="wish-child">{{ wish.childName }}</text>
  34. <text class="wish-title">{{ wish.title }}</text>
  35. <text class="wish-category" v-if="wish.category">{{ wish.category }}</text>
  36. </view>
  37. <view class="wish-actions">
  38. <button class="btn-price" @click="showPriceDialog(wish)">定价</button>
  39. <button class="btn-reject" @click="rejectWish(wish)">拒绝</button>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 待审批兑换 -->
  44. <view class="section" v-if="pendingExchangeWishes.length > 0">
  45. <view class="section-title">⏳ 待审批兑换</view>
  46. <view
  47. v-for="wish in pendingExchangeWishes"
  48. :key="wish.id"
  49. class="wish-card"
  50. >
  51. <view class="wish-info">
  52. <text class="wish-child">{{ wish.childName }}</text>
  53. <text class="wish-title">{{ wish.title }}</text>
  54. <text class="wish-points">{{ wish.pointsRequired }}积分</text>
  55. </view>
  56. <view class="wish-actions">
  57. <button class="btn-approve" @click="approveExchange(wish, true)">批准</button>
  58. <button class="btn-reject" @click="approveExchange(wish, false)">拒绝</button>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 待兑现 -->
  63. <view class="section" v-if="approvedWishes.length > 0">
  64. <view class="section-title">📦 待兑现</view>
  65. <view
  66. v-for="wish in approvedWishes"
  67. :key="wish.id"
  68. class="wish-card"
  69. >
  70. <view class="wish-info">
  71. <text class="wish-child">{{ wish.childName }}</text>
  72. <text class="wish-title">{{ wish.title }}</text>
  73. <text class="wish-points">已扣{{ wish.pointsRequired }}积分</text>
  74. </view>
  75. <view class="wish-actions">
  76. <button class="btn-fulfill" @click="markFulfilled(wish)">已购买</button>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 空状态 -->
  81. <view class="empty" v-if="pendingWishes.length === 0">
  82. <text class="empty-icon">✅</text>
  83. <text class="empty-text">暂无待处理心愿</text>
  84. </view>
  85. </view>
  86. <!-- 全部心愿列表 -->
  87. <view class="wish-list" v-if="activeTab === 'all'">
  88. <view
  89. v-for="wish in allWishes"
  90. :key="wish.id"
  91. class="wish-card"
  92. :class="wish.status"
  93. >
  94. <view class="wish-header">
  95. <view class="wish-info-left">
  96. <text class="wish-child">{{ wish.childName }}</text>
  97. <text class="wish-title">{{ wish.title }}</text>
  98. </view>
  99. <text class="wish-status" :class="wish.status">{{ wish.statusText }}</text>
  100. </view>
  101. <view class="wish-meta">
  102. <text class="wish-points" v-if="wish.pointsRequired">{{ wish.pointsRequired }}积分</text>
  103. <text class="wish-time">{{ wish.createdAt }}</text>
  104. </view>
  105. </view>
  106. <!-- 空状态 -->
  107. <view class="empty" v-if="allWishes.length === 0">
  108. <text class="empty-icon">🎁</text>
  109. <text class="empty-text">暂无心愿</text>
  110. </view>
  111. </view>
  112. <!-- 定价弹窗 -->
  113. <view class="modal-mask" v-if="priceDialogVisible" @click="priceDialogVisible = false">
  114. <view class="modal" @click.stop>
  115. <view class="modal-title">设置积分</view>
  116. <view class="modal-content">
  117. <text class="modal-wish-title">{{ currentWish && currentWish.title }}</text>
  118. <view class="input-row">
  119. <text class="inputLabel">所需积分:</text>
  120. <input
  121. type="number"
  122. v-model="priceValue"
  123. placeholder="请输入积分"
  124. class="price-input"
  125. />
  126. </view>
  127. </view>
  128. <view class="modal-btns">
  129. <button class="btn-cancel" @click="priceDialogVisible = false">取消</button>
  130. <button class="btn-confirm" @click="submitPrice">确定</button>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. <view v-else>
  136. <FamilyEmptyState type="card" />
  137. </view>
  138. </view>
  139. </template>
  140. <script>
  141. import {
  142. getPendingWishes,
  143. getWishes,
  144. setWishPrice,
  145. rejectWish,
  146. approveWishExchange,
  147. markWishFulfilled
  148. } from '../../../utils/api.js'
  149. export default {
  150. data() {
  151. return {
  152. activeTab: 'pending',
  153. memberId: '',
  154. childName: '',
  155. pendingWishes: [],
  156. allWishes: [],
  157. priceDialogVisible: false,
  158. currentWish: null,
  159. priceValue: ''
  160. }
  161. },
  162. computed: {
  163. hasFamily: function() {
  164. return this.$store.getters.hasFamily
  165. },
  166. pendingCount() {
  167. return this.pendingWishes.length
  168. },
  169. draftWishes() {
  170. return this.pendingWishes.filter(w => w.status === 'draft')
  171. },
  172. pendingExchangeWishes() {
  173. return this.pendingWishes.filter(w => w.status === 'pending_exchange')
  174. },
  175. approvedWishes() {
  176. return this.pendingWishes.filter(w => w.status === 'approved')
  177. }
  178. },
  179. onShow() {
  180. this.loadData()
  181. },
  182. onLoad(options) {
  183. if (options.memberId) {
  184. this.memberId = options.memberId
  185. this.childName = options.childName || '该孩子'
  186. }
  187. },
  188. methods: {
  189. async loadData() {
  190. try {
  191. // 获取待处理列表
  192. const pendingRes = await getPendingWishes()
  193. let wishes = pendingRes.data || []
  194. // 如果指定了 memberId,按孩子过滤
  195. if (this.memberId) {
  196. wishes = wishes.filter(w => String(w.memberId) === String(this.memberId))
  197. }
  198. this.pendingWishes = wishes
  199. // 获取全部心愿
  200. const allRes = await getWishes({})
  201. let allWishes = allRes.data || []
  202. if (this.memberId) {
  203. allWishes = allWishes.filter(w => String(w.memberId) === String(this.memberId))
  204. }
  205. this.allWishes = allWishes
  206. } catch (e) {
  207. console.error('加载数据失败', e)
  208. uni.showToast({ title: '加载失败', icon: 'none' })
  209. }
  210. },
  211. showPriceDialog(wish) {
  212. this.currentWish = wish
  213. this.priceValue = ''
  214. this.priceDialogVisible = true
  215. },
  216. async submitPrice() {
  217. const points = parseInt(this.priceValue)
  218. if (!points || points <= 0) {
  219. uni.showToast({ title: '请输入有效积分', icon: 'none' })
  220. return
  221. }
  222. try {
  223. await setWishPrice(this.currentWish.id, points)
  224. uni.showToast({ title: '定价成功', icon: 'success' })
  225. this.priceDialogVisible = false
  226. this.loadData()
  227. } catch (e) {
  228. uni.showToast({ title: e.message || '定价失败', icon: 'none' })
  229. }
  230. },
  231. async rejectWish(wish) {
  232. uni.showModal({
  233. title: '拒绝心愿',
  234. content: `确定要拒绝"${wish.title}"吗?`,
  235. success: async (res) => {
  236. if (res.confirm) {
  237. try {
  238. await rejectWish(wish.id, '不合适')
  239. uni.showToast({ title: '已拒绝', icon: 'success' })
  240. this.loadData()
  241. } catch (e) {
  242. uni.showToast({ title: '操作失败', icon: 'none' })
  243. }
  244. }
  245. }
  246. })
  247. },
  248. async approveExchange(wish, approved) {
  249. const action = approved ? '批准' : '拒绝'
  250. uni.showModal({
  251. title: `${action}兑换`,
  252. content: `确定要${action}"${wish.title}"的兑换申请吗?`,
  253. success: async (res) => {
  254. if (res.confirm) {
  255. try {
  256. await approveWishExchange(wish.id, approved)
  257. uni.showToast({ title: `已${action}`, icon: 'success' })
  258. this.loadData()
  259. } catch (e) {
  260. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  261. }
  262. }
  263. }
  264. })
  265. },
  266. async markFulfilled(wish) {
  267. uni.showModal({
  268. title: '标记已购买',
  269. content: `确定已购买"${wish.title}"吗?`,
  270. success: async (res) => {
  271. if (res.confirm) {
  272. try {
  273. await markWishFulfilled(wish.id)
  274. uni.showToast({ title: '已标记', icon: 'success' })
  275. this.loadData()
  276. } catch (e) {
  277. uni.showToast({ title: '操作失败', icon: 'none' })
  278. }
  279. }
  280. }
  281. })
  282. }
  283. }
  284. }
  285. </script>
  286. <style scoped>
  287. .container {
  288. padding: 30rpx;
  289. min-height: 100vh;
  290. background: #f5f5f5;
  291. }
  292. /* 标签页 */
  293. .tabs {
  294. display: flex;
  295. background: #fff;
  296. border-radius: 50rpx;
  297. padding: 8rpx;
  298. margin-bottom: 30rpx;
  299. }
  300. .tab-item {
  301. flex: 1;
  302. text-align: center;
  303. padding: 16rpx;
  304. border-radius: 40rpx;
  305. font-size: 28rpx;
  306. color: #666;
  307. position: relative;
  308. }
  309. .tab-item.active {
  310. background: linear-gradient(135deg, #F97316, #FB923C);
  311. color: #fff;
  312. }
  313. .badge {
  314. position: absolute;
  315. top: 4rpx;
  316. right: 20rpx;
  317. background: #F97316;
  318. color: #fff;
  319. font-size: 20rpx;
  320. padding: 2rpx 10rpx;
  321. border-radius: 20rpx;
  322. min-width: 30rpx;
  323. text-align: center;
  324. }
  325. .tab-item.active .badge {
  326. background: #fff;
  327. color: #F97316;
  328. }
  329. /* 分组 */
  330. .section {
  331. margin-bottom: 30rpx;
  332. }
  333. .section-title {
  334. font-size: 28rpx;
  335. color: #666;
  336. margin-bottom: 15rpx;
  337. padding-left: 10rpx;
  338. }
  339. /* 心愿卡片 */
  340. .wish-card {
  341. background: #fff;
  342. border-radius: 15rpx;
  343. padding: 25rpx;
  344. margin-bottom: 15rpx;
  345. }
  346. .wish-header {
  347. display: flex;
  348. justify-content: space-between;
  349. align-items: flex-start;
  350. }
  351. .wish-info {
  352. flex: 1;
  353. }
  354. .wish-info-left {
  355. flex: 1;
  356. }
  357. .wish-child {
  358. font-size: 24rpx;
  359. color: #F97316;
  360. background: #FFF5F5;
  361. padding: 4rpx 12rpx;
  362. border-radius: 10rpx;
  363. margin-right: 10rpx;
  364. }
  365. .wish-title {
  366. font-size: 30rpx;
  367. color: #333;
  368. font-weight: bold;
  369. margin-left: 10rpx;
  370. }
  371. .wish-category {
  372. font-size: 24rpx;
  373. color: #666;
  374. background: #f5f5f5;
  375. padding: 4rpx 12rpx;
  376. border-radius: 10rpx;
  377. margin-left: 10rpx;
  378. }
  379. .wish-meta {
  380. display: flex;
  381. justify-content: space-between;
  382. margin-top: 15rpx;
  383. }
  384. .wish-points {
  385. font-size: 26rpx;
  386. color: #F97316;
  387. font-weight: bold;
  388. }
  389. .wish-time {
  390. font-size: 24rpx;
  391. color: #999;
  392. }
  393. .wish-status {
  394. font-size: 24rpx;
  395. padding: 6rpx 16rpx;
  396. border-radius: 20rpx;
  397. background: #f0f0f0;
  398. color: #666;
  399. }
  400. .wish-status.active { background: #D1FAE5; color: #059669; }
  401. .wish-status.pending_exchange { background: #FEF3C7; color: #D97706; }
  402. .wish-status.approved { background: #DBEAFE; color: #2563EB; }
  403. .wish-status.exchanging { background: #DBEAFE; color: #2563EB; }
  404. .wish-status.fulfilled { background: #EDE9FE; color: #7C3AED; }
  405. .wish-actions {
  406. display: flex;
  407. gap: 15rpx;
  408. margin-top: 20rpx;
  409. }
  410. .btn-price, .btn-approve, .btn-fulfill {
  411. background: linear-gradient(135deg, #F97316, #FB923C);
  412. color: #fff;
  413. font-size: 26rpx;
  414. padding: 12rpx 24rpx;
  415. border-radius: 30rpx;
  416. margin: 0;
  417. }
  418. .btn-reject {
  419. background: #fff;
  420. color: #999;
  421. border: 1rpx solid #ddd;
  422. font-size: 26rpx;
  423. padding: 12rpx 24rpx;
  424. border-radius: 30rpx;
  425. margin: 0;
  426. }
  427. /* 空状态 */
  428. .empty {
  429. display: flex;
  430. flex-direction: column;
  431. align-items: center;
  432. padding: 80rpx;
  433. }
  434. .empty-icon {
  435. font-size: 80rpx;
  436. margin-bottom: 20rpx;
  437. }
  438. .empty-text {
  439. font-size: 28rpx;
  440. color: #999;
  441. }
  442. /* 弹窗 */
  443. .modal-mask {
  444. position: fixed;
  445. top: 0;
  446. left: 0;
  447. right: 0;
  448. bottom: 0;
  449. background: rgba(0,0,0,0.5);
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. }
  454. .modal {
  455. background: #fff;
  456. border-radius: 20rpx;
  457. padding: 40rpx;
  458. width: 80%;
  459. }
  460. .modal-title {
  461. font-size: 32rpx;
  462. font-weight: bold;
  463. text-align: center;
  464. margin-bottom: 30rpx;
  465. }
  466. .modal-content {
  467. margin-bottom: 30rpx;
  468. }
  469. .modal-wish-title {
  470. font-size: 28rpx;
  471. color: #333;
  472. display: block;
  473. text-align: center;
  474. margin-bottom: 30rpx;
  475. }
  476. .input-row {
  477. display: flex;
  478. align-items: center;
  479. }
  480. .inputLabel {
  481. font-size: 28rpx;
  482. color: #333;
  483. }
  484. .price-input {
  485. flex: 1;
  486. background: #f5f5f5;
  487. border-radius: 15rpx;
  488. padding: 20rpx;
  489. font-size: 28rpx;
  490. }
  491. .modal-btns {
  492. display: flex;
  493. gap: 20rpx;
  494. }
  495. .btn-cancel, .btn-confirm {
  496. flex: 1;
  497. padding: 20rpx;
  498. border-radius: 40rpx;
  499. font-size: 28rpx;
  500. }
  501. .btn-cancel {
  502. background: #f5f5f5;
  503. color: #666;
  504. }
  505. .btn-confirm {
  506. background: linear-gradient(135deg, #F97316, #FB923C);
  507. color: #fff;
  508. }
  509. </style>