commission.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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">{{ formatPriceWithSymbol(summary.totalCommission) }}</text>
  9. <text class="header-value orange" v-else>{{ formatPriceWithSymbol(0) }}</text>
  10. </view>
  11. <view class="header-item">
  12. <text class="header-label">可提现</text>
  13. <text class="header-value blue" v-if="summary">{{ formatPriceWithSymbol(summary.availableAmount) }}</text>
  14. <text class="header-value blue" v-else>{{ formatPriceWithSymbol(0) }}</text>
  15. </view>
  16. <view class="header-item">
  17. <text class="header-label">待结算</text>
  18. <text class="header-value green" v-if="summary">{{ formatPriceWithSymbol(summary.pendingAmount) }}</text>
  19. <text class="header-value green" v-else>{{ formatPriceWithSymbol(0) }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- Tab 切换 -->
  24. <view class="tab-bar">
  25. <view class="tab-item" :class="currentTab === 'all' ? 'tab-active' : ''" @click="switchTab('all')">
  26. <text class="tab-text">全部</text>
  27. </view>
  28. <view class="tab-item" :class="currentTab === 'settled' ? 'tab-active' : ''" @click="switchTab('settled')">
  29. <text class="tab-text">已结算</text>
  30. </view>
  31. <view class="tab-item" :class="currentTab === 'pending' ? 'tab-active' : ''" @click="switchTab('pending')">
  32. <text class="tab-text">待结算</text>
  33. </view>
  34. </view>
  35. <!-- 佣金列表 -->
  36. <view class="list-section">
  37. <view class="list-item" v-for="item in list" :key="item.id">
  38. <view class="item-left">
  39. <text :class="['type-tag', item.commissionType === 'member' ? 'tag-orange' : 'tag-blue']">
  40. {{ item.commissionType === 'member' ? '会员佣金' : '商品佣金' }}
  41. </text>
  42. <text class="item-desc">{{ getOrderDesc(item) }}</text>
  43. </view>
  44. <view class="item-right">
  45. <text class="item-amount">+{{ formatPriceWithSymbol(item.commissionAmount) }}</text>
  46. <text class="item-status" :class="item.status === 'settled' ? 'status-settled' : item.status === 'cancelled' ? 'status-cancelled' : 'status-pending'">{{ getStatusText(item.status) }}</text>
  47. <text class="item-time">{{ formatTime(item.createdAt) }}</text>
  48. </view>
  49. </view>
  50. <view class="empty-state" v-if="!loading && list.length === 0">
  51. <text>暂无佣金记录</text>
  52. </view>
  53. <view class="loading-state" v-if="loading">
  54. <text>加载中...</text>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import { getCommissionList, getCommissionSummary, getCommissionStats } from '../../utils/api.js'
  61. import { parseDate } from '../../utils/format.js'
  62. export default {
  63. data() {
  64. return {
  65. list: [],
  66. summary: {},
  67. page: 1,
  68. hasMore: true,
  69. loading: false,
  70. currentTab: 'all'
  71. }
  72. },
  73. onLoad() {
  74. this.loadSummary()
  75. this.loadList()
  76. },
  77. onReachBottom() {
  78. if (this.hasMore && !this.loading) {
  79. this.page++
  80. this.loadList()
  81. }
  82. },
  83. methods: {
  84. switchTab(tab) {
  85. if (this.currentTab === tab) return
  86. this.currentTab = tab
  87. this.page = 1
  88. this.list = []
  89. this.loadList()
  90. },
  91. async loadSummary() {
  92. try {
  93. const res = await getCommissionSummary()
  94. if (res.data) {
  95. this.summary = res.data
  96. }
  97. } catch (e) {
  98. console.error('获取佣金总览失败', e)
  99. }
  100. },
  101. async loadList() {
  102. this.loading = true
  103. try {
  104. var page = this.page
  105. var size = 20
  106. var status = ''
  107. if (this.currentTab === 'settled') {
  108. status = 'settled'
  109. } else if (this.currentTab === 'pending') {
  110. status = 'pending'
  111. }
  112. const res = await getCommissionList(page, size, status)
  113. if (res.data && res.data.records) {
  114. this.list = this.page === 1 ? res.data.records : this.list.concat(res.data.records)
  115. this.hasMore = res.data.records.length >= 20
  116. } else {
  117. this.hasMore = false
  118. }
  119. } catch (e) {
  120. console.error('获取佣金明细失败', e)
  121. }
  122. this.loading = false
  123. },
  124. getOrderDesc(item) {
  125. var typeMap = {
  126. membership: '会员',
  127. product: '商品',
  128. assessment: '测评',
  129. package: '任务模板'
  130. }
  131. return (typeMap[item.orderType] || item.orderType) + '订单 #' + item.orderId
  132. },
  133. getStatusText(status) {
  134. var map = { settled: '已结算', pending: '待结算', cancelled: '已取消' }
  135. return map[status] || status || '待结算'
  136. },
  137. getStatusClass(status) {
  138. if (status === 'settled') return 'status-settled'
  139. if (status === 'cancelled') return 'status-cancelled'
  140. return 'status-pending'
  141. },
  142. formatTime(time) {
  143. if (!time) return ''
  144. var d = parseDate(time)
  145. if (!d) return ''
  146. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  147. }
  148. }
  149. }
  150. </script>
  151. <style scoped>
  152. .container {
  153. padding: 30rpx;
  154. min-height: 100vh;
  155. background: #FFF7ED;
  156. }
  157. .header-card {
  158. background: #fff;
  159. border-radius: 20rpx;
  160. padding: 32rpx 24rpx;
  161. margin-bottom: 24rpx;
  162. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  163. }
  164. .header-row {
  165. display: flex;
  166. }
  167. .header-item {
  168. flex: 1;
  169. text-align: center;
  170. }
  171. .header-label {
  172. font-size: 22rpx;
  173. color: #94A3B8;
  174. display: block;
  175. margin-bottom: 8rpx;
  176. }
  177. .header-value {
  178. font-size: 36rpx;
  179. font-weight: bold;
  180. }
  181. .header-value.orange { color: #F97316; }
  182. .header-value.blue { color: #0EA5E9; }
  183. .header-value.green { color: #10B981; }
  184. /* ===== Tab切换 ===== */
  185. .tab-bar {
  186. display: flex;
  187. background: #fff;
  188. border-radius: 16rpx;
  189. padding: 8rpx;
  190. margin-bottom: 24rpx;
  191. box-shadow: 0 2rpx 8rpx rgba(249,115,22,0.06);
  192. }
  193. .tab-item {
  194. flex: 1;
  195. text-align: center;
  196. padding: 16rpx 0;
  197. border-radius: 12rpx;
  198. }
  199. .tab-active {
  200. background: #F97316;
  201. }
  202. .tab-active .tab-text {
  203. color: #fff;
  204. font-weight: 600;
  205. }
  206. .tab-text {
  207. font-size: 26rpx;
  208. color: #64748B;
  209. }
  210. .list-section {
  211. background: #fff;
  212. border-radius: 20rpx;
  213. overflow: hidden;
  214. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  215. }
  216. .list-item {
  217. display: flex;
  218. justify-content: space-between;
  219. padding: 28rpx 24rpx;
  220. border-bottom: 1rpx solid #FED7AA;
  221. }
  222. .list-item:last-child {
  223. border-bottom: none;
  224. }
  225. .item-left {
  226. flex: 1;
  227. }
  228. .type-tag {
  229. font-size: 20rpx;
  230. padding: 4rpx 12rpx;
  231. border-radius: 6rpx;
  232. display: inline-block;
  233. margin-bottom: 8rpx;
  234. }
  235. .tag-orange {
  236. background: #FEF3C7;
  237. color: #D97706;
  238. }
  239. .tag-blue {
  240. background: #DBEAFE;
  241. color: #2563EB;
  242. }
  243. .item-desc {
  244. font-size: 24rpx;
  245. color: #64748B;
  246. display: block;
  247. }
  248. .item-right {
  249. text-align: right;
  250. }
  251. .item-amount {
  252. font-size: 30rpx;
  253. font-weight: bold;
  254. color: #F97316;
  255. display: block;
  256. }
  257. .item-status {
  258. font-size: 20rpx;
  259. padding: 2rpx 10rpx;
  260. border-radius: 6rpx;
  261. display: inline-block;
  262. margin-top: 4rpx;
  263. }
  264. .status-settled {
  265. color: #10B981;
  266. background: #D1FAE5;
  267. }
  268. .status-pending {
  269. color: #D97706;
  270. background: #FEF3C7;
  271. }
  272. .status-cancelled {
  273. color: #94A3B8;
  274. background: #F1F5F9;
  275. }
  276. .item-time {
  277. font-size: 20rpx;
  278. color: #94A3B8;
  279. display: block;
  280. margin-top: 4rpx;
  281. }
  282. .empty-state, .loading-state {
  283. text-align: center;
  284. padding: 60rpx;
  285. color: #94A3B8;
  286. font-size: 28rpx;
  287. }
  288. </style>