index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <view class="page-commission" :class="themeClass">
  3. <!-- Loading -->
  4. <view v-if="loading" class="loading-state">
  5. <text class="loading-text">加载中...</text>
  6. </view>
  7. <template v-else>
  8. <!-- Error / permission gate (US-6.5 §2-3) -->
  9. <view v-if="error" class="error-state">
  10. <text class="error-icon">🔒</text>
  11. <text class="error-text">{{ error }}</text>
  12. </view>
  13. <template v-else>
  14. <!-- ===== 我的收益 ===== -->
  15. <view class="section earnings-section">
  16. <view class="section-header">
  17. <text class="section-title">💰 我的收益</text>
  18. </view>
  19. <view class="earnings-grid">
  20. <view class="earn-item">
  21. <text class="earn-label">累计收益</text>
  22. <text class="earn-value accent">¥{{ formatMoney(stats.totalEarnings) }}</text>
  23. </view>
  24. <view class="earn-item">
  25. <text class="earn-label">可提现余额</text>
  26. <text class="earn-value">¥{{ formatMoney(stats.availableBalance) }}</text>
  27. </view>
  28. <view class="earn-item">
  29. <text class="earn-label">本月收益</text>
  30. <text class="earn-value">¥{{ formatMoney(stats.monthEarnings) }}</text>
  31. </view>
  32. <view class="earn-item">
  33. <text class="earn-label">今日预估</text>
  34. <text class="earn-value">¥{{ formatMoney(stats.todayEstimate) }}</text>
  35. </view>
  36. </view>
  37. <!-- L1/L2 commission breakdown -->
  38. <view class="earnings-breakdown" v-if="l1Total > 0 || l2Total > 0">
  39. <view class="breakdown-row">
  40. <text class="breakdown-label">一级推广佣金</text>
  41. <text class="breakdown-value">¥{{ formatMoney(l1Total) }}</text>
  42. </view>
  43. <view class="breakdown-row">
  44. <text class="breakdown-label">二级推广佣金</text>
  45. <text class="breakdown-value">¥{{ formatMoney(l2Total) }}</text>
  46. </view>
  47. </view>
  48. <!-- Withdraw notice -->
  49. <view class="withdraw-notice">
  50. <text class="withdraw-notice-text">💳 提现功能即将开放,敬请期待</text>
  51. </view>
  52. </view>
  53. <!-- ===== 我的团队 ===== -->
  54. <view class="section team-section">
  55. <view class="section-header">
  56. <text class="section-title">👥 我的团队</text>
  57. <text v-if="team.length > 0" class="section-sub" @click="goTeamList">查看全部 →</text>
  58. </view>
  59. <view class="team-grid">
  60. <view class="team-stat">
  61. <text class="stat-num">{{ stats.directInvites }}</text>
  62. <text class="stat-label">直接下级</text>
  63. </view>
  64. <view class="team-stat">
  65. <text class="stat-num">{{ stats.indirectInvites }}</text>
  66. <text class="stat-label">间接下级</text>
  67. </view>
  68. <view class="team-stat">
  69. <text class="stat-num">{{ stats.convertedCount }}</text>
  70. <text class="stat-label">下级升级</text>
  71. </view>
  72. <view class="team-stat">
  73. <text class="stat-num">{{ stats.totalCommissions }}</text>
  74. <text class="stat-label">佣金笔数</text>
  75. </view>
  76. </view>
  77. <!-- Recent team members preview -->
  78. <view v-if="team.length > 0" class="team-preview">
  79. <view v-for="(m, idx) in team.slice(0, 5)" :key="idx" class="member-row">
  80. <image class="member-avatar" :src="m.avatarUrl || '/static/default-avatar.png'" mode="aspectFill" />
  81. <view class="member-info">
  82. <text class="member-name">{{ m.nickname || '微信用户' }}</text>
  83. <text class="member-date">{{ formatDate(m.createdAt) }} 加入</text>
  84. </view>
  85. <text v-if="m.isVip" class="member-vip">VIP</text>
  86. </view>
  87. </view>
  88. <view v-else class="empty-state">
  89. <text class="empty-text">暂无推广成员,快去分享推广码吧</text>
  90. </view>
  91. </view>
  92. <!-- ===== 推广工具 ===== -->
  93. <view class="section">
  94. <view class="section-header">
  95. <text class="section-title">📤 推广工具</text>
  96. </view>
  97. <view class="tool-card" @click="showQrActions">
  98. <view class="tool-left">
  99. <text class="tool-icon">▣</text>
  100. <view>
  101. <text class="tool-name">我的推广二维码</text>
  102. <text class="tool-desc">点击保存/分享</text>
  103. </view>
  104. </view>
  105. <view class="tool-right">
  106. <text class="ref-code-tag">{{ userStore.referralCode }}</text>
  107. <text class="tool-arrow">›</text>
  108. </view>
  109. </view>
  110. <view class="tool-card" @click="copyReferral">
  111. <view class="tool-left">
  112. <text class="tool-icon">📋</text>
  113. <view>
  114. <text class="tool-name">复制推广码</text>
  115. <text class="tool-desc">{{ userStore.referralCode || '加载中' }}</text>
  116. </view>
  117. </view>
  118. <text class="tool-arrow">›</text>
  119. </view>
  120. <view class="tool-card" @click="copyPromoLink">
  121. <view class="tool-left">
  122. <text class="tool-icon">🔗</text>
  123. <view>
  124. <text class="tool-name">复制推广链接</text>
  125. <text class="tool-desc">分享链接,对方点击自动绑定</text>
  126. </view>
  127. </view>
  128. <text class="tool-arrow">›</text>
  129. </view>
  130. </view>
  131. <!-- ===== 佣金明细 ===== -->
  132. <view class="section">
  133. <view class="section-header">
  134. <text class="section-title">📋 佣金明细</text>
  135. </view>
  136. <view v-if="commissions.length === 0" class="empty-state">
  137. <text class="empty-text">暂无佣金记录</text>
  138. </view>
  139. <view v-for="(c, idx) in commissions" :key="idx" class="commission-row">
  140. <view class="comm-left">
  141. <text class="comm-amount">+¥{{ (c.amount / 100).toFixed(2) }}</text>
  142. <text class="comm-level">{{ c.level === 1 ? '一级推广' : '二级推广' }}</text>
  143. <text v-if="c.remark" class="comm-remark">{{ c.remark }}</text>
  144. </view>
  145. <view class="comm-right">
  146. <text class="comm-status" :class="'status-' + c.status">
  147. {{ statusText(c.status) }}
  148. </text>
  149. <text class="comm-date">{{ formatDate(c.createdAt) }}</text>
  150. </view>
  151. </view>
  152. </view>
  153. <!-- QR code modal (hidden by default, shown via action sheet) -->
  154. </template>
  155. </template>
  156. </view>
  157. </template>
  158. <script setup>
  159. import { ref, computed, onMounted } from 'vue'
  160. import { onPullDownRefresh } from '@dcloudio/uni-app'
  161. import { useUserStore } from '@/stores/user'
  162. import { commissionApi } from '@/utils/api'
  163. import { useTheme } from '@/composables/useThemeStyle'
  164. const { themeClass } = useTheme()
  165. const userStore = useUserStore()
  166. const commissions = ref([])
  167. const team = ref([])
  168. const loading = ref(true)
  169. const error = ref('')
  170. const stats = ref({
  171. totalEarnings: 0,
  172. availableBalance: 0,
  173. todayEstimate: 0,
  174. monthEarnings: 0,
  175. directInvites: 0,
  176. indirectInvites: 0,
  177. convertedCount: 0,
  178. totalCommissions: 0
  179. })
  180. // L1/L2 commission breakdown from commissions list
  181. const l1Total = computed(() => {
  182. return commissions.value
  183. .filter(c => c.level === 1 && c.status === 'settled')
  184. .reduce((sum, c) => sum + (c.amount || 0), 0)
  185. })
  186. const l2Total = computed(() => {
  187. return commissions.value
  188. .filter(c => c.level === 2 && c.status === 'settled')
  189. .reduce((sum, c) => sum + (c.amount || 0), 0)
  190. })
  191. // US-6.5 §2-3: Only paid users can access
  192. onMounted(async () => {
  193. if (!userStore.isVipActive) {
  194. loading.value = false
  195. error.value = '开通会员后可查看推广收益'
  196. return
  197. }
  198. await fetchData()
  199. })
  200. async function fetchData() {
  201. error.value = ''
  202. loading.value = true
  203. try {
  204. const [listData, teamData, statsData] = await Promise.all([
  205. commissionApi.list(),
  206. commissionApi.team(),
  207. commissionApi.stats()
  208. ])
  209. commissions.value = listData || []
  210. team.value = teamData || []
  211. if (statsData) {
  212. stats.value = statsData
  213. }
  214. } catch (e) {
  215. error.value = '网络错误,请下拉刷新重试'
  216. } finally {
  217. loading.value = false
  218. }
  219. }
  220. // Pull-to-refresh (US-6.5 §24)
  221. onPullDownRefresh(async () => {
  222. if (!userStore.isVipActive) return
  223. await fetchData()
  224. uni.stopPullDownRefresh()
  225. })
  226. function formatMoney(cents) {
  227. if (cents == null) return '0.00'
  228. return (cents / 100).toFixed(2)
  229. }
  230. function showTeamDetail() {
  231. uni.showModal({
  232. title: '推广团队',
  233. content: `直接下级 ${stats.value.directInvites} 人\n间接下级 ${stats.value.indirectInvites} 人\n已升级为VIP ${stats.value.convertedCount} 人`,
  234. showCancel: false
  235. })
  236. }
  237. function goWithdraw() {
  238. uni.navigateTo({ url: '/pages/withdraw/index' })
  239. }
  240. function goTeamList() {
  241. uni.showActionSheet({
  242. itemList: ['查看全部成员', '收起'],
  243. success: (res) => {
  244. if (res.tapIndex === 0) {
  245. // Scroll to team section by showing a modal with full list
  246. if (team.value.length > 10) {
  247. uni.showModal({
  248. title: '推广团队',
  249. content: `直接下级 ${stats.value.directInvites} 人\n间接下级 ${stats.value.indirectInvites} 人\n已升级VIP ${stats.value.convertedCount} 人\n\n共 ${team.value.length} 名成员`,
  250. showCancel: false
  251. })
  252. }
  253. }
  254. }
  255. })
  256. }
  257. function copyPromoLink() {
  258. if (!userStore.referralCode) return
  259. const link = `pages/index/index?ref=${userStore.referralCode}`
  260. uni.setClipboardData({
  261. data: link,
  262. success: () => uni.showToast({ title: '已复制推广链接', icon: 'success' })
  263. })
  264. }
  265. function showQrActions() {
  266. if (!userStore.referralCode) return
  267. uni.showActionSheet({
  268. itemList: ['复制推广码', '保存二维码到相册'],
  269. success: (res) => {
  270. if (res.tapIndex === 0) {
  271. copyReferral()
  272. } else if (res.tapIndex === 1) {
  273. saveQrToAlbum()
  274. }
  275. }
  276. })
  277. }
  278. function copyReferral() {
  279. if (userStore.referralCode) {
  280. uni.setClipboardData({
  281. data: userStore.referralCode,
  282. success: () => uni.showToast({ title: '已复制推广码', icon: 'success' })
  283. })
  284. }
  285. }
  286. function saveQrToAlbum() {
  287. const url = `https://api.qrserver.com/v1/create-qr-code/?size=560x560&data=${userStore.referralCode}`
  288. uni.showLoading({ title: '保存中...' })
  289. uni.downloadFile({
  290. url,
  291. success: (res) => {
  292. if (res.statusCode === 200) {
  293. uni.saveImageToPhotosAlbum({
  294. filePath: res.tempFilePath,
  295. success: () => {
  296. uni.hideLoading()
  297. uni.showToast({ title: '已保存到相册', icon: 'success' })
  298. },
  299. fail: () => {
  300. uni.hideLoading()
  301. uni.showToast({ title: '保存失败,请检查相册权限', icon: 'none' })
  302. }
  303. })
  304. } else {
  305. uni.hideLoading()
  306. uni.showToast({ title: '二维码生成失败', icon: 'none' })
  307. }
  308. },
  309. fail: () => {
  310. uni.hideLoading()
  311. uni.showToast({ title: '网络错误', icon: 'none' })
  312. }
  313. })
  314. }
  315. function statusText(status) {
  316. const map = { settled: '已结算', pending: '处理中', withdrawn: '已提现', available: '可提现' }
  317. return map[status] || status
  318. }
  319. function formatDate(dateStr) {
  320. if (!dateStr) return ''
  321. const d = new Date(dateStr)
  322. return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
  323. }
  324. </script>
  325. <style scoped lang="scss">
  326. .page-commission {
  327. min-height: 100vh;
  328. background: var(--color-bg);
  329. padding: 16px;
  330. }
  331. /* Error / permission gate */
  332. .error-state {
  333. padding: 80px 20px;
  334. text-align: center;
  335. }
  336. .error-icon {
  337. font-size: 40px;
  338. display: block;
  339. margin-bottom: 12px;
  340. }
  341. .error-text {
  342. font-size: 14px;
  343. color: var(--color-text-secondary);
  344. }
  345. /* Loading */
  346. .loading-state {
  347. padding: 60px 0;
  348. text-align: center;
  349. }
  350. .loading-text {
  351. font-size: 14px;
  352. color: var(--color-text-secondary);
  353. }
  354. /* Section */
  355. .section {
  356. background: var(--color-bg-card);
  357. border-radius: 14px;
  358. padding: 16px;
  359. margin-bottom: 16px;
  360. }
  361. .section-header {
  362. display: flex;
  363. justify-content: space-between;
  364. align-items: center;
  365. margin-bottom: 14px;
  366. }
  367. .section-title {
  368. font-size: 16px;
  369. font-weight: 700;
  370. color: var(--color-text-primary);
  371. }
  372. .section-sub {
  373. font-size: 12px;
  374. color: var(--color-info);
  375. font-weight: 500;
  376. }
  377. /* ===== Earnings ===== */
  378. .earnings-section {
  379. background: linear-gradient(135deg, var(--color-brand), #2D4A7A);
  380. }
  381. .earnings-section .section-title {
  382. color: rgba(255,255,255,0.9);
  383. }
  384. .earnings-grid {
  385. display: grid;
  386. grid-template-columns: 1fr 1fr;
  387. gap: 12px;
  388. }
  389. .earn-item {
  390. text-align: center;
  391. padding: 8px 0;
  392. }
  393. .earn-label {
  394. font-size: 11px;
  395. color: rgba(255,255,255,0.55);
  396. display: block;
  397. margin-bottom: 4px;
  398. }
  399. .earn-value {
  400. font-size: 22px;
  401. font-weight: 700;
  402. color: #fff;
  403. display: block;
  404. }
  405. .earn-value.accent {
  406. color: var(--color-gold);
  407. }
  408. .withdraw-bar {
  409. margin-top: 14px;
  410. padding: 10px 0;
  411. background: rgba(255,255,255,0.06);
  412. border: 1px solid rgba(251,191,36,0.15);
  413. border-radius: 10px;
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. gap: 6px;
  418. }
  419. .withdraw-text {
  420. font-size: 14px;
  421. font-weight: 600;
  422. color: var(--color-gold);
  423. }
  424. .withdraw-arrow {
  425. font-size: 16px;
  426. color: var(--color-gold);
  427. }
  428. /* ===== Earnings Breakdown ===== */
  429. .earnings-breakdown {
  430. margin-top: 12px;
  431. padding: 10px 14px;
  432. background: rgba(255,255,255,0.03);
  433. border-radius: 8px;
  434. }
  435. .breakdown-row {
  436. display: flex;
  437. justify-content: space-between;
  438. align-items: center;
  439. padding: 4px 0;
  440. }
  441. .breakdown-label {
  442. font-size: 12px;
  443. color: rgba(255,255,255,0.5);
  444. }
  445. .breakdown-value {
  446. font-size: 13px;
  447. font-weight: 500;
  448. color: rgba(255,255,255,0.75);
  449. }
  450. /* ===== Withdraw Notice ===== */
  451. .withdraw-notice {
  452. margin-top: 14px;
  453. padding: 10px 0;
  454. background: rgba(255,255,255,0.03);
  455. border: 1px solid rgba(255,255,255,0.06);
  456. border-radius: 10px;
  457. display: flex;
  458. align-items: center;
  459. justify-content: center;
  460. }
  461. .withdraw-notice-text {
  462. font-size: 13px;
  463. color: rgba(255,255,255,0.4);
  464. }
  465. /* ===== Team ===== */
  466. .team-grid {
  467. display: grid;
  468. grid-template-columns: 1fr 1fr 1fr 1fr;
  469. gap: 8px;
  470. margin-bottom: 14px;
  471. }
  472. .team-stat {
  473. text-align: center;
  474. padding: 8px 0;
  475. }
  476. .stat-num {
  477. font-size: 24px;
  478. font-weight: 700;
  479. color: var(--color-brand);
  480. display: block;
  481. }
  482. .stat-label {
  483. font-size: 11px;
  484. color: var(--color-text-secondary);
  485. margin-top: 2px;
  486. display: block;
  487. }
  488. .team-preview {
  489. border-top: 1px solid var(--color-bg-input);
  490. padding-top: 10px;
  491. }
  492. .member-row {
  493. display: flex;
  494. align-items: center;
  495. padding: 8px 0;
  496. border-bottom: 1px solid var(--color-bg);
  497. }
  498. .member-row:last-child { border-bottom: none; }
  499. .member-avatar {
  500. width: 32px;
  501. height: 32px;
  502. border-radius: 50%;
  503. margin-right: 10px;
  504. flex-shrink: 0;
  505. }
  506. .member-info { flex: 1; }
  507. .member-name {
  508. font-size: 13px;
  509. color: var(--color-text-primary);
  510. display: block;
  511. }
  512. .member-date {
  513. font-size: 11px;
  514. color: var(--color-text-secondary);
  515. margin-top: 1px;
  516. display: block;
  517. }
  518. .member-vip {
  519. font-size: 10px;
  520. color: var(--color-gold);
  521. background: #FEF3C7;
  522. padding: 2px 8px;
  523. border-radius: 4px;
  524. font-weight: 500;
  525. }
  526. /* ===== Tools ===== */
  527. .tool-card {
  528. display: flex;
  529. justify-content: space-between;
  530. align-items: center;
  531. padding: 14px 0;
  532. border-bottom: 1px solid var(--color-bg-input);
  533. }
  534. .tool-card:last-child { border-bottom: none; }
  535. .tool-left {
  536. display: flex;
  537. align-items: center;
  538. gap: 12px;
  539. flex: 1;
  540. }
  541. .tool-icon {
  542. width: 36px;
  543. height: 36px;
  544. border-radius: 8px;
  545. background: var(--color-bg);
  546. display: flex;
  547. align-items: center;
  548. justify-content: center;
  549. font-size: 16px;
  550. color: var(--color-brand);
  551. flex-shrink: 0;
  552. }
  553. .tool-name {
  554. font-size: 14px;
  555. font-weight: 600;
  556. color: var(--color-text-primary);
  557. display: block;
  558. }
  559. .tool-desc {
  560. font-size: 11px;
  561. color: var(--color-text-secondary);
  562. margin-top: 2px;
  563. display: block;
  564. }
  565. .tool-right {
  566. display: flex;
  567. align-items: center;
  568. gap: 8px;
  569. }
  570. .ref-code-tag {
  571. font-size: 12px;
  572. font-weight: 600;
  573. color: var(--color-gold);
  574. background: var(--color-gold-bg);
  575. padding: 2px 10px;
  576. border-radius: 4px;
  577. letter-spacing: 1px;
  578. }
  579. .tool-arrow {
  580. font-size: 18px;
  581. color: var(--color-text-secondary);
  582. }
  583. /* ===== Commission List ===== */
  584. .commission-row {
  585. display: flex;
  586. justify-content: space-between;
  587. align-items: center;
  588. padding: 12px 0;
  589. border-bottom: 1px solid var(--color-bg-input);
  590. }
  591. .commission-row:last-child { border-bottom: none; }
  592. .comm-left { flex: 1; }
  593. .comm-amount {
  594. font-size: 15px;
  595. font-weight: 600;
  596. color: var(--color-success);
  597. display: block;
  598. }
  599. .comm-level {
  600. font-size: 12px;
  601. color: var(--color-text-secondary);
  602. margin-top: 2px;
  603. display: block;
  604. }
  605. .comm-remark {
  606. font-size: 11px;
  607. color: var(--color-text-tertiary);
  608. margin-top: 1px;
  609. display: block;
  610. }
  611. .comm-right { text-align: right; }
  612. .comm-status {
  613. font-size: 11px;
  614. padding: 2px 8px;
  615. border-radius: 4px;
  616. display: inline-block;
  617. margin-bottom: 2px;
  618. }
  619. .comm-status.status-settled { background: var(--color-success-bg); color: var(--color-success); }
  620. .comm-status.status-pending { background: var(--color-warning-bg); color: var(--color-warning); }
  621. .comm-status.status-withdrawn { background: var(--color-bg-input); color: var(--color-text-secondary); }
  622. .comm-status.status-available { background: var(--color-info-bg); color: var(--color-info); }
  623. .comm-date {
  624. font-size: 11px;
  625. color: var(--color-text-secondary);
  626. display: block;
  627. }
  628. /* Empty State */
  629. .empty-state {
  630. padding: 24px 0;
  631. text-align: center;
  632. }
  633. .empty-text {
  634. font-size: 13px;
  635. color: var(--color-text-secondary);
  636. }
  637. </style>