index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <scroll-view class="container" scroll-y>
  3. <!-- 邀请码区域 -->
  4. <view class="invite-card">
  5. <view class="code-section">
  6. <text class="code-label">我的邀请码</text>
  7. <view class="code-value" @click="copyCode">
  8. <text class="code-text">{{ referralCode || '加载中...' }}</text>
  9. <text class="copy-icon">⎘</text>
  10. </view>
  11. <text class="code-hint">点击复制邀请码,分享给好友</text>
  12. </view>
  13. <button class="share-btn" @click="shareCard">分享邀请卡</button>
  14. </view>
  15. <!-- 收益概览 -->
  16. <view class="earnings-card">
  17. <view class="earnings-header">
  18. <text class="earnings-title">收益总览</text>
  19. </view>
  20. <view class="earnings-body">
  21. <view class="earning-item">
  22. <text class="earning-label">累计佣金</text>
  23. <text class="earning-value orange" v-if="summary">{{ formatPriceWithSymbol(summary.totalCommission) }}</text>
  24. <text class="earning-value orange" v-else>{{ formatPriceWithSymbol(0) }}</text>
  25. </view>
  26. <view class="earning-divider"></view>
  27. <view class="earning-item">
  28. <text class="earning-label">可提现</text>
  29. <text class="earning-value blue" v-if="summary">{{ formatPriceWithSymbol(summary.availableAmount) }}</text>
  30. <text class="earning-value blue" v-else>{{ formatPriceWithSymbol(0) }}</text>
  31. </view>
  32. <view class="earning-divider"></view>
  33. <view class="earning-item">
  34. <text class="earning-label">待结算</text>
  35. <text class="earning-value green" v-if="summary">{{ formatPriceWithSymbol(summary.pendingAmount) }}</text>
  36. <text class="earning-value green" v-else>{{ formatPriceWithSymbol(0) }}</text>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 功能入口 -->
  41. <view class="menu-grid">
  42. <view class="menu-item" @click="goCommission">
  43. <view class="menu-icon-wrap icon-commission">
  44. <text class="menu-icon-text">📋</text>
  45. </view>
  46. <text class="menu-text">佣金明细</text>
  47. </view>
  48. <view class="menu-item" @click="goWithdraw">
  49. <view class="menu-icon-wrap icon-withdraw">
  50. <text class="menu-icon-text">💰</text>
  51. </view>
  52. <text class="menu-text">立即提现</text>
  53. </view>
  54. <view class="menu-item" @click="goInvite">
  55. <view class="menu-icon-wrap icon-invite">
  56. <text class="menu-icon-text">👥</text>
  57. </view>
  58. <text class="menu-text">邀请好友</text>
  59. </view>
  60. <view class="menu-item" @click="goTeam">
  61. <view class="menu-icon-wrap icon-team">
  62. <text class="menu-icon-text">🤝</text>
  63. </view>
  64. <text class="menu-text">推广团队</text>
  65. </view>
  66. </view>
  67. </scroll-view>
  68. </template>
  69. <script>
  70. import { getReferralCode, getReferralSummary, getCommissionSummary } from '../../utils/api.js'
  71. export default {
  72. data() {
  73. return {
  74. referralCode: '',
  75. totalEarnings: '0.00',
  76. availableAmount: '0.00',
  77. summary: null
  78. }
  79. },
  80. computed: {
  81. isLoggedIn() {
  82. return !!uni.getStorageSync('token')
  83. }
  84. },
  85. onLoad() {
  86. this.loadData()
  87. },
  88. methods: {
  89. async loadData() {
  90. try {
  91. const codeRes = await getReferralCode()
  92. if (codeRes.data) {
  93. this.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  94. }
  95. } catch (e) {
  96. console.error('获取邀请码失败', e)
  97. }
  98. try {
  99. const summaryRes = await getReferralSummary()
  100. if (summaryRes.data) {
  101. this.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  102. }
  103. } catch (e) {
  104. console.error('获取邀请统计失败', e)
  105. }
  106. try {
  107. const comRes = await getCommissionSummary()
  108. if (comRes.data) {
  109. this.summary = comRes.data
  110. this.availableAmount = comRes.data.availableAmount || '0.00'
  111. }
  112. } catch (e) {
  113. console.error('获取佣金总览失败', e)
  114. }
  115. },
  116. copyCode() {
  117. if (!this.referralCode) return
  118. uni.setClipboardData({
  119. data: this.referralCode,
  120. success: function() {
  121. uni.showToast({ title: '邀请码已复制', icon: 'success' })
  122. }
  123. })
  124. },
  125. shareCard() {
  126. uni.showToast({ title: '即将上线', icon: 'none' })
  127. },
  128. goCommission() {
  129. uni.navigateTo({ url: '/pages/promotion/commission' })
  130. },
  131. goWithdraw() {
  132. uni.navigateTo({ url: '/pages/promotion/withdraw' })
  133. },
  134. goInvite() {
  135. uni.navigateTo({ url: '/pages/promotion/invite' })
  136. },
  137. goTeam() {
  138. uni.showToast({ title: '即将上线', icon: 'none' })
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. .container {
  145. padding: 30rpx;
  146. min-height: 100vh;
  147. background: #FFF7ED;
  148. }
  149. .invite-card {
  150. background: linear-gradient(135deg, #F97316, #EA580C);
  151. border-radius: 20rpx;
  152. padding: 40rpx;
  153. color: #fff;
  154. margin-bottom: 30rpx;
  155. }
  156. .code-section {
  157. margin-bottom: 30rpx;
  158. }
  159. .code-label {
  160. font-size: 24rpx;
  161. opacity: 0.85;
  162. }
  163. .code-value {
  164. display: flex;
  165. align-items: center;
  166. margin-top: 12rpx;
  167. }
  168. .code-text {
  169. font-size: 44rpx;
  170. font-weight: bold;
  171. letter-spacing: 6rpx;
  172. }
  173. .copy-icon {
  174. font-size: 36rpx;
  175. margin-left: 16rpx;
  176. opacity: 0.9;
  177. }
  178. .code-hint {
  179. font-size: 22rpx;
  180. opacity: 0.7;
  181. margin-top: 8rpx;
  182. display: block;
  183. }
  184. .share-btn {
  185. background: rgba(255,255,255,0.2);
  186. color: #fff;
  187. font-size: 28rpx;
  188. border-radius: 40rpx;
  189. height: 72rpx;
  190. line-height: 72rpx;
  191. border: 1rpx solid rgba(255,255,255,0.3);
  192. }
  193. .share-btn::after { border: none; }
  194. .share-btn:active { opacity: 0.8; }
  195. /* ===== 收益总览 ===== */
  196. .earnings-card {
  197. background: #fff;
  198. border-radius: 20rpx;
  199. margin-bottom: 30rpx;
  200. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  201. overflow: hidden;
  202. }
  203. .earnings-header {
  204. padding: 24rpx 32rpx 0;
  205. }
  206. .earnings-title {
  207. font-size: 28rpx;
  208. font-weight: 600;
  209. color: #1E293B;
  210. }
  211. .earnings-body {
  212. display: flex;
  213. align-items: center;
  214. padding: 24rpx 32rpx 32rpx;
  215. }
  216. .earning-item {
  217. flex: 1;
  218. text-align: center;
  219. }
  220. .earning-label {
  221. font-size: 22rpx;
  222. color: #94A3B8;
  223. display: block;
  224. margin-bottom: 8rpx;
  225. }
  226. .earning-value {
  227. font-size: 36rpx;
  228. font-weight: bold;
  229. }
  230. .earning-value.orange { color: #F97316; }
  231. .earning-value.blue { color: #0EA5E9; }
  232. .earning-value.green { color: #10B981; }
  233. .earning-divider {
  234. width: 1rpx;
  235. height: 64rpx;
  236. background: #FED7AA;
  237. }
  238. /* ===== 功能入口 ===== */
  239. .menu-grid {
  240. display: flex;
  241. flex-wrap: wrap;
  242. background: #fff;
  243. border-radius: 20rpx;
  244. padding: 24rpx 0;
  245. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  246. }
  247. .menu-item {
  248. width: 50%;
  249. display: flex;
  250. flex-direction: column;
  251. align-items: center;
  252. padding: 24rpx 0;
  253. box-sizing: border-box;
  254. }
  255. .menu-icon-wrap {
  256. width: 80rpx;
  257. height: 80rpx;
  258. border-radius: 40rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. margin-bottom: 12rpx;
  263. }
  264. .icon-commission { background: #FEF3C7; }
  265. .icon-withdraw { background: #DBEAFE; }
  266. .icon-invite { background: #D1FAE5; }
  267. .icon-team { background: #FCE7F3; }
  268. .menu-icon-text {
  269. font-size: 36rpx;
  270. }
  271. .menu-text {
  272. font-size: 26rpx;
  273. color: #1E293B;
  274. font-weight: 500;
  275. }
  276. </style>