index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. familyId: '',
  149. childId: '',
  150. childName: '',
  151. pendingWishes: [],
  152. allWishes: [],
  153. priceDialogVisible: false,
  154. currentWish: null,
  155. priceValue: ''
  156. }
  157. },
  158. computed: {
  159. pendingCount() {
  160. return this.pendingWishes.length
  161. },
  162. draftWishes() {
  163. return this.pendingWishes.filter(w => w.status === 'draft')
  164. },
  165. pendingExchangeWishes() {
  166. return this.pendingWishes.filter(w => w.status === 'pending_exchange')
  167. },
  168. approvedWishes() {
  169. return this.pendingWishes.filter(w => w.status === 'approved')
  170. }
  171. },
  172. onShow() {
  173. this.familyId = uni.getStorageSync('familyId')
  174. this.loadData()
  175. },
  176. onLoad(options) {
  177. if (options.childId) {
  178. this.childId = options.childId
  179. this.childName = options.childName || '该孩子'
  180. }
  181. },
  182. methods: {
  183. async loadData() {
  184. try {
  185. // 获取待处理列表
  186. const pendingRes = await getPendingWishes(this.familyId)
  187. let wishes = pendingRes.data || []
  188. // 如果指定了 childId,按孩子过滤
  189. if (this.childId) {
  190. wishes = wishes.filter(w => String(w.childId) === String(this.childId))
  191. }
  192. this.pendingWishes = wishes
  193. // 获取全部心愿
  194. const allRes = await getWishes({ familyId: this.familyId })
  195. let allWishes = allRes.data || []
  196. if (this.childId) {
  197. allWishes = allWishes.filter(w => String(w.childId) === String(this.childId))
  198. }
  199. this.allWishes = allWishes
  200. } catch (e) {
  201. console.error('加载数据失败', e)
  202. uni.showToast({ title: '加载失败', icon: 'none' })
  203. }
  204. },
  205. showPriceDialog(wish) {
  206. this.currentWish = wish
  207. this.priceValue = ''
  208. this.priceDialogVisible = true
  209. },
  210. async submitPrice() {
  211. const points = parseInt(this.priceValue)
  212. if (!points || points <= 0) {
  213. uni.showToast({ title: '请输入有效积分', icon: 'none' })
  214. return
  215. }
  216. try {
  217. await setWishPrice(this.currentWish.id, points)
  218. uni.showToast({ title: '定价成功', icon: 'success' })
  219. this.priceDialogVisible = false
  220. this.loadData()
  221. } catch (e) {
  222. uni.showToast({ title: e.message || '定价失败', icon: 'none' })
  223. }
  224. },
  225. async rejectWish(wish) {
  226. uni.showModal({
  227. title: '拒绝心愿',
  228. content: `确定要拒绝"${wish.title}"吗?`,
  229. success: async (res) => {
  230. if (res.confirm) {
  231. try {
  232. await rejectWish(wish.id, '不合适')
  233. uni.showToast({ title: '已拒绝', icon: 'success' })
  234. this.loadData()
  235. } catch (e) {
  236. uni.showToast({ title: '操作失败', icon: 'none' })
  237. }
  238. }
  239. }
  240. })
  241. },
  242. async approveExchange(wish, approved) {
  243. const action = approved ? '批准' : '拒绝'
  244. uni.showModal({
  245. title: `${action}兑换`,
  246. content: `确定要${action}"${wish.title}"的兑换申请吗?`,
  247. success: async (res) => {
  248. if (res.confirm) {
  249. try {
  250. await approveWishExchange(wish.id, approved)
  251. uni.showToast({ title: `已${action}`, icon: 'success' })
  252. this.loadData()
  253. } catch (e) {
  254. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  255. }
  256. }
  257. }
  258. })
  259. },
  260. async markFulfilled(wish) {
  261. uni.showModal({
  262. title: '标记已购买',
  263. content: `确定已购买"${wish.title}"吗?`,
  264. success: async (res) => {
  265. if (res.confirm) {
  266. try {
  267. await markWishFulfilled(wish.id)
  268. uni.showToast({ title: '已标记', icon: 'success' })
  269. this.loadData()
  270. } catch (e) {
  271. uni.showToast({ title: '操作失败', icon: 'none' })
  272. }
  273. }
  274. }
  275. })
  276. }
  277. }
  278. }
  279. </script>
  280. <style scoped>
  281. .container {
  282. padding: 30rpx;
  283. min-height: 100vh;
  284. background: #f5f5f5;
  285. }
  286. /* 标签页 */
  287. .tabs {
  288. display: flex;
  289. background: #fff;
  290. border-radius: 50rpx;
  291. padding: 8rpx;
  292. margin-bottom: 30rpx;
  293. }
  294. .tab-item {
  295. flex: 1;
  296. text-align: center;
  297. padding: 16rpx;
  298. border-radius: 40rpx;
  299. font-size: 28rpx;
  300. color: #666;
  301. position: relative;
  302. }
  303. .tab-item.active {
  304. background: linear-gradient(135deg, #F97316, #FB923C);
  305. color: #fff;
  306. }
  307. .badge {
  308. position: absolute;
  309. top: 4rpx;
  310. right: 20rpx;
  311. background: #F97316;
  312. color: #fff;
  313. font-size: 20rpx;
  314. padding: 2rpx 10rpx;
  315. border-radius: 20rpx;
  316. min-width: 30rpx;
  317. text-align: center;
  318. }
  319. .tab-item.active .badge {
  320. background: #fff;
  321. color: #F97316;
  322. }
  323. /* 分组 */
  324. .section {
  325. margin-bottom: 30rpx;
  326. }
  327. .section-title {
  328. font-size: 28rpx;
  329. color: #666;
  330. margin-bottom: 15rpx;
  331. padding-left: 10rpx;
  332. }
  333. /* 心愿卡片 */
  334. .wish-card {
  335. background: #fff;
  336. border-radius: 15rpx;
  337. padding: 25rpx;
  338. margin-bottom: 15rpx;
  339. }
  340. .wish-header {
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: flex-start;
  344. }
  345. .wish-info {
  346. flex: 1;
  347. }
  348. .wish-info-left {
  349. flex: 1;
  350. }
  351. .wish-child {
  352. font-size: 24rpx;
  353. color: #F97316;
  354. background: #FFF5F5;
  355. padding: 4rpx 12rpx;
  356. border-radius: 10rpx;
  357. margin-right: 10rpx;
  358. }
  359. .wish-title {
  360. font-size: 30rpx;
  361. color: #333;
  362. font-weight: bold;
  363. margin-left: 10rpx;
  364. }
  365. .wish-category {
  366. font-size: 24rpx;
  367. color: #666;
  368. background: #f5f5f5;
  369. padding: 4rpx 12rpx;
  370. border-radius: 10rpx;
  371. margin-left: 10rpx;
  372. }
  373. .wish-meta {
  374. display: flex;
  375. justify-content: space-between;
  376. margin-top: 15rpx;
  377. }
  378. .wish-points {
  379. font-size: 26rpx;
  380. color: #F97316;
  381. font-weight: bold;
  382. }
  383. .wish-time {
  384. font-size: 24rpx;
  385. color: #999;
  386. }
  387. .wish-status {
  388. font-size: 24rpx;
  389. padding: 6rpx 16rpx;
  390. border-radius: 20rpx;
  391. background: #f0f0f0;
  392. color: #666;
  393. }
  394. .wish-status.active { background: #D1FAE5; color: #059669; }
  395. .wish-status.pending_exchange { background: #FEF3C7; color: #D97706; }
  396. .wish-status.approved { background: #DBEAFE; color: #2563EB; }
  397. .wish-status.exchanging { background: #DBEAFE; color: #2563EB; }
  398. .wish-status.fulfilled { background: #EDE9FE; color: #7C3AED; }
  399. .wish-actions {
  400. display: flex;
  401. gap: 15rpx;
  402. margin-top: 20rpx;
  403. }
  404. .btn-price, .btn-approve, .btn-fulfill {
  405. background: linear-gradient(135deg, #F97316, #FB923C);
  406. color: #fff;
  407. font-size: 26rpx;
  408. padding: 12rpx 24rpx;
  409. border-radius: 30rpx;
  410. margin: 0;
  411. }
  412. .btn-reject {
  413. background: #fff;
  414. color: #999;
  415. border: 1rpx solid #ddd;
  416. font-size: 26rpx;
  417. padding: 12rpx 24rpx;
  418. border-radius: 30rpx;
  419. margin: 0;
  420. }
  421. /* 空状态 */
  422. .empty {
  423. display: flex;
  424. flex-direction: column;
  425. align-items: center;
  426. padding: 80rpx;
  427. }
  428. .empty-icon {
  429. font-size: 80rpx;
  430. margin-bottom: 20rpx;
  431. }
  432. .empty-text {
  433. font-size: 28rpx;
  434. color: #999;
  435. }
  436. /* 弹窗 */
  437. .modal-mask {
  438. position: fixed;
  439. top: 0;
  440. left: 0;
  441. right: 0;
  442. bottom: 0;
  443. background: rgba(0,0,0,0.5);
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. }
  448. .modal {
  449. background: #fff;
  450. border-radius: 20rpx;
  451. padding: 40rpx;
  452. width: 80%;
  453. }
  454. .modal-title {
  455. font-size: 32rpx;
  456. font-weight: bold;
  457. text-align: center;
  458. margin-bottom: 30rpx;
  459. }
  460. .modal-content {
  461. margin-bottom: 30rpx;
  462. }
  463. .modal-wish-title {
  464. font-size: 28rpx;
  465. color: #333;
  466. display: block;
  467. text-align: center;
  468. margin-bottom: 30rpx;
  469. }
  470. .input-row {
  471. display: flex;
  472. align-items: center;
  473. }
  474. .inputLabel {
  475. font-size: 28rpx;
  476. color: #333;
  477. }
  478. .price-input {
  479. flex: 1;
  480. background: #f5f5f5;
  481. border-radius: 15rpx;
  482. padding: 20rpx;
  483. font-size: 28rpx;
  484. }
  485. .modal-btns {
  486. display: flex;
  487. gap: 20rpx;
  488. }
  489. .btn-cancel, .btn-confirm {
  490. flex: 1;
  491. padding: 20rpx;
  492. border-radius: 40rpx;
  493. font-size: 28rpx;
  494. }
  495. .btn-cancel {
  496. background: #f5f5f5;
  497. color: #666;
  498. }
  499. .btn-confirm {
  500. background: linear-gradient(135deg, #F97316, #FB923C);
  501. color: #fff;
  502. }
  503. </style>