index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <view class="page-commission">
  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. const userStore = useUserStore()
  164. const commissions = ref([])
  165. const team = ref([])
  166. const loading = ref(true)
  167. const error = ref('')
  168. const stats = ref({
  169. totalEarnings: 0,
  170. availableBalance: 0,
  171. todayEstimate: 0,
  172. monthEarnings: 0,
  173. directInvites: 0,
  174. indirectInvites: 0,
  175. convertedCount: 0,
  176. totalCommissions: 0
  177. })
  178. // L1/L2 commission breakdown from commissions list
  179. const l1Total = computed(() => {
  180. return commissions.value
  181. .filter(c => c.level === 1 && c.status === 'settled')
  182. .reduce((sum, c) => sum + (c.amount || 0), 0)
  183. })
  184. const l2Total = computed(() => {
  185. return commissions.value
  186. .filter(c => c.level === 2 && c.status === 'settled')
  187. .reduce((sum, c) => sum + (c.amount || 0), 0)
  188. })
  189. // US-6.5 §2-3: Only paid users can access
  190. onMounted(async () => {
  191. if (!userStore.isVipActive) {
  192. loading.value = false
  193. error.value = '开通会员后可查看推广收益'
  194. return
  195. }
  196. await fetchData()
  197. })
  198. async function fetchData() {
  199. error.value = ''
  200. loading.value = true
  201. try {
  202. const [listData, teamData, statsData] = await Promise.all([
  203. commissionApi.list(),
  204. commissionApi.team(),
  205. commissionApi.stats()
  206. ])
  207. commissions.value = listData || []
  208. team.value = teamData || []
  209. if (statsData) {
  210. stats.value = statsData
  211. }
  212. } catch (e) {
  213. error.value = '网络错误,请下拉刷新重试'
  214. } finally {
  215. loading.value = false
  216. }
  217. }
  218. // Pull-to-refresh (US-6.5 §24)
  219. onPullDownRefresh(async () => {
  220. if (!userStore.isVipActive) return
  221. await fetchData()
  222. uni.stopPullDownRefresh()
  223. })
  224. function formatMoney(cents) {
  225. if (cents == null) return '0.00'
  226. return (cents / 100).toFixed(2)
  227. }
  228. function showTeamDetail() {
  229. uni.showModal({
  230. title: '推广团队',
  231. content: `直接下级 ${stats.value.directInvites} 人\n间接下级 ${stats.value.indirectInvites} 人\n已升级为VIP ${stats.value.convertedCount} 人`,
  232. showCancel: false
  233. })
  234. }
  235. function goWithdraw() {
  236. uni.navigateTo({ url: '/pages/withdraw/index' })
  237. }
  238. function goTeamList() {
  239. uni.showActionSheet({
  240. itemList: ['查看全部成员', '收起'],
  241. success: (res) => {
  242. if (res.tapIndex === 0) {
  243. // Scroll to team section by showing a modal with full list
  244. if (team.value.length > 10) {
  245. uni.showModal({
  246. title: '推广团队',
  247. content: `直接下级 ${stats.value.directInvites} 人\n间接下级 ${stats.value.indirectInvites} 人\n已升级VIP ${stats.value.convertedCount} 人\n\n共 ${team.value.length} 名成员`,
  248. showCancel: false
  249. })
  250. }
  251. }
  252. }
  253. })
  254. }
  255. function copyPromoLink() {
  256. if (!userStore.referralCode) return
  257. const link = `pages/index/index?ref=${userStore.referralCode}`
  258. uni.setClipboardData({
  259. data: link,
  260. success: () => uni.showToast({ title: '已复制推广链接', icon: 'success' })
  261. })
  262. }
  263. function showQrActions() {
  264. if (!userStore.referralCode) return
  265. uni.showActionSheet({
  266. itemList: ['复制推广码', '保存二维码到相册'],
  267. success: (res) => {
  268. if (res.tapIndex === 0) {
  269. copyReferral()
  270. } else if (res.tapIndex === 1) {
  271. saveQrToAlbum()
  272. }
  273. }
  274. })
  275. }
  276. function copyReferral() {
  277. if (userStore.referralCode) {
  278. uni.setClipboardData({
  279. data: userStore.referralCode,
  280. success: () => uni.showToast({ title: '已复制推广码', icon: 'success' })
  281. })
  282. }
  283. }
  284. function saveQrToAlbum() {
  285. const url = `https://api.qrserver.com/v1/create-qr-code/?size=560x560&data=${userStore.referralCode}`
  286. uni.showLoading({ title: '保存中...' })
  287. uni.downloadFile({
  288. url,
  289. success: (res) => {
  290. if (res.statusCode === 200) {
  291. uni.saveImageToPhotosAlbum({
  292. filePath: res.tempFilePath,
  293. success: () => {
  294. uni.hideLoading()
  295. uni.showToast({ title: '已保存到相册', icon: 'success' })
  296. },
  297. fail: () => {
  298. uni.hideLoading()
  299. uni.showToast({ title: '保存失败,请检查相册权限', icon: 'none' })
  300. }
  301. })
  302. } else {
  303. uni.hideLoading()
  304. uni.showToast({ title: '二维码生成失败', icon: 'none' })
  305. }
  306. },
  307. fail: () => {
  308. uni.hideLoading()
  309. uni.showToast({ title: '网络错误', icon: 'none' })
  310. }
  311. })
  312. }
  313. function statusText(status) {
  314. const map = { settled: '已结算', pending: '处理中', withdrawn: '已提现', available: '可提现' }
  315. return map[status] || status
  316. }
  317. function formatDate(dateStr) {
  318. if (!dateStr) return ''
  319. const d = new Date(dateStr)
  320. return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
  321. }
  322. </script>
  323. <style scoped lang="scss">
  324. .page-commission {
  325. min-height: 100vh;
  326. background: var(--color-bg);
  327. padding: 16px;
  328. }
  329. /* Error / permission gate */
  330. .error-state {
  331. padding: 80px 20px;
  332. text-align: center;
  333. }
  334. .error-icon {
  335. font-size: 40px;
  336. display: block;
  337. margin-bottom: 12px;
  338. }
  339. .error-text {
  340. font-size: 14px;
  341. color: var(--color-text-secondary);
  342. }
  343. /* Loading */
  344. .loading-state {
  345. padding: 60px 0;
  346. text-align: center;
  347. }
  348. .loading-text {
  349. font-size: 14px;
  350. color: var(--color-text-secondary);
  351. }
  352. /* Section */
  353. .section {
  354. background: #fff;
  355. border-radius: 14px;
  356. padding: 16px;
  357. margin-bottom: 16px;
  358. }
  359. .section-header {
  360. display: flex;
  361. justify-content: space-between;
  362. align-items: center;
  363. margin-bottom: 14px;
  364. }
  365. .section-title {
  366. font-size: 16px;
  367. font-weight: 700;
  368. color: var(--color-text-primary);
  369. }
  370. .section-sub {
  371. font-size: 12px;
  372. color: #3B82F6;
  373. font-weight: 500;
  374. }
  375. /* ===== Earnings ===== */
  376. .earnings-section {
  377. background: linear-gradient(135deg, var(--color-brand), #2D4A7A);
  378. }
  379. .earnings-section .section-title {
  380. color: rgba(255,255,255,0.9);
  381. }
  382. .earnings-grid {
  383. display: grid;
  384. grid-template-columns: 1fr 1fr;
  385. gap: 12px;
  386. }
  387. .earn-item {
  388. text-align: center;
  389. padding: 8px 0;
  390. }
  391. .earn-label {
  392. font-size: 11px;
  393. color: rgba(255,255,255,0.55);
  394. display: block;
  395. margin-bottom: 4px;
  396. }
  397. .earn-value {
  398. font-size: 22px;
  399. font-weight: 700;
  400. color: #fff;
  401. display: block;
  402. }
  403. .earn-value.accent {
  404. color: var(--color-gold);
  405. }
  406. .withdraw-bar {
  407. margin-top: 14px;
  408. padding: 10px 0;
  409. background: rgba(255,255,255,0.06);
  410. border: 1px solid rgba(251,191,36,0.15);
  411. border-radius: 10px;
  412. display: flex;
  413. align-items: center;
  414. justify-content: center;
  415. gap: 6px;
  416. }
  417. .withdraw-text {
  418. font-size: 14px;
  419. font-weight: 600;
  420. color: var(--color-gold);
  421. }
  422. .withdraw-arrow {
  423. font-size: 16px;
  424. color: var(--color-gold);
  425. }
  426. /* ===== Earnings Breakdown ===== */
  427. .earnings-breakdown {
  428. margin-top: 12px;
  429. padding: 10px 14px;
  430. background: rgba(255,255,255,0.03);
  431. border-radius: 8px;
  432. }
  433. .breakdown-row {
  434. display: flex;
  435. justify-content: space-between;
  436. align-items: center;
  437. padding: 4px 0;
  438. }
  439. .breakdown-label {
  440. font-size: 12px;
  441. color: rgba(255,255,255,0.5);
  442. }
  443. .breakdown-value {
  444. font-size: 13px;
  445. font-weight: 500;
  446. color: rgba(255,255,255,0.75);
  447. }
  448. /* ===== Withdraw Notice ===== */
  449. .withdraw-notice {
  450. margin-top: 14px;
  451. padding: 10px 0;
  452. background: rgba(255,255,255,0.03);
  453. border: 1px solid rgba(255,255,255,0.06);
  454. border-radius: 10px;
  455. display: flex;
  456. align-items: center;
  457. justify-content: center;
  458. }
  459. .withdraw-notice-text {
  460. font-size: 13px;
  461. color: rgba(255,255,255,0.4);
  462. }
  463. /* ===== Team ===== */
  464. .team-grid {
  465. display: grid;
  466. grid-template-columns: 1fr 1fr 1fr 1fr;
  467. gap: 8px;
  468. margin-bottom: 14px;
  469. }
  470. .team-stat {
  471. text-align: center;
  472. padding: 8px 0;
  473. }
  474. .stat-num {
  475. font-size: 24px;
  476. font-weight: 700;
  477. color: var(--color-brand);
  478. display: block;
  479. }
  480. .stat-label {
  481. font-size: 11px;
  482. color: var(--color-text-secondary);
  483. margin-top: 2px;
  484. display: block;
  485. }
  486. .team-preview {
  487. border-top: 1px solid var(--color-bg-input);
  488. padding-top: 10px;
  489. }
  490. .member-row {
  491. display: flex;
  492. align-items: center;
  493. padding: 8px 0;
  494. border-bottom: 1px solid var(--color-bg);
  495. }
  496. .member-row:last-child { border-bottom: none; }
  497. .member-avatar {
  498. width: 32px;
  499. height: 32px;
  500. border-radius: 50%;
  501. margin-right: 10px;
  502. flex-shrink: 0;
  503. }
  504. .member-info { flex: 1; }
  505. .member-name {
  506. font-size: 13px;
  507. color: var(--color-text-primary);
  508. display: block;
  509. }
  510. .member-date {
  511. font-size: 11px;
  512. color: var(--color-text-secondary);
  513. margin-top: 1px;
  514. display: block;
  515. }
  516. .member-vip {
  517. font-size: 10px;
  518. color: var(--color-gold);
  519. background: #FEF3C7;
  520. padding: 2px 8px;
  521. border-radius: 4px;
  522. font-weight: 500;
  523. }
  524. /* ===== Tools ===== */
  525. .tool-card {
  526. display: flex;
  527. justify-content: space-between;
  528. align-items: center;
  529. padding: 14px 0;
  530. border-bottom: 1px solid var(--color-bg-input);
  531. }
  532. .tool-card:last-child { border-bottom: none; }
  533. .tool-left {
  534. display: flex;
  535. align-items: center;
  536. gap: 12px;
  537. flex: 1;
  538. }
  539. .tool-icon {
  540. width: 36px;
  541. height: 36px;
  542. border-radius: 8px;
  543. background: var(--color-bg);
  544. display: flex;
  545. align-items: center;
  546. justify-content: center;
  547. font-size: 16px;
  548. color: var(--color-brand);
  549. flex-shrink: 0;
  550. }
  551. .tool-name {
  552. font-size: 14px;
  553. font-weight: 600;
  554. color: var(--color-text-primary);
  555. display: block;
  556. }
  557. .tool-desc {
  558. font-size: 11px;
  559. color: var(--color-text-secondary);
  560. margin-top: 2px;
  561. display: block;
  562. }
  563. .tool-right {
  564. display: flex;
  565. align-items: center;
  566. gap: 8px;
  567. }
  568. .ref-code-tag {
  569. font-size: 12px;
  570. font-weight: 600;
  571. color: var(--color-gold);
  572. background: #FEF3C7;
  573. padding: 2px 10px;
  574. border-radius: 4px;
  575. letter-spacing: 1px;
  576. }
  577. .tool-arrow {
  578. font-size: 18px;
  579. color: #CBD5E0;
  580. }
  581. /* ===== Commission List ===== */
  582. .commission-row {
  583. display: flex;
  584. justify-content: space-between;
  585. align-items: center;
  586. padding: 12px 0;
  587. border-bottom: 1px solid var(--color-bg-input);
  588. }
  589. .commission-row:last-child { border-bottom: none; }
  590. .comm-left { flex: 1; }
  591. .comm-amount {
  592. font-size: 15px;
  593. font-weight: 600;
  594. color: #2D8B67;
  595. display: block;
  596. }
  597. .comm-level {
  598. font-size: 12px;
  599. color: var(--color-text-secondary);
  600. margin-top: 2px;
  601. display: block;
  602. }
  603. .comm-remark {
  604. font-size: 11px;
  605. color: #8B9DAB;
  606. margin-top: 1px;
  607. display: block;
  608. }
  609. .comm-right { text-align: right; }
  610. .comm-status {
  611. font-size: 11px;
  612. padding: 2px 8px;
  613. border-radius: 4px;
  614. display: inline-block;
  615. margin-bottom: 2px;
  616. }
  617. .comm-status.status-settled { background: #ECFDF5; color: #2D8B67; }
  618. .comm-status.status-pending { background: #FEF3C7; color: #D4A017; }
  619. .comm-status.status-withdrawn { background: var(--color-bg-input); color: var(--color-text-secondary); }
  620. .comm-status.status-available { background: #EFF6FF; color: #3B82F6; }
  621. .comm-date {
  622. font-size: 11px;
  623. color: var(--color-text-secondary);
  624. display: block;
  625. }
  626. /* Empty State */
  627. .empty-state {
  628. padding: 24px 0;
  629. text-align: center;
  630. }
  631. .empty-text {
  632. font-size: 13px;
  633. color: var(--color-text-secondary);
  634. }
  635. </style>