You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

720 lines
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. content: '';
  290. position: absolute;
  291. left: 42rpx;
  292. right: 42rpx;
  293. bottom: 118rpx;
  294. height: 1rpx;
  295. background: rgba(255, 255, 255, 0.2);
  296. }
  297. .wallet-copy,
  298. .wallet-stats {
  299. position: relative;
  300. z-index: 1;
  301. }
  302. .wallet-kicker {
  303. display: block;
  304. color: rgba(255, 255, 255, 0.74);
  305. font-size: 24rpx;
  306. font-weight: 800;
  307. line-height: 1;
  308. }
  309. .wallet-main {
  310. margin-top: 20rpx;
  311. display: flex;
  312. align-items: center;
  313. justify-content: space-between;
  314. gap: 24rpx;
  315. }
  316. .balance-line {
  317. min-width: 0;
  318. display: flex;
  319. align-items: flex-end;
  320. }
  321. .balance-number {
  322. color: #ffffff;
  323. font-size: 70rpx;
  324. font-weight: 900;
  325. line-height: 0.95;
  326. }
  327. .balance-unit {
  328. margin-left: 10rpx;
  329. margin-bottom: 8rpx;
  330. color: rgba(255, 255, 255, 0.78);
  331. font-size: 26rpx;
  332. font-weight: 800;
  333. }
  334. .recharge-action {
  335. height: 68rpx;
  336. min-width: 136rpx;
  337. padding: 0 30rpx;
  338. border-radius: 999rpx;
  339. color: #0b74ea;
  340. background: #ffffff;
  341. font-size: 27rpx;
  342. font-weight: 900;
  343. line-height: 68rpx;
  344. text-align: center;
  345. box-sizing: border-box;
  346. flex-shrink: 0;
  347. }
  348. .wallet-stats {
  349. margin-top: 46rpx;
  350. display: grid;
  351. grid-template-columns: repeat(3, minmax(0, 1fr));
  352. gap: 12rpx;
  353. }
  354. .stat-item {
  355. min-width: 0;
  356. }
  357. .stat-value {
  358. display: block;
  359. color: #ffffff;
  360. font-size: 28rpx;
  361. font-weight: 900;
  362. line-height: 1;
  363. }
  364. .stat-value.consume {
  365. color: #ffe2c7;
  366. }
  367. .stat-label {
  368. display: block;
  369. margin-top: 10rpx;
  370. color: rgba(255, 255, 255, 0.68);
  371. font-size: 21rpx;
  372. line-height: 1;
  373. }
  374. .filter-panel {
  375. margin-top: 24rpx;
  376. padding: 8rpx;
  377. border-radius: 24rpx;
  378. background: #ffffff;
  379. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  380. display: grid;
  381. grid-template-columns: repeat(5, minmax(0, 1fr));
  382. gap: 8rpx;
  383. }
  384. .filter-item {
  385. height: 88rpx;
  386. border-radius: 20rpx;
  387. display: flex;
  388. flex-direction: column;
  389. align-items: center;
  390. justify-content: center;
  391. color: #7f8896;
  392. }
  393. .filter-item.active {
  394. color: #0b8cff;
  395. background: #eef7ff;
  396. }
  397. .filter-name {
  398. font-size: 27rpx;
  399. font-weight: 900;
  400. line-height: 1;
  401. }
  402. .filter-count {
  403. margin-top: 8rpx;
  404. font-size: 20rpx;
  405. font-weight: 700;
  406. line-height: 1;
  407. opacity: 0.72;
  408. }
  409. .list-head {
  410. margin-top: 30rpx;
  411. margin-bottom: 16rpx;
  412. display: flex;
  413. align-items: center;
  414. justify-content: space-between;
  415. }
  416. .list-title {
  417. color: #172033;
  418. font-size: 32rpx;
  419. font-weight: 900;
  420. }
  421. .list-sub {
  422. color: #8a95a6;
  423. font-size: 24rpx;
  424. }
  425. .ledger-panel {
  426. border-radius: 26rpx;
  427. background: #ffffff;
  428. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  429. overflow: hidden;
  430. }
  431. .ledger-row {
  432. position: relative;
  433. min-height: 156rpx;
  434. padding: 26rpx 28rpx;
  435. display: flex;
  436. align-items: center;
  437. gap: 22rpx;
  438. box-sizing: border-box;
  439. }
  440. .ledger-row::after {
  441. content: '';
  442. position: absolute;
  443. left: 112rpx;
  444. right: 28rpx;
  445. bottom: 0;
  446. height: 1rpx;
  447. background: #edf2f7;
  448. }
  449. .ledger-row:last-child::after {
  450. display: none;
  451. }
  452. .type-mark {
  453. width: 62rpx;
  454. height: 62rpx;
  455. border-radius: 20rpx;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. font-size: 29rpx;
  460. font-weight: 900;
  461. flex-shrink: 0;
  462. }
  463. .type-mark.recharge {
  464. color: #0b8cff;
  465. background: #eef7ff;
  466. }
  467. .type-mark.consume {
  468. color: #ff681f;
  469. background: #fff4ec;
  470. }
  471. .type-mark.reward {
  472. color: #17a65a;
  473. background: #edfdf4;
  474. }
  475. .type-mark.refund,
  476. .type-mark.adjust {
  477. color: #7a5af8;
  478. background: #f3f0ff;
  479. }
  480. .ledger-main {
  481. min-width: 0;
  482. flex: 1;
  483. }
  484. .title-row {
  485. display: flex;
  486. align-items: center;
  487. gap: 14rpx;
  488. }
  489. .ledger-title {
  490. min-width: 0;
  491. color: #172033;
  492. font-size: 29rpx;
  493. font-weight: 900;
  494. line-height: 1.25;
  495. overflow: hidden;
  496. text-overflow: ellipsis;
  497. white-space: nowrap;
  498. }
  499. .ledger-status {
  500. height: 32rpx;
  501. padding: 0 12rpx;
  502. border-radius: 999rpx;
  503. color: #17a65a;
  504. background: #edfdf4;
  505. font-size: 19rpx;
  506. font-weight: 800;
  507. line-height: 32rpx;
  508. flex-shrink: 0;
  509. }
  510. .ledger-desc {
  511. display: block;
  512. margin-top: 10rpx;
  513. color: #7f8896;
  514. font-size: 24rpx;
  515. line-height: 1.35;
  516. overflow: hidden;
  517. text-overflow: ellipsis;
  518. white-space: nowrap;
  519. }
  520. .ledger-meta {
  521. margin-top: 14rpx;
  522. display: flex;
  523. align-items: center;
  524. gap: 14rpx;
  525. color: #9aa4b2;
  526. font-size: 22rpx;
  527. }
  528. .ledger-order {
  529. margin-top: 10rpx;
  530. display: flex;
  531. align-items: center;
  532. gap: 10rpx;
  533. }
  534. .ledger-order-text {
  535. min-width: 0;
  536. flex: 1;
  537. color: #9aa4b2;
  538. font-size: 21rpx;
  539. overflow: hidden;
  540. white-space: nowrap;
  541. text-overflow: ellipsis;
  542. }
  543. .ledger-order-copy {
  544. flex-shrink: 0;
  545. color: #0b8cff;
  546. font-size: 21rpx;
  547. font-weight: 800;
  548. }
  549. .ledger-type {
  550. height: 34rpx;
  551. padding: 0 14rpx;
  552. border-radius: 999rpx;
  553. font-size: 20rpx;
  554. font-weight: 900;
  555. line-height: 34rpx;
  556. }
  557. .ledger-type.recharge {
  558. color: #0b8cff;
  559. background: #eef7ff;
  560. }
  561. .ledger-type.consume {
  562. color: #ff681f;
  563. background: #fff4ec;
  564. }
  565. .ledger-type.reward {
  566. color: #17a65a;
  567. background: #edfdf4;
  568. }
  569. .ledger-type.refund,
  570. .ledger-type.adjust {
  571. color: #7a5af8;
  572. background: #f3f0ff;
  573. }
  574. .ledger-amount {
  575. color: #172033;
  576. font-size: 34rpx;
  577. font-weight: 900;
  578. line-height: 1;
  579. flex-shrink: 0;
  580. }
  581. .ledger-amount.plus {
  582. color: #17a65a;
  583. }
  584. .ledger-amount.minus {
  585. color: #ff681f;
  586. }
  587. .empty-state {
  588. min-height: 430rpx;
  589. margin-top: 0;
  590. border-radius: 26rpx;
  591. background: #ffffff;
  592. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  593. display: flex;
  594. flex-direction: column;
  595. align-items: center;
  596. justify-content: center;
  597. text-align: center;
  598. }
  599. .empty-icon {
  600. width: 92rpx;
  601. height: 92rpx;
  602. border-radius: 28rpx;
  603. color: #0b8cff;
  604. background: #eef7ff;
  605. font-size: 34rpx;
  606. font-weight: 900;
  607. line-height: 92rpx;
  608. }
  609. .empty-title {
  610. margin-top: 24rpx;
  611. color: #172033;
  612. font-size: 30rpx;
  613. font-weight: 900;
  614. line-height: 1;
  615. }
  616. .empty-desc {
  617. width: 500rpx;
  618. max-width: 80%;
  619. margin-top: 14rpx;
  620. color: #8a95a6;
  621. font-size: 24rpx;
  622. line-height: 1.45;
  623. }
  624. .loading,
  625. .end-text {
  626. padding: 28rpx 0 12rpx;
  627. color: #9aa4b2;
  628. font-size: 24rpx;
  629. line-height: 1;
  630. text-align: center;
  631. }
  632. </style>