commission.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="container">
  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. export default {
  54. data() {
  55. return {
  56. list: [],
  57. summary: {},
  58. page: 1,
  59. hasMore: true,
  60. loading: false
  61. }
  62. },
  63. onLoad() {
  64. this.loadSummary()
  65. this.loadList()
  66. },
  67. onReachBottom() {
  68. if (this.hasMore && !this.loading) {
  69. this.page++
  70. this.loadList()
  71. }
  72. },
  73. methods: {
  74. async loadSummary() {
  75. try {
  76. var res = await getCfSummary()
  77. if (res.data) {
  78. this.summary = res.data
  79. }
  80. } catch (e) {
  81. console.error('获取 CF 总览失败', e)
  82. }
  83. },
  84. async loadList() {
  85. this.loading = true
  86. try {
  87. var res = await getCfList(this.page, 20)
  88. if (res.data && res.data.records) {
  89. this.list = this.page === 1 ? res.data.records : this.list.concat(res.data.records)
  90. this.hasMore = res.data.records.length >= 20
  91. } else {
  92. this.hasMore = false
  93. }
  94. } catch (e) {
  95. console.error('获取 CF 流水失败', e)
  96. }
  97. this.loading = false
  98. },
  99. isPositive(type) {
  100. return type === 'earn' || type === 'unfreeze'
  101. },
  102. getAmountText(item) {
  103. var prefix = this.isPositive(item.type) ? '+' : '-'
  104. return prefix + this.cfToYuan(item.amount)
  105. },
  106. getTypeText(type) {
  107. var map = { earn: '获得', spend: '支出', freeze: '冻结', unfreeze: '解冻', withdraw: '提现' }
  108. return map[type] || type || '变动'
  109. },
  110. getRefText(refType) {
  111. var map = { product_order: '商品订单', activity: '活动', withdrawal: '提现', migration: '迁移', cf_transfer_out: '转让转出', cf_transfer_in: '转让转入' }
  112. return map[refType] || ''
  113. },
  114. cfToYuan(val) {
  115. if (val === null || val === undefined) return '¥0.00'
  116. var num = Number(val)
  117. if (isNaN(num)) return '¥0.00'
  118. return '¥' + (num / 100).toFixed(2)
  119. },
  120. formatTime(time) {
  121. if (!time) return ''
  122. var d = parseDate(time)
  123. if (!d) return ''
  124. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0') + ' ' +
  125. String(d.getHours()).padStart(2, '0') + ':' +
  126. String(d.getMinutes()).padStart(2, '0') + ':' +
  127. String(d.getSeconds()).padStart(2, '0')
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .container {
  134. padding: 30rpx;
  135. min-height: 100vh;
  136. background: #FFF7ED;
  137. }
  138. .header-card {
  139. background: #fff;
  140. border-radius: 20rpx;
  141. padding: 32rpx 24rpx;
  142. margin-bottom: 24rpx;
  143. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  144. }
  145. .header-row {
  146. display: flex;
  147. }
  148. .header-item {
  149. flex: 1;
  150. text-align: center;
  151. }
  152. .header-label {
  153. font-size: 22rpx;
  154. color: #94A3B8;
  155. display: block;
  156. margin-bottom: 8rpx;
  157. }
  158. .header-value {
  159. font-size: 36rpx;
  160. font-weight: bold;
  161. }
  162. .header-value.orange { color: #F97316; }
  163. .header-value.blue { color: #0EA5E9; }
  164. .header-value.green { color: #10B981; }
  165. .list-section {
  166. background: #fff;
  167. border-radius: 20rpx;
  168. overflow: hidden;
  169. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  170. }
  171. .list-item {
  172. display: flex;
  173. justify-content: space-between;
  174. padding: 28rpx 24rpx;
  175. border-bottom: 1rpx solid #FED7AA;
  176. }
  177. .list-item:last-child {
  178. border-bottom: none;
  179. }
  180. .item-left {
  181. flex: 1;
  182. }
  183. .type-tag {
  184. font-size: 20rpx;
  185. padding: 4rpx 12rpx;
  186. border-radius: 6rpx;
  187. display: inline-block;
  188. margin-bottom: 8rpx;
  189. }
  190. .tag-orange {
  191. background: #FEF3C7;
  192. color: #D97706;
  193. }
  194. .tag-blue {
  195. background: #DBEAFE;
  196. color: #2563EB;
  197. }
  198. .item-desc {
  199. font-size: 24rpx;
  200. color: #64748B;
  201. display: block;
  202. }
  203. .item-right {
  204. text-align: right;
  205. }
  206. .item-amount {
  207. font-size: 30rpx;
  208. font-weight: bold;
  209. display: block;
  210. }
  211. .amount-positive {
  212. color: #F97316;
  213. }
  214. .amount-negative {
  215. color: #94A3B8;
  216. }
  217. .item-status {
  218. font-size: 20rpx;
  219. color: #94A3B8;
  220. display: inline-block;
  221. margin-top: 4rpx;
  222. }
  223. .item-time {
  224. font-size: 20rpx;
  225. color: #94A3B8;
  226. display: block;
  227. margin-top: 4rpx;
  228. }
  229. .empty-state, .loading-state, .loadmore-state {
  230. text-align: center;
  231. padding: 60rpx;
  232. color: #94A3B8;
  233. font-size: 28rpx;
  234. }
  235. </style>