index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 class="menu-item" @click="goLeaderboard">
  67. <view class="menu-icon-wrap icon-leaderboard">
  68. <text class="menu-icon-text">🏆</text>
  69. </view>
  70. <text class="menu-text">推广排行榜</text>
  71. </view>
  72. </view>
  73. <SharePoster :show="showPoster" :referralCode="referralCode" :qrCodeBase64="qrCodeBase64" :nickname="userNickname" :userAvatar="userAvatar" @close="showPoster = false" />
  74. </scroll-view>
  75. </template>
  76. <script>
  77. import { getReferralCode, getReferralSummary, getCommissionSummary, getInviteQrCode } from '../../utils/api.js'
  78. import SharePoster from '@/components/SharePoster.vue'
  79. export default {
  80. components: { SharePoster },
  81. data() {
  82. return {
  83. referralCode: '',
  84. totalEarnings: '0.00',
  85. availableAmount: '0.00',
  86. summary: null,
  87. showPoster: false,
  88. qrCodeBase64: '',
  89. userAvatar: '',
  90. userNickname: ''
  91. }
  92. },
  93. computed: {
  94. isLoggedIn() {
  95. return !!uni.getStorageSync('token')
  96. }
  97. },
  98. onLoad() {
  99. this.loadData()
  100. },
  101. onShareAppMessage() {
  102. var code = this.referralCode || ''
  103. var path = '/pages/invite/join'
  104. if (code) {
  105. path = path + '?inviteCode=' + code
  106. }
  107. return {
  108. title: '我在浠艾福发现了好用的家庭成长工具,快来加入!',
  109. path: path,
  110. imageUrl: ''
  111. }
  112. },
  113. methods: {
  114. async loadData() {
  115. try {
  116. const codeRes = await getReferralCode()
  117. if (codeRes.data) {
  118. this.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  119. }
  120. } catch (e) {
  121. console.error('获取邀请码失败', e)
  122. }
  123. try {
  124. const summaryRes = await getReferralSummary()
  125. if (summaryRes.data) {
  126. this.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  127. }
  128. } catch (e) {
  129. console.error('获取邀请统计失败', e)
  130. }
  131. try {
  132. const comRes = await getCommissionSummary()
  133. if (comRes.data) {
  134. this.summary = comRes.data
  135. this.availableAmount = comRes.data.availableAmount || '0.00'
  136. }
  137. } catch (e) {
  138. console.error('获取佣金总览失败', e)
  139. }
  140. },
  141. copyCode() {
  142. if (!this.referralCode) return
  143. uni.setClipboardData({
  144. data: this.referralCode,
  145. success: function() {
  146. uni.showToast({ title: '邀请码已复制', icon: 'success' })
  147. }
  148. })
  149. },
  150. async shareCard() {
  151. try {
  152. uni.showLoading({ title: '生成中...' })
  153. var res = await getInviteQrCode()
  154. if (res.data) {
  155. this.qrCodeBase64 = res.data.qrCodeBase64 || ''
  156. this.userNickname = uni.getStorageSync('nickname') || ''
  157. this.userAvatar = uni.getStorageSync('avatar') || ''
  158. this.showPoster = true
  159. }
  160. } catch (e) {
  161. uni.showToast({ title: '生成失败', icon: 'none' })
  162. } finally {
  163. uni.hideLoading()
  164. }
  165. },
  166. goCommission() {
  167. uni.navigateTo({ url: '/pages/promotion/commission' })
  168. },
  169. goWithdraw() {
  170. uni.navigateTo({ url: '/pages/promotion/withdraw' })
  171. },
  172. goInvite() {
  173. uni.navigateTo({ url: '/pages/promotion/invite' })
  174. },
  175. goTeam() {
  176. uni.navigateTo({ url: '/pages/promotion/team' })
  177. },
  178. goLeaderboard() {
  179. uni.navigateTo({ url: '/pages/promotion/leaderboard' })
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped>
  185. .container {
  186. padding: 30rpx;
  187. min-height: 100vh;
  188. background: #FFF7ED;
  189. }
  190. .invite-card {
  191. background: linear-gradient(135deg, #F97316, #EA580C);
  192. border-radius: 20rpx;
  193. padding: 40rpx;
  194. color: #fff;
  195. margin-bottom: 30rpx;
  196. }
  197. .code-section {
  198. margin-bottom: 30rpx;
  199. }
  200. .code-label {
  201. font-size: 24rpx;
  202. opacity: 0.85;
  203. }
  204. .code-value {
  205. display: flex;
  206. align-items: center;
  207. margin-top: 12rpx;
  208. }
  209. .code-text {
  210. font-size: 44rpx;
  211. font-weight: bold;
  212. letter-spacing: 6rpx;
  213. }
  214. .copy-icon {
  215. font-size: 36rpx;
  216. margin-left: 16rpx;
  217. opacity: 0.9;
  218. }
  219. .code-hint {
  220. font-size: 22rpx;
  221. opacity: 0.7;
  222. margin-top: 8rpx;
  223. display: block;
  224. }
  225. .share-btn {
  226. background: rgba(255,255,255,0.2);
  227. color: #fff;
  228. font-size: 28rpx;
  229. border-radius: 40rpx;
  230. height: 72rpx;
  231. line-height: 72rpx;
  232. border: 1rpx solid rgba(255,255,255,0.3);
  233. }
  234. .share-btn::after { border: none; }
  235. .share-btn:active { opacity: 0.8; }
  236. /* ===== 收益总览 ===== */
  237. .earnings-card {
  238. background: #fff;
  239. border-radius: 20rpx;
  240. margin-bottom: 30rpx;
  241. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  242. overflow: hidden;
  243. }
  244. .earnings-header {
  245. padding: 24rpx 32rpx 0;
  246. }
  247. .earnings-title {
  248. font-size: 28rpx;
  249. font-weight: 600;
  250. color: #1E293B;
  251. }
  252. .earnings-body {
  253. display: flex;
  254. align-items: center;
  255. padding: 24rpx 32rpx 32rpx;
  256. }
  257. .earning-item {
  258. flex: 1;
  259. text-align: center;
  260. }
  261. .earning-label {
  262. font-size: 22rpx;
  263. color: #94A3B8;
  264. display: block;
  265. margin-bottom: 8rpx;
  266. }
  267. .earning-value {
  268. font-size: 36rpx;
  269. font-weight: bold;
  270. }
  271. .earning-value.orange { color: #F97316; }
  272. .earning-value.blue { color: #0EA5E9; }
  273. .earning-value.green { color: #10B981; }
  274. .earning-divider {
  275. width: 1rpx;
  276. height: 64rpx;
  277. background: #FED7AA;
  278. }
  279. /* ===== 功能入口 ===== */
  280. .menu-grid {
  281. display: flex;
  282. flex-wrap: wrap;
  283. background: #fff;
  284. border-radius: 20rpx;
  285. padding: 24rpx 0;
  286. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  287. }
  288. .menu-item {
  289. width: 50%;
  290. display: flex;
  291. flex-direction: column;
  292. align-items: center;
  293. padding: 24rpx 0;
  294. box-sizing: border-box;
  295. }
  296. .menu-icon-wrap {
  297. width: 80rpx;
  298. height: 80rpx;
  299. border-radius: 40rpx;
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. margin-bottom: 12rpx;
  304. }
  305. .icon-commission { background: #FEF3C7; }
  306. .icon-withdraw { background: #DBEAFE; }
  307. .icon-invite { background: #D1FAE5; }
  308. .icon-team { background: #FCE7F3; }
  309. .icon-leaderboard { background: #FFF3CD; }
  310. .menu-icon-text {
  311. font-size: 36rpx;
  312. }
  313. .menu-text {
  314. font-size: 26rpx;
  315. color: #1E293B;
  316. font-weight: 500;
  317. }
  318. </style>