commission.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 头部总览 -->
  4. <view class="header-card">
  5. <view class="header-row">
  6. <view class="header-item">
  7. <text class="header-label">累计获取</text>
  8. <text class="header-value orange" v-if="summary">{{ cfToYuan(summary.totalEarned) }}</text>
  9. <text class="header-value orange" v-else>¥0.00</text>
  10. </view>
  11. <view class="header-item">
  12. <text class="header-label">可用余额</text>
  13. <text class="header-value blue" v-if="summary">{{ cfToYuan(summary.available) }}</text>
  14. <text class="header-value blue" v-else>¥0.00</text>
  15. </view>
  16. <view class="header-item">
  17. <text class="header-label">冻结</text>
  18. <text class="header-value green" v-if="summary">{{ cfToYuan(summary.frozen) }}</text>
  19. <text class="header-value green" v-else>¥0.00</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- CF 流水列表 -->
  24. <view class="list-section">
  25. <view class="list-item" v-for="item in list" :key="item.id">
  26. <view class="item-left">
  27. <text :class="['type-tag', isPositive(item.type) ? 'tag-orange' : 'tag-blue']">
  28. {{ getTypeText(item.type) }}
  29. </text>
  30. <text class="item-desc">{{ item.remark || 'CF值变动' }}</text>
  31. </view>
  32. <view class="item-right">
  33. <text :class="['item-amount', isPositive(item.type) ? 'amount-positive' : 'amount-negative']">{{ getAmountText(item) }}</text>
  34. <text class="item-status">{{ getRefText(item.refType) }}</text>
  35. <text class="item-time">{{ formatTime(item.createdAt) }}</text>
  36. </view>
  37. </view>
  38. <view class="empty-state" v-if="!loading && list.length === 0">
  39. <text>暂无 CF 流水记录</text>
  40. </view>
  41. <view class="loading-state" v-if="loading">
  42. <text>加载中...</text>
  43. </view>
  44. <view class="loadmore-state" v-if="!loading && list.length > 0 && !hasMore">
  45. <text>没有更多了</text>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { getCfSummary, getCfList } from '../../utils/api.js'
  52. import { parseDate } from '../../utils/format.js'
  53. import fontScaleMixin from '@/mixins/font-scale.js'
  54. export default {
  55. mixins: [fontScaleMixin],
  56. data() {
  57. return {
  58. list: [],
  59. summary: {},
  60. page: 1,
  61. hasMore: true,
  62. loading: false
  63. }
  64. },
  65. onLoad() {
  66. this.loadSummary()
  67. this.loadList()
  68. },
  69. onReachBottom() {
  70. if (this.hasMore && !this.loading) {
  71. this.page++
  72. this.loadList()
  73. }
  74. },
  75. methods: {
  76. async loadSummary() {
  77. try {
  78. var res = await getCfSummary()
  79. if (res.data) {
  80. this.summary = res.data
  81. }
  82. } catch (e) {
  83. console.error('获取 CF 总览失败', e)
  84. }
  85. },
  86. async loadList() {
  87. this.loading = true
  88. try {
  89. var res = await getCfList(this.page, 20)
  90. if (res.data && res.data.records) {
  91. this.list = this.page === 1 ? res.data.records : this.list.concat(res.data.records)
  92. this.hasMore = res.data.records.length >= 20
  93. } else {
  94. this.hasMore = false
  95. }
  96. } catch (e) {
  97. console.error('获取 CF 流水失败', e)
  98. }
  99. this.loading = false
  100. },
  101. isPositive(type) {
  102. return type === 'earn' || type === 'unfreeze'
  103. },
  104. getAmountText(item) {
  105. var prefix = this.isPositive(item.type) ? '+' : '-'
  106. return prefix + this.cfToYuan(item.amount)
  107. },
  108. getTypeText(type) {
  109. var map = { earn: '获得', spend: '支出', freeze: '冻结', unfreeze: '解冻', withdraw: '提现' }
  110. return map[type] || type || '变动'
  111. },
  112. getRefText(refType) {
  113. var map = { product_order: '商品订单', activity: '活动', withdrawal: '提现', migration: '迁移', cf_transfer_out: '转让转出', cf_transfer_in: '转让转入' }
  114. return map[refType] || ''
  115. },
  116. cfToYuan(val) {
  117. if (val === null || val === undefined) return '¥0.00'
  118. var num = Number(val)
  119. if (isNaN(num)) return '¥0.00'
  120. return '¥' + (num / 100).toFixed(2)
  121. },
  122. formatTime(time) {
  123. if (!time) return ''
  124. var d = parseDate(time)
  125. if (!d) return ''
  126. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0') + ' ' +
  127. String(d.getHours()).padStart(2, '0') + ':' +
  128. String(d.getMinutes()).padStart(2, '0') + ':' +
  129. String(d.getSeconds()).padStart(2, '0')
  130. }
  131. }
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .container {
  136. padding: $uni-space-page;
  137. min-height: 100vh;
  138. background: $uni-primary-pale;
  139. }
  140. .header-card {
  141. background: $app-surface;
  142. border-radius: 24rpx;
  143. padding: 32rpx 24rpx;
  144. margin-bottom: 24rpx;
  145. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  146. }
  147. .header-row {
  148. display: flex;
  149. }
  150. .header-item {
  151. flex: 1;
  152. text-align: center;
  153. }
  154. .header-label {
  155. font-size: calc(22rpx * var(--font-scale, 1));
  156. color: $app-text-subtle;
  157. display: block;
  158. margin-bottom: 8rpx;
  159. }
  160. .header-value {
  161. font-size: calc(36rpx * var(--font-scale, 1));
  162. font-weight: bold;
  163. }
  164. .header-value.orange { color: $brand-primary; }
  165. .header-value.blue { color: $uni-info; }
  166. .header-value.green { color: $status-success; }
  167. .list-section {
  168. background: $app-surface;
  169. border-radius: 24rpx;
  170. overflow: hidden;
  171. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  172. }
  173. .list-item {
  174. display: flex;
  175. justify-content: space-between;
  176. padding: 28rpx 24rpx;
  177. border-bottom: 1rpx solid $brand-primary-light-2;
  178. }
  179. .list-item:last-child {
  180. border-bottom: none;
  181. }
  182. .item-left {
  183. flex: 1;
  184. }
  185. .type-tag {
  186. font-size: calc(20rpx * var(--font-scale, 1));
  187. padding: 4rpx 12rpx;
  188. border-radius: 8rpx;
  189. display: inline-block;
  190. margin-bottom: 8rpx;
  191. }
  192. .tag-orange {
  193. background: $status-warning-soft;
  194. color: $status-warning-deep;
  195. }
  196. .tag-blue {
  197. background: $status-info-soft;
  198. color: $status-info-deep;
  199. }
  200. .item-desc {
  201. font-size: calc(24rpx * var(--font-scale, 1));
  202. color: $uni-text-color-secondary;
  203. display: block;
  204. }
  205. .item-right {
  206. text-align: right;
  207. }
  208. .item-amount {
  209. font-size: calc(30rpx * var(--font-scale, 1));
  210. font-weight: bold;
  211. display: block;
  212. }
  213. .amount-positive {
  214. color: $brand-primary;
  215. }
  216. .amount-negative {
  217. color: $app-text-subtle;
  218. }
  219. .item-status {
  220. font-size: calc(20rpx * var(--font-scale, 1));
  221. color: $app-text-subtle;
  222. display: inline-block;
  223. margin-top: 4rpx;
  224. }
  225. .item-time {
  226. font-size: calc(20rpx * var(--font-scale, 1));
  227. color: $app-text-subtle;
  228. display: block;
  229. margin-top: 4rpx;
  230. }
  231. .empty-state, .loading-state, .loadmore-state {
  232. text-align: center;
  233. padding: 60rpx;
  234. color: $app-text-subtle;
  235. font-size: calc(28rpx * var(--font-scale, 1));
  236. }
  237. </style>