index.vue 14 KB

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