Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

722 рядки
15 KiB

  1. <template>
  2. <view class="page">
  3. <view class="wrap">
  4. <view class="wallet-card">
  5. <view class="wallet-copy">
  6. <text class="wallet-kicker">我的点数</text>
  7. <view class="wallet-main">
  8. <view class="balance-line">
  9. <text class="balance-number">{{ balanceText }}</text>
  10. <text v-if="balanceUnit" class="balance-unit">{{ balanceUnit }}</text>
  11. </view>
  12. <view class="recharge-action" @click="goRecharge">充值</view>
  13. </view>
  14. </view>
  15. <view class="wallet-stats">
  16. <view v-for="item in summaryStats" :key="item.key" class="stat-item">
  17. <text class="stat-value" :class="item.key">{{ item.value }}</text>
  18. <text class="stat-label">{{ item.label }}</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="filter-panel">
  23. <view
  24. v-for="item in tabs"
  25. :key="item.key"
  26. class="filter-item"
  27. :class="{ active: activeTab === item.key }"
  28. @click="changeTab(item.key)"
  29. >
  30. <text class="filter-name">{{ item.name }}</text>
  31. <text class="filter-count">{{ tabCounts[item.key] || 0 }}条</text>
  32. </view>
  33. </view>
  34. <view class="list-head">
  35. <text class="list-title">流水明细</text>
  36. <text class="list-sub">{{ activeTabName }}</text>
  37. </view>
  38. <view v-if="list.length" class="ledger-panel">
  39. <view v-for="item in list" :key="item.id" class="ledger-row">
  40. <view class="type-mark" :class="item.type">
  41. <text>{{ getTypeMark(item.type) }}</text>
  42. </view>
  43. <view class="ledger-main">
  44. <view class="title-row">
  45. <text class="ledger-title">{{ item.title }}</text>
  46. <text class="ledger-status">已完成</text>
  47. </view>
  48. <text class="ledger-desc">{{ item.desc }}</text>
  49. <view class="ledger-meta">
  50. <text class="ledger-type" :class="item.type">{{ item.type_text }}</text>
  51. <text>{{ item.time }}</text>
  52. </view>
  53. <!-- 充值流水带上订单号,方便对账 / 找客服核单,点一下可复制 -->
  54. <view v-if="orderNo(item)" class="ledger-order" @click="copyOrderNo(orderNo(item))">
  55. <text class="ledger-order-text">订单号 {{ orderNo(item) }}</text>
  56. <text class="ledger-order-copy">复制</text>
  57. </view>
  58. </view>
  59. <text class="ledger-amount" :class="item.amount > 0 ? 'plus' : 'minus'">
  60. {{ formatAmount(item.amount) }}
  61. </text>
  62. </view>
  63. </view>
  64. <view v-if="!list.length && !loading" class="empty-state">
  65. <view class="empty-icon">账</view>
  66. <text class="empty-title">暂无账单记录</text>
  67. <text class="empty-desc">{{ activeTab === 'all' ? '充值或创作后,这里会展示点数变化。' : '当前分类还没有记录。' }}</text>
  68. </view>
  69. <view v-if="loading" class="loading">{{ list.length ? '加载更多...' : '加载中...' }}</view>
  70. <view v-if="list.length && list.length >= total && !loading" class="end-text">没有更多了</view>
  71. </view>
  72. </view>
  73. </template>
  74. <script setup>
  75. import { computed, ref } from 'vue'
  76. import { onLoad, onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  77. import { pointApi } from '@/api/index.js'
  78. import { useUserStore } from '@/store/user.js'
  79. import { useApp } from '@/utils/useApp.js'
  80. const userStore = useUserStore()
  81. const { toast } = useApp()
  82. const activeTab = ref('all')
  83. const list = ref([])
  84. const page = ref(1)
  85. const pageSize = 10
  86. const total = ref(0)
  87. const loading = ref(false)
  88. const refreshing = ref(false)
  89. const balance = ref({ points: 0, total_recharge: 0, total_consume: 0 })
  90. const summary = ref({
  91. recharge: 0,
  92. consume: 0,
  93. reward: 0,
  94. refund: 0,
  95. adjust: 0,
  96. counts: {
  97. all: 0,
  98. recharge: 0,
  99. consume: 0,
  100. reward: 0,
  101. other: 0
  102. }
  103. })
  104. let firstShow = true
  105. const tabs = [
  106. { key: 'all', name: '全部' },
  107. { key: 'recharge', name: '充值' },
  108. { key: 'consume', name: '消费' },
  109. { key: 'reward', name: '奖励' },
  110. { key: 'other', name: '其他' }
  111. ]
  112. const typeMark = {
  113. all: '',
  114. recharge: '+',
  115. consume: '-',
  116. reward: '奖',
  117. refund: '退',
  118. adjust: '调'
  119. }
  120. const balanceText = computed(() => {
  121. const points = balance.value.points !== undefined ? balance.value.points : userStore.balance
  122. return Number(points) < 0 ? '不限' : String(Number(points) || 0)
  123. })
  124. const balanceUnit = computed(() => {
  125. return ['不限', '无限'].includes(String(balanceText.value)) ? '' : '点'
  126. })
  127. const tabCounts = computed(() => {
  128. return summary.value.counts || {}
  129. })
  130. const activeTabName = computed(() => {
  131. const item = tabs.find((tab) => tab.key === activeTab.value)
  132. return item ? `${item.name}记录` : '全部记录'
  133. })
  134. const summaryStats = computed(() => {
  135. return [
  136. { key: 'recharge', label: '累计充值', value: formatSigned(summary.value.recharge, true) },
  137. { key: 'consume', label: '累计消费', value: summary.value.consume ? `-${summary.value.consume}` : '0' },
  138. { key: 'reward', label: '奖励获得', value: formatSigned(summary.value.reward, true) }
  139. ]
  140. })
  141. onLoad((options = {}) => {
  142. if (options.type && tabs.some((item) => item.key === options.type)) {
  143. activeTab.value = options.type
  144. }
  145. refreshSilent()
  146. })
  147. onShow(() => {
  148. if (firstShow) {
  149. firstShow = false
  150. return
  151. }
  152. refreshSilent()
  153. })
  154. onPullDownRefresh(() => {
  155. refreshing.value = true
  156. refreshSilent()
  157. })
  158. onReachBottom(() => loadMore())
  159. async function fetchList(reset = false) {
  160. if (loading.value) {
  161. if (refreshing.value) uni.stopPullDownRefresh()
  162. return
  163. }
  164. loading.value = true
  165. if (reset) page.value = 1
  166. try {
  167. const res = await pointApi.getLogList({
  168. type: activeTab.value,
  169. page_no: page.value,
  170. page_size: pageSize
  171. })
  172. const rows = res.list || []
  173. const data = res.data || {}
  174. list.value = reset ? rows : list.value.concat(rows)
  175. total.value = Number(data.total || rows.length)
  176. setBalance(data.balance || {})
  177. summary.value = normalizeSummary(data.summary || {})
  178. } catch (e) {
  179. toast(e.msg || '账单加载失败')
  180. } finally {
  181. loading.value = false
  182. refreshing.value = false
  183. uni.stopPullDownRefresh()
  184. }
  185. }
  186. function refreshSilent() {
  187. fetchList(true)
  188. }
  189. function loadMore() {
  190. if (loading.value || list.value.length >= total.value) return
  191. page.value += 1
  192. fetchList()
  193. }
  194. function changeTab(key) {
  195. if (activeTab.value === key) return
  196. activeTab.value = key
  197. refreshSilent()
  198. }
  199. function normalizeSummary(data = {}) {
  200. const counts = Object.assign({
  201. all: 0,
  202. recharge: 0,
  203. consume: 0,
  204. reward: 0,
  205. other: 0
  206. }, data.counts || {})
  207. Object.keys(counts).forEach((key) => {
  208. counts[key] = Number(counts[key] || 0)
  209. })
  210. return {
  211. recharge: Number(data.recharge || 0),
  212. consume: Number(data.consume || 0),
  213. reward: Number(data.reward || 0),
  214. refund: Number(data.refund || 0),
  215. adjust: Number(data.adjust || 0),
  216. counts
  217. }
  218. }
  219. function setBalance(data = {}) {
  220. balance.value = data
  221. if (data.points !== undefined || data.point_balance !== undefined) {
  222. userStore.balance = Number(data.points !== undefined ? data.points : data.point_balance) || 0
  223. userStore.balanceDetail = data
  224. }
  225. }
  226. function formatSigned(value, plus = false) {
  227. const num = Number(value || 0)
  228. if (num > 0 && plus) return `+${num}`
  229. return String(num)
  230. }
  231. function formatAmount(value) {
  232. const num = Number(value || 0)
  233. return num > 0 ? `+${num}` : String(num)
  234. }
  235. /**
  236. * 充值流水的订单号。
  237. * 后端 point_log.biz_no 在充值时存的就是 point_order.order_no(消费存的是计费流水号,不展示)。
  238. */
  239. function orderNo(item) {
  240. if (!item || item.type !== 'recharge') return ''
  241. return String(item.biz_no || '').trim()
  242. }
  243. function copyOrderNo(value) {
  244. if (!value) return
  245. uni.setClipboardData({
  246. data: value,
  247. success: () => toast('订单号已复制'),
  248. fail: () => toast('复制失败,请长按选择')
  249. })
  250. }
  251. function getTypeMark(type) {
  252. return typeMark[type] || '记'
  253. }
  254. function goRecharge() {
  255. uni.navigateTo({ url: '/pages/recharge/recharge' })
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .page {
  260. min-height: 100vh;
  261. background: #f3f7fb;
  262. }
  263. .wrap {
  264. padding: 30rpx 30rpx calc(44rpx + env(safe-area-inset-bottom));
  265. box-sizing: border-box;
  266. }
  267. .wallet-card {
  268. position: relative;
  269. min-height: 308rpx;
  270. padding: 34rpx 32rpx 26rpx;
  271. border-radius: 30rpx;
  272. color: #ffffff;
  273. background: linear-gradient(135deg, #1167e8 0%, #0b8cff 58%, #41c7ff 100%);
  274. box-shadow: 0 18rpx 40rpx rgba(11, 140, 255, 0.22);
  275. overflow: hidden;
  276. box-sizing: border-box;
  277. }
  278. .wallet-card::before {
  279. content: '';
  280. position: absolute;
  281. right: -96rpx;
  282. top: -130rpx;
  283. width: 330rpx;
  284. height: 330rpx;
  285. border-radius: 50%;
  286. background: rgba(255, 255, 255, 0.16);
  287. }
  288. .wallet-card::after {
  289. display: none;
  290. }
  291. .wallet-copy,
  292. .wallet-stats {
  293. position: relative;
  294. z-index: 1;
  295. }
  296. .wallet-kicker {
  297. display: block;
  298. color: rgba(255, 255, 255, 0.74);
  299. font-size: 24rpx;
  300. font-weight: 800;
  301. line-height: 1;
  302. }
  303. .wallet-main {
  304. margin-top: 20rpx;
  305. display: flex;
  306. align-items: center;
  307. justify-content: space-between;
  308. gap: 24rpx;
  309. }
  310. .balance-line {
  311. min-width: 0;
  312. display: flex;
  313. align-items: flex-end;
  314. }
  315. .balance-number {
  316. color: #ffffff;
  317. font-size: 70rpx;
  318. font-weight: 900;
  319. line-height: 0.95;
  320. }
  321. .balance-unit {
  322. margin-left: 10rpx;
  323. margin-bottom: 8rpx;
  324. color: rgba(255, 255, 255, 0.78);
  325. font-size: 26rpx;
  326. font-weight: 800;
  327. }
  328. .recharge-action {
  329. height: 68rpx;
  330. min-width: 136rpx;
  331. padding: 0 30rpx;
  332. border-radius: 999rpx;
  333. color: #0b74ea;
  334. background: #ffffff;
  335. font-size: 27rpx;
  336. font-weight: 900;
  337. line-height: 68rpx;
  338. text-align: center;
  339. box-sizing: border-box;
  340. flex-shrink: 0;
  341. }
  342. .wallet-stats {
  343. margin-top: 34rpx;
  344. padding-top: 28rpx;
  345. border-top: 1rpx solid rgba(255, 255, 255, 0.22);
  346. display: grid;
  347. grid-template-columns: repeat(3, minmax(0, 1fr));
  348. gap: 0;
  349. }
  350. .stat-item {
  351. min-width: 0;
  352. display: flex;
  353. min-height: 76rpx;
  354. flex-direction: column;
  355. align-items: center;
  356. justify-content: center;
  357. text-align: center;
  358. }
  359. .stat-value {
  360. display: block;
  361. color: #ffffff;
  362. font-size: 30rpx;
  363. font-weight: 900;
  364. line-height: 1.08;
  365. }
  366. .stat-value.consume {
  367. color: #ffe2c7;
  368. }
  369. .stat-label {
  370. display: block;
  371. margin-top: 8rpx;
  372. color: rgba(255, 255, 255, 0.68);
  373. font-size: 22rpx;
  374. line-height: 1.15;
  375. }
  376. .filter-panel {
  377. margin-top: 24rpx;
  378. padding: 8rpx;
  379. border-radius: 24rpx;
  380. background: #ffffff;
  381. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  382. display: grid;
  383. grid-template-columns: repeat(5, minmax(0, 1fr));
  384. gap: 8rpx;
  385. }
  386. .filter-item {
  387. height: 88rpx;
  388. border-radius: 20rpx;
  389. display: flex;
  390. flex-direction: column;
  391. align-items: center;
  392. justify-content: center;
  393. color: #7f8896;
  394. }
  395. .filter-item.active {
  396. color: #0b8cff;
  397. background: #eef7ff;
  398. }
  399. .filter-name {
  400. font-size: 27rpx;
  401. font-weight: 900;
  402. line-height: 1;
  403. }
  404. .filter-count {
  405. margin-top: 8rpx;
  406. font-size: 20rpx;
  407. font-weight: 700;
  408. line-height: 1;
  409. opacity: 0.72;
  410. }
  411. .list-head {
  412. margin-top: 30rpx;
  413. margin-bottom: 16rpx;
  414. display: flex;
  415. align-items: center;
  416. justify-content: space-between;
  417. }
  418. .list-title {
  419. color: #172033;
  420. font-size: 32rpx;
  421. font-weight: 900;
  422. }
  423. .list-sub {
  424. color: #8a95a6;
  425. font-size: 24rpx;
  426. }
  427. .ledger-panel {
  428. border-radius: 26rpx;
  429. background: #ffffff;
  430. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  431. overflow: hidden;
  432. }
  433. .ledger-row {
  434. position: relative;
  435. min-height: 156rpx;
  436. padding: 26rpx 28rpx;
  437. display: flex;
  438. align-items: center;
  439. gap: 22rpx;
  440. box-sizing: border-box;
  441. }
  442. .ledger-row::after {
  443. content: '';
  444. position: absolute;
  445. left: 112rpx;
  446. right: 28rpx;
  447. bottom: 0;
  448. height: 1rpx;
  449. background: #edf2f7;
  450. }
  451. .ledger-row:last-child::after {
  452. display: none;
  453. }
  454. .type-mark {
  455. width: 62rpx;
  456. height: 62rpx;
  457. border-radius: 20rpx;
  458. display: flex;
  459. align-items: center;
  460. justify-content: center;
  461. font-size: 29rpx;
  462. font-weight: 900;
  463. flex-shrink: 0;
  464. }
  465. .type-mark.recharge {
  466. color: #0b8cff;
  467. background: #eef7ff;
  468. }
  469. .type-mark.consume {
  470. color: #ff681f;
  471. background: #fff4ec;
  472. }
  473. .type-mark.reward {
  474. color: #17a65a;
  475. background: #edfdf4;
  476. }
  477. .type-mark.refund,
  478. .type-mark.adjust {
  479. color: #7a5af8;
  480. background: #f3f0ff;
  481. }
  482. .ledger-main {
  483. min-width: 0;
  484. flex: 1;
  485. }
  486. .title-row {
  487. display: flex;
  488. align-items: center;
  489. gap: 14rpx;
  490. }
  491. .ledger-title {
  492. min-width: 0;
  493. color: #172033;
  494. font-size: 29rpx;
  495. font-weight: 900;
  496. line-height: 1.25;
  497. overflow: hidden;
  498. text-overflow: ellipsis;
  499. white-space: nowrap;
  500. }
  501. .ledger-status {
  502. height: 32rpx;
  503. padding: 0 12rpx;
  504. border-radius: 999rpx;
  505. color: #17a65a;
  506. background: #edfdf4;
  507. font-size: 19rpx;
  508. font-weight: 800;
  509. line-height: 32rpx;
  510. flex-shrink: 0;
  511. }
  512. .ledger-desc {
  513. display: block;
  514. margin-top: 10rpx;
  515. color: #7f8896;
  516. font-size: 24rpx;
  517. line-height: 1.35;
  518. overflow: hidden;
  519. text-overflow: ellipsis;
  520. white-space: nowrap;
  521. }
  522. .ledger-meta {
  523. margin-top: 14rpx;
  524. display: flex;
  525. align-items: center;
  526. gap: 14rpx;
  527. color: #9aa4b2;
  528. font-size: 22rpx;
  529. }
  530. .ledger-order {
  531. margin-top: 10rpx;
  532. display: flex;
  533. align-items: center;
  534. gap: 10rpx;
  535. }
  536. .ledger-order-text {
  537. min-width: 0;
  538. flex: 1;
  539. color: #9aa4b2;
  540. font-size: 21rpx;
  541. overflow: hidden;
  542. white-space: nowrap;
  543. text-overflow: ellipsis;
  544. }
  545. .ledger-order-copy {
  546. flex-shrink: 0;
  547. color: #0b8cff;
  548. font-size: 21rpx;
  549. font-weight: 800;
  550. }
  551. .ledger-type {
  552. height: 34rpx;
  553. padding: 0 14rpx;
  554. border-radius: 999rpx;
  555. font-size: 20rpx;
  556. font-weight: 900;
  557. line-height: 34rpx;
  558. }
  559. .ledger-type.recharge {
  560. color: #0b8cff;
  561. background: #eef7ff;
  562. }
  563. .ledger-type.consume {
  564. color: #ff681f;
  565. background: #fff4ec;
  566. }
  567. .ledger-type.reward {
  568. color: #17a65a;
  569. background: #edfdf4;
  570. }
  571. .ledger-type.refund,
  572. .ledger-type.adjust {
  573. color: #7a5af8;
  574. background: #f3f0ff;
  575. }
  576. .ledger-amount {
  577. color: #172033;
  578. font-size: 34rpx;
  579. font-weight: 900;
  580. line-height: 1;
  581. flex-shrink: 0;
  582. }
  583. .ledger-amount.plus {
  584. color: #17a65a;
  585. }
  586. .ledger-amount.minus {
  587. color: #ff681f;
  588. }
  589. .empty-state {
  590. min-height: 430rpx;
  591. margin-top: 0;
  592. border-radius: 26rpx;
  593. background: #ffffff;
  594. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  595. display: flex;
  596. flex-direction: column;
  597. align-items: center;
  598. justify-content: center;
  599. text-align: center;
  600. }
  601. .empty-icon {
  602. width: 92rpx;
  603. height: 92rpx;
  604. border-radius: 28rpx;
  605. color: #0b8cff;
  606. background: #eef7ff;
  607. font-size: 34rpx;
  608. font-weight: 900;
  609. line-height: 92rpx;
  610. }
  611. .empty-title {
  612. margin-top: 24rpx;
  613. color: #172033;
  614. font-size: 30rpx;
  615. font-weight: 900;
  616. line-height: 1;
  617. }
  618. .empty-desc {
  619. width: 500rpx;
  620. max-width: 80%;
  621. margin-top: 14rpx;
  622. color: #8a95a6;
  623. font-size: 24rpx;
  624. line-height: 1.45;
  625. }
  626. .loading,
  627. .end-text {
  628. padding: 28rpx 0 12rpx;
  629. color: #9aa4b2;
  630. font-size: 24rpx;
  631. line-height: 1;
  632. text-align: center;
  633. }
  634. </style>