index.vue 13 KB

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