index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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="stats-cards">
  17. <view class="stat-card today-card">
  18. <text class="stat-value">{{ stats.todayCommission || 0 }}</text>
  19. <text class="stat-label">今日佣金(分)</text>
  20. </view>
  21. <view class="stat-card month-card">
  22. <text class="stat-value">{{ stats.monthCommission || 0 }}</text>
  23. <text class="stat-label">本月佣金(分)</text>
  24. </view>
  25. <view class="stat-card total-card">
  26. <text class="stat-value">{{ stats.totalCommission || 0 }}</text>
  27. <text class="stat-label">累计佣金(分)</text>
  28. </view>
  29. </view>
  30. <!-- 转化漏斗 -->
  31. <view class="funnel-section" v-if="funnelSteps && funnelSteps.length > 0">
  32. <text class="section-title">转化漏斗</text>
  33. <view class="funnel">
  34. <view class="funnel-step" v-for="(step, index) in funnelSteps" :key="index"
  35. :style="{width: step.width + '%'}">
  36. <text class="funnel-label">{{ step.label }}</text>
  37. <text class="funnel-count">{{ step.count }}</text>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 收益概览 -->
  42. <view class="earnings-card">
  43. <view class="earnings-header">
  44. <text class="earnings-title">收益总览</text>
  45. </view>
  46. <view class="earnings-body">
  47. <view class="earning-item">
  48. <text class="earning-label">累计佣金</text>
  49. <text class="earning-value orange" v-if="summary">{{ formatPriceWithSymbol(summary.totalCommission) }}</text>
  50. <text class="earning-value orange" v-else>{{ formatPriceWithSymbol(0) }}</text>
  51. </view>
  52. <view class="earning-divider"></view>
  53. <view class="earning-item">
  54. <text class="earning-label">可提现</text>
  55. <text class="earning-value blue" v-if="summary">{{ formatPriceWithSymbol(summary.availableAmount) }}</text>
  56. <text class="earning-value blue" v-else>{{ formatPriceWithSymbol(0) }}</text>
  57. </view>
  58. <view class="earning-divider"></view>
  59. <view class="earning-item">
  60. <text class="earning-label">待结算</text>
  61. <text class="earning-value green" v-if="summary">{{ formatPriceWithSymbol(summary.pendingAmount) }}</text>
  62. <text class="earning-value green" v-else>{{ formatPriceWithSymbol(0) }}</text>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- 功能入口 -->
  67. <view class="menu-grid">
  68. <view class="menu-item" @click="goCommission">
  69. <view class="menu-icon-wrap icon-commission">
  70. <text class="menu-icon-text">📋</text>
  71. </view>
  72. <text class="menu-text">佣金明细</text>
  73. </view>
  74. <view class="menu-item" @click="goWithdraw">
  75. <view class="menu-icon-wrap icon-withdraw">
  76. <text class="menu-icon-text">💰</text>
  77. </view>
  78. <text class="menu-text">立即提现</text>
  79. </view>
  80. <view class="menu-item" @click="goInvite">
  81. <view class="menu-icon-wrap icon-invite">
  82. <text class="menu-icon-text">👥</text>
  83. </view>
  84. <text class="menu-text">邀请好友</text>
  85. </view>
  86. <view class="menu-item" @click="goTeam">
  87. <view class="menu-icon-wrap icon-team">
  88. <text class="menu-icon-text">🤝</text>
  89. </view>
  90. <text class="menu-text">推广团队</text>
  91. </view>
  92. <view class="menu-item" @click="goLeaderboard">
  93. <view class="menu-icon-wrap icon-leaderboard">
  94. <text class="menu-icon-text">🏆</text>
  95. </view>
  96. <text class="menu-text">推广排行榜</text>
  97. </view>
  98. </view>
  99. <SharePoster :show="showPoster" :referralCode="referralCode" :qrCodeBase64="qrCodeBase64" :nickname="userNickname" :userAvatar="userAvatar" @close="showPoster = false" />
  100. </scroll-view>
  101. </template>
  102. <script>
  103. import { getReferralCode, getReferralSummary, getCommissionSummary, getInviteQrCode } from '../../utils/api.js'
  104. import SharePoster from '@/components/SharePoster.vue'
  105. export default {
  106. components: { SharePoster },
  107. data() {
  108. return {
  109. referralCode: '',
  110. totalEarnings: '0.00',
  111. availableAmount: '0.00',
  112. summary: null,
  113. showPoster: false,
  114. qrCodeBase64: '',
  115. userAvatar: '',
  116. userNickname: '',
  117. stats: {},
  118. funnelData: {},
  119. funnelSteps: []
  120. }
  121. },
  122. computed: {
  123. isLoggedIn() {
  124. return !!uni.getStorageSync('token')
  125. }
  126. },
  127. onLoad() {
  128. this.loadData()
  129. },
  130. onShow() {
  131. this.loadStats()
  132. this.loadFunnelData()
  133. },
  134. onShareAppMessage() {
  135. var code = this.referralCode || ''
  136. var path = '/pages/invite/join'
  137. if (code) {
  138. path = path + '?inviteCode=' + code
  139. }
  140. return {
  141. title: '我在浠艾福发现了好用的家庭成长工具,快来加入!',
  142. path: path,
  143. imageUrl: ''
  144. }
  145. },
  146. methods: {
  147. async loadData() {
  148. try {
  149. const codeRes = await getReferralCode()
  150. if (codeRes.data) {
  151. this.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  152. }
  153. } catch (e) {
  154. console.error('获取邀请码失败', e)
  155. }
  156. try {
  157. const summaryRes = await getReferralSummary()
  158. if (summaryRes.data) {
  159. this.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  160. }
  161. } catch (e) {
  162. console.error('获取邀请统计失败', e)
  163. }
  164. try {
  165. const comRes = await getCommissionSummary()
  166. if (comRes.data) {
  167. this.summary = comRes.data
  168. this.availableAmount = comRes.data.availableAmount || '0.00'
  169. }
  170. } catch (e) {
  171. console.error('获取佣金总览失败', e)
  172. }
  173. },
  174. loadStats: function() {
  175. var self = this
  176. var token = uni.getStorageSync('token')
  177. var baseUrl = ''
  178. try {
  179. var config = require('../../config.js')
  180. baseUrl = config.default.baseUrl || config.baseUrl || ''
  181. } catch (e) {
  182. baseUrl = ''
  183. }
  184. uni.request({
  185. url: baseUrl + '/api/commission/stats',
  186. method: 'POST',
  187. header: { 'Authorization': 'Bearer ' + token },
  188. success: function(res) {
  189. if (res.data && res.data.code === 200) {
  190. self.stats = res.data.data || {}
  191. }
  192. }
  193. })
  194. },
  195. loadFunnelData: function() {
  196. var self = this
  197. var token = uni.getStorageSync('token')
  198. var baseUrl = ''
  199. try {
  200. var config = require('../../config.js')
  201. baseUrl = config.default.baseUrl || config.baseUrl || ''
  202. } catch (e) {
  203. baseUrl = ''
  204. }
  205. uni.request({
  206. url: baseUrl + '/api/commission/funnel',
  207. method: 'POST',
  208. header: { 'Authorization': 'Bearer ' + token },
  209. success: function(res) {
  210. if (res.data && res.data.code === 200) {
  211. self.funnelData = res.data.data || {}
  212. self.buildFunnelSteps()
  213. }
  214. }
  215. })
  216. },
  217. buildFunnelSteps: function() {
  218. var data = this.funnelData
  219. var max = Math.max(data.invites || 1, data.registered || 0, data.purchased || 0, data.repeatPurchased || 0, data.totalOrders || 0)
  220. if (max < 1) max = 1
  221. this.funnelSteps = [
  222. { label: '邀请', count: data.invites || 0, width: 100 },
  223. { label: '注册', count: data.registered || 0, width: Math.round(((data.registered || 0) / max) * 100) },
  224. { label: '首购', count: data.purchased || 0, width: Math.round(((data.purchased || 0) / max) * 100) },
  225. { label: '复购', count: data.repeatPurchased || 0, width: Math.round(((data.repeatPurchased || 0) / max) * 100) },
  226. { label: '订单', count: data.totalOrders || 0, width: Math.round(((data.totalOrders || 0) / max) * 100) }
  227. ]
  228. },
  229. copyCode() {
  230. if (!this.referralCode) return
  231. uni.setClipboardData({
  232. data: this.referralCode,
  233. success: function() {
  234. uni.showToast({ title: '邀请码已复制', icon: 'success' })
  235. }
  236. })
  237. },
  238. async shareCard() {
  239. try {
  240. uni.showLoading({ title: '生成中...' })
  241. var res = await getInviteQrCode()
  242. if (res.data) {
  243. this.qrCodeBase64 = res.data.qrCodeBase64 || ''
  244. this.userNickname = uni.getStorageSync('nickname') || ''
  245. this.userAvatar = uni.getStorageSync('avatar') || ''
  246. this.showPoster = true
  247. }
  248. } catch (e) {
  249. uni.showToast({ title: '生成失败', icon: 'none' })
  250. } finally {
  251. uni.hideLoading()
  252. }
  253. },
  254. goCommission() {
  255. uni.navigateTo({ url: '/pages/promotion/commission' })
  256. },
  257. goWithdraw() {
  258. uni.navigateTo({ url: '/pages/promotion/withdraw' })
  259. },
  260. goInvite() {
  261. uni.navigateTo({ url: '/pages/promotion/invite' })
  262. },
  263. goTeam() {
  264. uni.navigateTo({ url: '/pages/promotion/team' })
  265. },
  266. goLeaderboard() {
  267. uni.navigateTo({ url: '/pages/promotion/leaderboard' })
  268. }
  269. }
  270. }
  271. </script>
  272. <style scoped>
  273. .container {
  274. padding: 30rpx;
  275. min-height: 100vh;
  276. background: #FFF7ED;
  277. }
  278. .invite-card {
  279. background: linear-gradient(135deg, #F97316, #EA580C);
  280. border-radius: 20rpx;
  281. padding: 40rpx;
  282. color: #fff;
  283. margin-bottom: 30rpx;
  284. }
  285. .code-section {
  286. margin-bottom: 30rpx;
  287. }
  288. .code-label {
  289. font-size: 24rpx;
  290. opacity: 0.85;
  291. }
  292. .code-value {
  293. display: flex;
  294. align-items: center;
  295. margin-top: 12rpx;
  296. }
  297. .code-text {
  298. font-size: 44rpx;
  299. font-weight: bold;
  300. letter-spacing: 6rpx;
  301. }
  302. .copy-icon {
  303. font-size: 36rpx;
  304. margin-left: 16rpx;
  305. opacity: 0.9;
  306. }
  307. .code-hint {
  308. font-size: 22rpx;
  309. opacity: 0.7;
  310. margin-top: 8rpx;
  311. display: block;
  312. }
  313. .share-btn {
  314. background: rgba(255,255,255,0.2);
  315. color: #fff;
  316. font-size: 28rpx;
  317. border-radius: 40rpx;
  318. height: 72rpx;
  319. line-height: 72rpx;
  320. border: 1rpx solid rgba(255,255,255,0.3);
  321. }
  322. .share-btn::after { border: none; }
  323. .share-btn:active { opacity: 0.8; }
  324. /* ===== 统计卡片 ===== */
  325. .stats-cards {
  326. display: flex;
  327. justify-content: space-between;
  328. margin-bottom: 30rpx;
  329. }
  330. .stat-card {
  331. flex: 1;
  332. margin: 0 10rpx;
  333. border-radius: 16rpx;
  334. padding: 24rpx 0;
  335. text-align: center;
  336. color: #fff;
  337. }
  338. .stat-card:first-child { margin-left: 0; }
  339. .stat-card:last-child { margin-right: 0; }
  340. .today-card { background: linear-gradient(135deg, #F97316, #FB923C); }
  341. .month-card { background: linear-gradient(135deg, #0EA5E9, #38BDF8); }
  342. .total-card { background: linear-gradient(135deg, #10B981, #34D399); }
  343. .stat-value {
  344. font-size: 36rpx;
  345. font-weight: bold;
  346. display: block;
  347. }
  348. .stat-label {
  349. font-size: 22rpx;
  350. opacity: 0.9;
  351. margin-top: 8rpx;
  352. display: block;
  353. }
  354. /* ===== 转化漏斗 ===== */
  355. .funnel-section {
  356. background: #fff;
  357. border-radius: 20rpx;
  358. padding: 30rpx;
  359. margin-bottom: 30rpx;
  360. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  361. }
  362. .section-title {
  363. font-size: 28rpx;
  364. font-weight: 600;
  365. color: #1E293B;
  366. margin-bottom: 20rpx;
  367. display: block;
  368. }
  369. .funnel {
  370. display: flex;
  371. flex-direction: column;
  372. align-items: center;
  373. }
  374. .funnel-step {
  375. background: linear-gradient(90deg, #F97316, #FB923C);
  376. border-radius: 12rpx;
  377. padding: 20rpx 0;
  378. margin-bottom: 16rpx;
  379. display: flex;
  380. justify-content: space-between;
  381. align-items: center;
  382. padding-left: 24rpx;
  383. padding-right: 24rpx;
  384. min-width: 60%;
  385. transition: all 0.3s ease;
  386. }
  387. .funnel-label {
  388. font-size: 26rpx;
  389. color: #fff;
  390. font-weight: 500;
  391. }
  392. .funnel-count {
  393. font-size: 28rpx;
  394. color: #fff;
  395. font-weight: bold;
  396. }
  397. /* ===== 收益总览 ===== */
  398. .earnings-card {
  399. background: #fff;
  400. border-radius: 20rpx;
  401. margin-bottom: 30rpx;
  402. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  403. overflow: hidden;
  404. }
  405. .earnings-header {
  406. padding: 24rpx 32rpx 0;
  407. }
  408. .earnings-title {
  409. font-size: 28rpx;
  410. font-weight: 600;
  411. color: #1E293B;
  412. }
  413. .earnings-body {
  414. display: flex;
  415. align-items: center;
  416. padding: 24rpx 32rpx 32rpx;
  417. }
  418. .earning-item {
  419. flex: 1;
  420. text-align: center;
  421. }
  422. .earning-label {
  423. font-size: 22rpx;
  424. color: #94A3B8;
  425. display: block;
  426. margin-bottom: 8rpx;
  427. }
  428. .earning-value {
  429. font-size: 36rpx;
  430. font-weight: bold;
  431. }
  432. .earning-value.orange { color: #F97316; }
  433. .earning-value.blue { color: #0EA5E9; }
  434. .earning-value.green { color: #10B981; }
  435. .earning-divider {
  436. width: 1rpx;
  437. height: 64rpx;
  438. background: #FED7AA;
  439. }
  440. /* ===== 功能入口 ===== */
  441. .menu-grid {
  442. display: flex;
  443. flex-wrap: wrap;
  444. background: #fff;
  445. border-radius: 20rpx;
  446. padding: 24rpx 0;
  447. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  448. }
  449. .menu-item {
  450. width: 50%;
  451. display: flex;
  452. flex-direction: column;
  453. align-items: center;
  454. padding: 24rpx 0;
  455. box-sizing: border-box;
  456. }
  457. .menu-icon-wrap {
  458. width: 80rpx;
  459. height: 80rpx;
  460. border-radius: 40rpx;
  461. display: flex;
  462. align-items: center;
  463. justify-content: center;
  464. margin-bottom: 12rpx;
  465. }
  466. .icon-commission { background: #FEF3C7; }
  467. .icon-withdraw { background: #DBEAFE; }
  468. .icon-invite { background: #D1FAE5; }
  469. .icon-team { background: #FCE7F3; }
  470. .icon-leaderboard { background: #FFF3CD; }
  471. .menu-icon-text {
  472. font-size: 36rpx;
  473. }
  474. .menu-text {
  475. font-size: 26rpx;
  476. color: #1E293B;
  477. font-weight: 500;
  478. }
  479. </style>