index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. @import "@/styles/theme.scss";
  325. .page-commission {
  326. min-height: 100vh;
  327. background: var(--color-bg);
  328. padding: 16px;
  329. }
  330. /* Error / permission gate */
  331. .error-state {
  332. padding: 80px 20px;
  333. text-align: center;
  334. }
  335. .error-icon {
  336. font-size: 40px;
  337. display: block;
  338. margin-bottom: 12px;
  339. }
  340. .error-text {
  341. font-size: 14px;
  342. color: var(--color-text-secondary);
  343. }
  344. /* Loading */
  345. .loading-state {
  346. padding: 60px 0;
  347. text-align: center;
  348. }
  349. .loading-text {
  350. font-size: 14px;
  351. color: var(--color-text-secondary);
  352. }
  353. /* Section */
  354. .section {
  355. background: #fff;
  356. border-radius: 14px;
  357. padding: 16px;
  358. margin-bottom: 16px;
  359. }
  360. .section-header {
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. margin-bottom: 14px;
  365. }
  366. .section-title {
  367. font-size: 16px;
  368. font-weight: 700;
  369. color: var(--color-text-primary);
  370. }
  371. .section-sub {
  372. font-size: 12px;
  373. color: #3B82F6;
  374. font-weight: 500;
  375. }
  376. /* ===== Earnings ===== */
  377. .earnings-section {
  378. background: linear-gradient(135deg, var(--color-brand), #2D4A7A);
  379. }
  380. .earnings-section .section-title {
  381. color: rgba(255,255,255,0.9);
  382. }
  383. .earnings-grid {
  384. display: grid;
  385. grid-template-columns: 1fr 1fr;
  386. gap: 12px;
  387. }
  388. .earn-item {
  389. text-align: center;
  390. padding: 8px 0;
  391. }
  392. .earn-label {
  393. font-size: 11px;
  394. color: rgba(255,255,255,0.55);
  395. display: block;
  396. margin-bottom: 4px;
  397. }
  398. .earn-value {
  399. font-size: 22px;
  400. font-weight: 700;
  401. color: #fff;
  402. display: block;
  403. }
  404. .earn-value.accent {
  405. color: var(--color-gold);
  406. }
  407. .withdraw-bar {
  408. margin-top: 14px;
  409. padding: 10px 0;
  410. background: rgba(255,255,255,0.06);
  411. border: 1px solid rgba(251,191,36,0.15);
  412. border-radius: 10px;
  413. display: flex;
  414. align-items: center;
  415. justify-content: center;
  416. gap: 6px;
  417. }
  418. .withdraw-text {
  419. font-size: 14px;
  420. font-weight: 600;
  421. color: var(--color-gold);
  422. }
  423. .withdraw-arrow {
  424. font-size: 16px;
  425. color: var(--color-gold);
  426. }
  427. /* ===== Earnings Breakdown ===== */
  428. .earnings-breakdown {
  429. margin-top: 12px;
  430. padding: 10px 14px;
  431. background: rgba(255,255,255,0.03);
  432. border-radius: 8px;
  433. }
  434. .breakdown-row {
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. padding: 4px 0;
  439. }
  440. .breakdown-label {
  441. font-size: 12px;
  442. color: rgba(255,255,255,0.5);
  443. }
  444. .breakdown-value {
  445. font-size: 13px;
  446. font-weight: 500;
  447. color: rgba(255,255,255,0.75);
  448. }
  449. /* ===== Withdraw Notice ===== */
  450. .withdraw-notice {
  451. margin-top: 14px;
  452. padding: 10px 0;
  453. background: rgba(255,255,255,0.03);
  454. border: 1px solid rgba(255,255,255,0.06);
  455. border-radius: 10px;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. }
  460. .withdraw-notice-text {
  461. font-size: 13px;
  462. color: rgba(255,255,255,0.4);
  463. }
  464. /* ===== Team ===== */
  465. .team-grid {
  466. display: grid;
  467. grid-template-columns: 1fr 1fr 1fr 1fr;
  468. gap: 8px;
  469. margin-bottom: 14px;
  470. }
  471. .team-stat {
  472. text-align: center;
  473. padding: 8px 0;
  474. }
  475. .stat-num {
  476. font-size: 24px;
  477. font-weight: 700;
  478. color: var(--color-brand);
  479. display: block;
  480. }
  481. .stat-label {
  482. font-size: 11px;
  483. color: var(--color-text-secondary);
  484. margin-top: 2px;
  485. display: block;
  486. }
  487. .team-preview {
  488. border-top: 1px solid var(--color-bg-input);
  489. padding-top: 10px;
  490. }
  491. .member-row {
  492. display: flex;
  493. align-items: center;
  494. padding: 8px 0;
  495. border-bottom: 1px solid var(--color-bg);
  496. }
  497. .member-row:last-child { border-bottom: none; }
  498. .member-avatar {
  499. width: 32px;
  500. height: 32px;
  501. border-radius: 50%;
  502. margin-right: 10px;
  503. flex-shrink: 0;
  504. }
  505. .member-info { flex: 1; }
  506. .member-name {
  507. font-size: 13px;
  508. color: var(--color-text-primary);
  509. display: block;
  510. }
  511. .member-date {
  512. font-size: 11px;
  513. color: var(--color-text-secondary);
  514. margin-top: 1px;
  515. display: block;
  516. }
  517. .member-vip {
  518. font-size: 10px;
  519. color: var(--color-gold);
  520. background: #FEF3C7;
  521. padding: 2px 8px;
  522. border-radius: 4px;
  523. font-weight: 500;
  524. }
  525. /* ===== Tools ===== */
  526. .tool-card {
  527. display: flex;
  528. justify-content: space-between;
  529. align-items: center;
  530. padding: 14px 0;
  531. border-bottom: 1px solid var(--color-bg-input);
  532. }
  533. .tool-card:last-child { border-bottom: none; }
  534. .tool-left {
  535. display: flex;
  536. align-items: center;
  537. gap: 12px;
  538. flex: 1;
  539. }
  540. .tool-icon {
  541. width: 36px;
  542. height: 36px;
  543. border-radius: 8px;
  544. background: var(--color-bg);
  545. display: flex;
  546. align-items: center;
  547. justify-content: center;
  548. font-size: 16px;
  549. color: var(--color-brand);
  550. flex-shrink: 0;
  551. }
  552. .tool-name {
  553. font-size: 14px;
  554. font-weight: 600;
  555. color: var(--color-text-primary);
  556. display: block;
  557. }
  558. .tool-desc {
  559. font-size: 11px;
  560. color: var(--color-text-secondary);
  561. margin-top: 2px;
  562. display: block;
  563. }
  564. .tool-right {
  565. display: flex;
  566. align-items: center;
  567. gap: 8px;
  568. }
  569. .ref-code-tag {
  570. font-size: 12px;
  571. font-weight: 600;
  572. color: var(--color-gold);
  573. background: #FEF3C7;
  574. padding: 2px 10px;
  575. border-radius: 4px;
  576. letter-spacing: 1px;
  577. }
  578. .tool-arrow {
  579. font-size: 18px;
  580. color: #CBD5E0;
  581. }
  582. /* ===== Commission List ===== */
  583. .commission-row {
  584. display: flex;
  585. justify-content: space-between;
  586. align-items: center;
  587. padding: 12px 0;
  588. border-bottom: 1px solid var(--color-bg-input);
  589. }
  590. .commission-row:last-child { border-bottom: none; }
  591. .comm-left { flex: 1; }
  592. .comm-amount {
  593. font-size: 15px;
  594. font-weight: 600;
  595. color: #2D8B67;
  596. display: block;
  597. }
  598. .comm-level {
  599. font-size: 12px;
  600. color: var(--color-text-secondary);
  601. margin-top: 2px;
  602. display: block;
  603. }
  604. .comm-remark {
  605. font-size: 11px;
  606. color: #8B9DAB;
  607. margin-top: 1px;
  608. display: block;
  609. }
  610. .comm-right { text-align: right; }
  611. .comm-status {
  612. font-size: 11px;
  613. padding: 2px 8px;
  614. border-radius: 4px;
  615. display: inline-block;
  616. margin-bottom: 2px;
  617. }
  618. .comm-status.status-settled { background: #ECFDF5; color: #2D8B67; }
  619. .comm-status.status-pending { background: #FEF3C7; color: #D4A017; }
  620. .comm-status.status-withdrawn { background: var(--color-bg-input); color: var(--color-text-secondary); }
  621. .comm-status.status-available { background: #EFF6FF; color: #3B82F6; }
  622. .comm-date {
  623. font-size: 11px;
  624. color: var(--color-text-secondary);
  625. display: block;
  626. }
  627. /* Empty State */
  628. .empty-state {
  629. padding: 24px 0;
  630. text-align: center;
  631. }
  632. .empty-text {
  633. font-size: 13px;
  634. color: var(--color-text-secondary);
  635. }
  636. </style>