Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

737 řádky
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">{{ displayTitle(item) }}</text>
  46. <text class="ledger-status">已完成</text>
  47. </view>
  48. <text class="ledger-desc">{{ displayDesc(item) }}</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. function displayTitle(item = {}) {
  236. const text = String(item.title || '').trim().replace(/\s*第\s*1\s*张\s*$/g, '').trim()
  237. return text || item.title || '点数变动'
  238. }
  239. function displayDesc(item = {}) {
  240. const raw = String(item.desc || '').trim()
  241. const text = raw
  242. .replace(/(?:,|,|、|\s)*(混元生图\s*3\.0|腾讯混元大模型|腾讯混元|混元大模型|混元模型|高精模型|高清模型)\s*/gi, '')
  243. .replace(/(?:,|,|、)\s*(生成模型|模型)\s*[::]?\s*[^,,、]+/g, '')
  244. .replace(/[,,、\s]+$/g, '')
  245. .trim()
  246. return text || raw
  247. }
  248. /**
  249. * 充值流水的订单号。
  250. * 后端 point_log.biz_no 在充值时存的就是 point_order.order_no(消费存的是计费流水号,不展示)。
  251. */
  252. function orderNo(item) {
  253. if (!item || item.type !== 'recharge') return ''
  254. return String(item.biz_no || '').trim()
  255. }
  256. function copyOrderNo(value) {
  257. if (!value) return
  258. uni.setClipboardData({
  259. data: value,
  260. success: () => toast('订单号已复制'),
  261. fail: () => toast('复制失败,请长按选择')
  262. })
  263. }
  264. function getTypeMark(type) {
  265. return typeMark[type] || '记'
  266. }
  267. function goRecharge() {
  268. uni.navigateTo({ url: '/pages/recharge/recharge' })
  269. }
  270. </script>
  271. <style lang="scss" scoped>
  272. .page {
  273. min-height: 100vh;
  274. background: #f3f7fb;
  275. }
  276. .wrap {
  277. padding: 30rpx 30rpx calc(44rpx + env(safe-area-inset-bottom));
  278. box-sizing: border-box;
  279. }
  280. .wallet-card {
  281. position: relative;
  282. min-height: 308rpx;
  283. padding: 34rpx 32rpx 26rpx;
  284. border-radius: 30rpx;
  285. color: #ffffff;
  286. background: linear-gradient(135deg, #1167e8 0%, #0b8cff 58%, #41c7ff 100%);
  287. box-shadow: 0 18rpx 40rpx rgba(11, 140, 255, 0.22);
  288. overflow: hidden;
  289. box-sizing: border-box;
  290. }
  291. .wallet-card::before {
  292. content: '';
  293. position: absolute;
  294. right: -96rpx;
  295. top: -130rpx;
  296. width: 330rpx;
  297. height: 330rpx;
  298. border-radius: 50%;
  299. background: rgba(255, 255, 255, 0.16);
  300. }
  301. .wallet-card::after {
  302. display: none;
  303. }
  304. .wallet-copy,
  305. .wallet-stats {
  306. position: relative;
  307. z-index: 1;
  308. }
  309. .wallet-kicker {
  310. display: block;
  311. color: rgba(255, 255, 255, 0.74);
  312. font-size: 24rpx;
  313. font-weight: 800;
  314. line-height: 1;
  315. }
  316. .wallet-main {
  317. margin-top: 20rpx;
  318. display: flex;
  319. align-items: center;
  320. justify-content: space-between;
  321. gap: 24rpx;
  322. }
  323. .balance-line {
  324. min-width: 0;
  325. display: flex;
  326. align-items: flex-end;
  327. }
  328. .balance-number {
  329. color: #ffffff;
  330. font-size: 70rpx;
  331. font-weight: 900;
  332. line-height: 0.95;
  333. }
  334. .balance-unit {
  335. margin-left: 10rpx;
  336. margin-bottom: 8rpx;
  337. color: rgba(255, 255, 255, 0.78);
  338. font-size: 26rpx;
  339. font-weight: 800;
  340. }
  341. .recharge-action {
  342. height: 68rpx;
  343. min-width: 136rpx;
  344. padding: 0 30rpx;
  345. border-radius: 999rpx;
  346. color: #0b74ea;
  347. background: #ffffff;
  348. font-size: 27rpx;
  349. font-weight: 900;
  350. line-height: 68rpx;
  351. text-align: center;
  352. box-sizing: border-box;
  353. flex-shrink: 0;
  354. }
  355. .wallet-stats {
  356. margin-top: 34rpx;
  357. padding-top: 28rpx;
  358. border-top: 1rpx solid rgba(255, 255, 255, 0.22);
  359. display: grid;
  360. grid-template-columns: repeat(3, minmax(0, 1fr));
  361. gap: 0;
  362. }
  363. .stat-item {
  364. min-width: 0;
  365. display: flex;
  366. min-height: 76rpx;
  367. flex-direction: column;
  368. align-items: center;
  369. justify-content: center;
  370. text-align: center;
  371. }
  372. .stat-value {
  373. display: block;
  374. color: #ffffff;
  375. font-size: 30rpx;
  376. font-weight: 900;
  377. line-height: 1.08;
  378. }
  379. .stat-value.consume {
  380. color: #ffe2c7;
  381. }
  382. .stat-label {
  383. display: block;
  384. margin-top: 8rpx;
  385. color: rgba(255, 255, 255, 0.68);
  386. font-size: 22rpx;
  387. line-height: 1.15;
  388. }
  389. .filter-panel {
  390. margin-top: 24rpx;
  391. padding: 8rpx;
  392. border-radius: 24rpx;
  393. background: #ffffff;
  394. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  395. display: grid;
  396. grid-template-columns: repeat(5, minmax(0, 1fr));
  397. gap: 8rpx;
  398. }
  399. .filter-item {
  400. height: 88rpx;
  401. border-radius: 20rpx;
  402. display: flex;
  403. flex-direction: column;
  404. align-items: center;
  405. justify-content: center;
  406. color: #7f8896;
  407. }
  408. .filter-item.active {
  409. color: #0b8cff;
  410. background: #eef7ff;
  411. }
  412. .filter-name {
  413. font-size: 27rpx;
  414. font-weight: 900;
  415. line-height: 1;
  416. }
  417. .filter-count {
  418. margin-top: 8rpx;
  419. font-size: 20rpx;
  420. font-weight: 700;
  421. line-height: 1;
  422. opacity: 0.72;
  423. }
  424. .list-head {
  425. margin-top: 30rpx;
  426. margin-bottom: 16rpx;
  427. display: flex;
  428. align-items: center;
  429. justify-content: space-between;
  430. }
  431. .list-title {
  432. color: #172033;
  433. font-size: 32rpx;
  434. font-weight: 900;
  435. }
  436. .list-sub {
  437. color: #8a95a6;
  438. font-size: 24rpx;
  439. }
  440. .ledger-panel {
  441. border-radius: 26rpx;
  442. background: #ffffff;
  443. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  444. overflow: hidden;
  445. }
  446. .ledger-row {
  447. position: relative;
  448. min-height: 156rpx;
  449. padding: 26rpx 28rpx;
  450. display: flex;
  451. align-items: center;
  452. gap: 22rpx;
  453. box-sizing: border-box;
  454. }
  455. .ledger-row::after {
  456. content: '';
  457. position: absolute;
  458. left: 112rpx;
  459. right: 28rpx;
  460. bottom: 0;
  461. height: 1rpx;
  462. background: #edf2f7;
  463. }
  464. .ledger-row:last-child::after {
  465. display: none;
  466. }
  467. .type-mark {
  468. width: 62rpx;
  469. height: 62rpx;
  470. border-radius: 20rpx;
  471. display: flex;
  472. align-items: center;
  473. justify-content: center;
  474. font-size: 29rpx;
  475. font-weight: 900;
  476. flex-shrink: 0;
  477. }
  478. .type-mark.recharge {
  479. color: #0b8cff;
  480. background: #eef7ff;
  481. }
  482. .type-mark.consume {
  483. color: #ff681f;
  484. background: #fff4ec;
  485. }
  486. .type-mark.reward {
  487. color: #17a65a;
  488. background: #edfdf4;
  489. }
  490. .type-mark.refund,
  491. .type-mark.adjust {
  492. color: #7a5af8;
  493. background: #f3f0ff;
  494. }
  495. .ledger-main {
  496. min-width: 0;
  497. flex: 1;
  498. }
  499. .title-row {
  500. display: flex;
  501. align-items: center;
  502. gap: 14rpx;
  503. }
  504. .ledger-title {
  505. min-width: 0;
  506. color: #172033;
  507. font-size: 29rpx;
  508. font-weight: 900;
  509. line-height: 1.25;
  510. overflow: hidden;
  511. text-overflow: ellipsis;
  512. white-space: nowrap;
  513. }
  514. .ledger-status {
  515. height: 32rpx;
  516. padding: 0 12rpx;
  517. border-radius: 999rpx;
  518. color: #17a65a;
  519. background: #edfdf4;
  520. font-size: 19rpx;
  521. font-weight: 800;
  522. line-height: 32rpx;
  523. flex-shrink: 0;
  524. }
  525. .ledger-desc {
  526. display: block;
  527. margin-top: 10rpx;
  528. color: #7f8896;
  529. font-size: 24rpx;
  530. line-height: 1.35;
  531. overflow: hidden;
  532. text-overflow: ellipsis;
  533. white-space: nowrap;
  534. }
  535. .ledger-meta {
  536. margin-top: 14rpx;
  537. display: flex;
  538. align-items: center;
  539. gap: 14rpx;
  540. color: #9aa4b2;
  541. font-size: 22rpx;
  542. }
  543. .ledger-order {
  544. margin-top: 10rpx;
  545. display: flex;
  546. align-items: center;
  547. gap: 10rpx;
  548. }
  549. .ledger-order-text {
  550. min-width: 0;
  551. flex: 1;
  552. color: #9aa4b2;
  553. font-size: 21rpx;
  554. overflow: hidden;
  555. white-space: nowrap;
  556. text-overflow: ellipsis;
  557. }
  558. .ledger-order-copy {
  559. flex-shrink: 0;
  560. color: #0b8cff;
  561. font-size: 21rpx;
  562. font-weight: 800;
  563. }
  564. .ledger-type {
  565. height: 34rpx;
  566. padding: 0 14rpx;
  567. border-radius: 999rpx;
  568. font-size: 20rpx;
  569. font-weight: 900;
  570. line-height: 34rpx;
  571. }
  572. .ledger-type.recharge {
  573. color: #0b8cff;
  574. background: #eef7ff;
  575. }
  576. .ledger-type.consume {
  577. color: #ff681f;
  578. background: #fff4ec;
  579. }
  580. .ledger-type.reward {
  581. color: #17a65a;
  582. background: #edfdf4;
  583. }
  584. .ledger-type.refund,
  585. .ledger-type.adjust {
  586. color: #7a5af8;
  587. background: #f3f0ff;
  588. }
  589. .ledger-amount {
  590. color: #172033;
  591. font-size: 34rpx;
  592. font-weight: 900;
  593. line-height: 1;
  594. flex-shrink: 0;
  595. }
  596. .ledger-amount.plus {
  597. color: #17a65a;
  598. }
  599. .ledger-amount.minus {
  600. color: #ff681f;
  601. }
  602. .empty-state {
  603. min-height: 430rpx;
  604. margin-top: 0;
  605. border-radius: 26rpx;
  606. background: #ffffff;
  607. box-shadow: 0 8rpx 28rpx rgba(34, 68, 112, 0.05);
  608. display: flex;
  609. flex-direction: column;
  610. align-items: center;
  611. justify-content: center;
  612. text-align: center;
  613. }
  614. .empty-icon {
  615. width: 92rpx;
  616. height: 92rpx;
  617. border-radius: 28rpx;
  618. color: #0b8cff;
  619. background: #eef7ff;
  620. font-size: 34rpx;
  621. font-weight: 900;
  622. line-height: 92rpx;
  623. }
  624. .empty-title {
  625. margin-top: 24rpx;
  626. color: #172033;
  627. font-size: 30rpx;
  628. font-weight: 900;
  629. line-height: 1;
  630. }
  631. .empty-desc {
  632. width: 500rpx;
  633. max-width: 80%;
  634. margin-top: 14rpx;
  635. color: #8a95a6;
  636. font-size: 24rpx;
  637. line-height: 1.45;
  638. }
  639. .loading,
  640. .end-text {
  641. padding: 28rpx 0 12rpx;
  642. color: #9aa4b2;
  643. font-size: 24rpx;
  644. line-height: 1;
  645. text-align: center;
  646. }
  647. </style>