commission.vue 7.3 KB

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