index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="container">
  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. </view>
  12. <button class="share-btn" @click="shareCard">📤 分享邀请卡</button>
  13. </view>
  14. <!-- 收益概览 -->
  15. <view class="earnings-card">
  16. <view class="earning-item">
  17. <text class="earning-label">累计收益</text>
  18. <text class="earning-value orange">¥{{ totalEarnings || '0.00' }}</text>
  19. </view>
  20. <view class="earning-divider"></view>
  21. <view class="earning-item">
  22. <text class="earning-label">可提现</text>
  23. <text class="earning-value blue">¥{{ availableAmount || '0.00' }}</text>
  24. </view>
  25. </view>
  26. <!-- 功能入口 -->
  27. <view class="menu-grid">
  28. <view class="menu-item" @click="goCommission">
  29. <text class="menu-icon">📋</text>
  30. <text class="menu-text">佣金明细</text>
  31. </view>
  32. <view class="menu-item" @click="goWithdraw">
  33. <text class="menu-icon">💰</text>
  34. <text class="menu-text">立即提现</text>
  35. </view>
  36. <view class="menu-item" @click="goInvite">
  37. <text class="menu-icon">👥</text>
  38. <text class="menu-text">邀请记录</text>
  39. </view>
  40. <view class="menu-item" @click="showTutorial">
  41. <text class="menu-icon">📖</text>
  42. <text class="menu-text">推广教程</text>
  43. </view>
  44. </view>
  45. <bottom-nav v-if="!isLoggedIn" current="promotion" />
  46. </view>
  47. </template>
  48. <script>
  49. import { getReferralCode, getReferralSummary } from '../../utils/api.js'
  50. export default {
  51. data() {
  52. return {
  53. referralCode: '',
  54. totalEarnings: '0.00',
  55. availableAmount: '0.00'
  56. }
  57. },
  58. computed: {
  59. isLoggedIn() {
  60. return !!uni.getStorageSync('token')
  61. }
  62. },
  63. onLoad() {
  64. this.loadData()
  65. },
  66. methods: {
  67. async loadData() {
  68. try {
  69. const codeRes = await getReferralCode()
  70. if (codeRes.data) {
  71. this.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  72. }
  73. } catch (e) {
  74. console.error('获取邀请码失败', e)
  75. }
  76. try {
  77. const summaryRes = await getReferralSummary()
  78. if (summaryRes.data) {
  79. this.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  80. }
  81. } catch (e) {
  82. console.error('获取邀请统计失败', e)
  83. }
  84. try {
  85. const { getCommissionSummary } = require('../../utils/api.js')
  86. const comRes = await getCommissionSummary()
  87. if (comRes.data) {
  88. this.availableAmount = comRes.data.availableAmount || '0.00'
  89. }
  90. } catch (e) {
  91. console.error('获取佣金总览失败', e)
  92. }
  93. },
  94. copyCode() {
  95. if (!this.referralCode) return
  96. uni.setClipboardData({
  97. data: this.referralCode,
  98. success: () => {
  99. uni.showToast({ title: '邀请码已复制', icon: 'success' })
  100. }
  101. })
  102. },
  103. shareCard() {
  104. uni.showToast({ title: '即将上线', icon: 'none' })
  105. },
  106. goCommission() {
  107. uni.navigateTo({ url: '/pages/promotion/commission' })
  108. },
  109. goWithdraw() {
  110. uni.navigateTo({ url: '/pages/promotion/withdraw' })
  111. },
  112. goInvite() {
  113. uni.navigateTo({ url: '/pages/promotion/invite' })
  114. },
  115. showTutorial() {
  116. uni.showToast({ title: '即将上线', icon: 'none' })
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .container {
  123. padding: 30rpx;
  124. min-height: 100vh;
  125. background: #f5f7fa;
  126. }
  127. .invite-card {
  128. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  129. border-radius: 20rpx;
  130. padding: 40rpx;
  131. color: #fff;
  132. margin-bottom: 30rpx;
  133. }
  134. .code-section {
  135. margin-bottom: 30rpx;
  136. }
  137. .code-label {
  138. font-size: 26rpx;
  139. opacity: 0.9;
  140. }
  141. .code-value {
  142. display: flex;
  143. align-items: center;
  144. margin-top: 16rpx;
  145. }
  146. .code-text {
  147. font-size: 40rpx;
  148. font-weight: bold;
  149. letter-spacing: 4rpx;
  150. }
  151. .copy-icon {
  152. font-size: 32rpx;
  153. margin-left: 16rpx;
  154. }
  155. .share-btn {
  156. background: rgba(255,255,255,0.2);
  157. color: #fff;
  158. font-size: 28rpx;
  159. border-radius: 40rpx;
  160. height: 72rpx;
  161. line-height: 72rpx;
  162. border: 1rpx solid rgba(255,255,255,0.3);
  163. }
  164. .share-btn::after { border: none; }
  165. .earnings-card {
  166. background: #fff;
  167. border-radius: 20rpx;
  168. padding: 40rpx;
  169. display: flex;
  170. align-items: center;
  171. margin-bottom: 30rpx;
  172. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
  173. }
  174. .earning-item {
  175. flex: 1;
  176. text-align: center;
  177. }
  178. .earning-label {
  179. font-size: 26rpx;
  180. color: #999;
  181. display: block;
  182. margin-bottom: 12rpx;
  183. }
  184. .earning-value {
  185. font-size: 44rpx;
  186. font-weight: bold;
  187. }
  188. .earning-value.orange { color: #F97316; }
  189. .earning-value.blue { color: #3A7CC4; }
  190. .earning-divider {
  191. width: 1rpx;
  192. height: 80rpx;
  193. background: #eee;
  194. }
  195. .menu-grid {
  196. display: flex;
  197. flex-wrap: wrap;
  198. background: #fff;
  199. border-radius: 20rpx;
  200. padding: 20rpx 0;
  201. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
  202. }
  203. .menu-item {
  204. width: 50%;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. padding: 30rpx 0;
  209. box-sizing: border-box;
  210. }
  211. .menu-icon {
  212. font-size: 48rpx;
  213. margin-bottom: 12rpx;
  214. }
  215. .menu-text {
  216. font-size: 28rpx;
  217. color: #333;
  218. }
  219. </style>