records.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <template>
  2. <view class="page">
  3. <NavBar title="我的邀请" :showBack="true">
  4. <template #right>
  5. <view class="nav-action" @click="goToInvite">
  6. <view class="invite-icon"></view>
  7. </view>
  8. </template>
  9. </NavBar>
  10. <view class="content">
  11. <!-- 统计概览 -->
  12. <view class="stats-header" v-if="statistics">
  13. <view class="stat-card">
  14. <text class="stat-num">{{ statistics.totalInvite || 0 }}</text>
  15. <text class="stat-label">总邀请数</text>
  16. </view>
  17. <view class="stat-card success">
  18. <text class="stat-num">{{ statistics.validInvite || 0 }}</text>
  19. <text class="stat-label">已激活</text>
  20. </view>
  21. <view class="stat-card primary">
  22. <text class="stat-num">{{ statistics.rewardCount || 0 }}</text>
  23. <text class="stat-label">已获奖励</text>
  24. </view>
  25. </view>
  26. <!-- 双向奖励说明 -->
  27. <view class="dual-reward-notice">
  28. <view class="notice-icon">💡</view>
  29. <text class="notice-text">统计包含:邀请人推荐奖励 + 被邀请人新人优惠券</text>
  30. </view>
  31. <!-- 邀请记录列表 -->
  32. <view class="list-section">
  33. <view class="list-header">
  34. <text class="list-title">邀请记录</text>
  35. <text class="list-count">共 {{ total }} 条</text>
  36. </view>
  37. <scroll-view
  38. scroll-y
  39. class="records-list"
  40. @scrolltolower="loadMore"
  41. :refresher-enabled="true"
  42. :refresher-triggered="isRefreshing"
  43. @refresherrefresh="onRefresh"
  44. >
  45. <view class="record-list">
  46. <view
  47. class="record-item"
  48. v-for="(item, index) in recordList"
  49. :key="item.id"
  50. >
  51. <view class="record-left">
  52. <view class="avatar-placeholder">
  53. <text class="avatar-text">{{ getAvatarText(item.inviteeName) }}</text>
  54. </view>
  55. </view>
  56. <view class="record-content">
  57. <view class="record-header">
  58. <text class="invitee-name">{{ item.inviteeName || '用户' + (index + 1) }}</text>
  59. <view class="status-tag" :class="getStatusClass(item.status)">
  60. {{ getStatusText(item.status) }}
  61. </view>
  62. </view>
  63. <view class="record-body">
  64. <view class="info-row">
  65. <view class="info-icon phone"></view>
  66. <text class="info-text">{{ maskPhone(item.inviteePhone) }}</text>
  67. </view>
  68. <view class="info-row">
  69. <view class="info-icon time"></view>
  70. <text class="info-text">邀请时间:{{ formatTime(item.inviteTime) }}</text>
  71. </view>
  72. <view class="info-row" v-if="item.activateTime">
  73. <view class="info-icon activate"></view>
  74. <text class="info-text">激活时间:{{ formatTime(item.activateTime) }}</text>
  75. </view>
  76. <view class="info-row" v-if="item.rewardTime">
  77. <view class="info-icon reward"></view>
  78. <text class="info-text">奖励发放:{{ formatTime(item.rewardTime) }}</text>
  79. </view>
  80. </view>
  81. <view class="record-reward" v-if="item.couponName && item.couponAmount">
  82. <view class="reward-badge" :class="getRewardTypeClass(item.rewardType)">
  83. <text class="reward-type-tag">{{ getRewardTypeText(item.rewardType) }}</text>
  84. <text class="reward-amount">+¥{{ item.couponAmount }}</text>
  85. <text class="reward-name">{{ item.couponName }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 空状态 -->
  91. <view class="empty-state" v-if="!isLoading && recordList.length === 0">
  92. <view class="empty-icon"></view>
  93. <text class="empty-text">暂无邀请记录</text>
  94. <text class="empty-tip">快去邀请好友吧!</text>
  95. <button class="empty-btn" @click="goToInvite">立即邀请</button>
  96. </view>
  97. <!-- 加载更多 -->
  98. <view class="loading-more" v-if="isLoadingMore">
  99. <view class="loading-spinner"></view>
  100. <text class="loading-text">加载中...</text>
  101. </view>
  102. <view class="no-more" v-if="!hasMore && recordList.length > 0">
  103. <text>没有更多了</text>
  104. </view>
  105. </view>
  106. </scroll-view>
  107. </view>
  108. </view>
  109. </view>
  110. </template>
  111. <script setup lang="ts">
  112. import { ref, onMounted } from 'vue';
  113. import { logger } from '@/utils/logger';
  114. import NavBar from '@/components/NavBar.vue';
  115. import { getMyInviteRecords, getMyInviteStatistics, InviteStatus, InviteStatusLabel } from '@/api/invite';
  116. import type { InviteRecord, InviteStatistics, InviteQueryParams } from '@/api/invite';
  117. const statistics = ref<InviteStatistics | null>(null);
  118. const recordList = ref<InviteRecord[]>([]);
  119. const total = ref(0);
  120. const page = ref(1);
  121. const pageSize = 10;
  122. const isLoading = ref(false);
  123. const isLoadingMore = ref(false);
  124. const isRefreshing = ref(false);
  125. const hasMore = ref(true);
  126. onMounted(() => {
  127. loadStatistics();
  128. loadData();
  129. });
  130. const loadStatistics = async () => {
  131. try {
  132. statistics.value = await getMyInviteStatistics();
  133. } catch (error) {
  134. logger.warn('加载统计数据失败', error);
  135. }
  136. };
  137. const loadData = async (reset = false) => {
  138. if (reset) {
  139. page.value = 1;
  140. hasMore.value = true;
  141. }
  142. if (isLoading.value) return;
  143. isLoading.value = true;
  144. try {
  145. const params: InviteQueryParams = {
  146. page: page.value,
  147. pageSize
  148. };
  149. const result = await getMyInviteRecords(params);
  150. if (reset) {
  151. recordList.value = result.list;
  152. } else {
  153. recordList.value = [...recordList.value, ...result.list];
  154. }
  155. total.value = result.total;
  156. hasMore.value = recordList.value.length < result.total;
  157. } catch (error) {
  158. logger.warn('加载邀请记录失败', error);
  159. } finally {
  160. isLoading.value = false;
  161. isRefreshing.value = false;
  162. isLoadingMore.value = false;
  163. }
  164. };
  165. const loadMore = () => {
  166. if (!hasMore.value || isLoadingMore.value) return;
  167. isLoadingMore.value = true;
  168. page.value++;
  169. loadData();
  170. };
  171. const onRefresh = () => {
  172. isRefreshing.value = true;
  173. loadData(true);
  174. loadStatistics();
  175. };
  176. const maskPhone = (phone: string) => {
  177. if (!phone || phone.length < 7) return phone;
  178. // 如果已经是脱敏格式,直接返回
  179. if (phone.includes('*')) return phone;
  180. return phone.substring(0, 3) + '****' + phone.substring(phone.length - 4);
  181. };
  182. const getStatusClass = (status: InviteStatus) => {
  183. const classMap: Record<InviteStatus, string> = {
  184. [InviteStatus.PENDING]: 'pending',
  185. [InviteStatus.ACTIVATED]: 'activated',
  186. [InviteStatus.REWARDED]: 'rewarded',
  187. [InviteStatus.FAILED]: 'failed'
  188. };
  189. return classMap[status] || '';
  190. };
  191. const getStatusText = (status: InviteStatus) => {
  192. const textMap: Record<InviteStatus, string> = {
  193. [InviteStatus.PENDING]: InviteStatusLabel.PENDING,
  194. [InviteStatus.ACTIVATED]: InviteStatusLabel.ACTIVATED,
  195. [InviteStatus.REWARDED]: InviteStatusLabel.REWARDED,
  196. [InviteStatus.FAILED]: InviteStatusLabel.FAILED
  197. };
  198. return textMap[status] || status;
  199. };
  200. const formatTime = (timeStr: string) => {
  201. if (!timeStr) return '';
  202. return timeStr.replace('T', ' ').substring(0, 19);
  203. };
  204. const getAvatarText = (name?: string) => {
  205. if (!name) return '?';
  206. return name.charAt(name.length - 1);
  207. };
  208. // 奖励类型判断(区分邀请人奖励和被邀请人新人券)
  209. const getRewardTypeClass = (rewardType?: string) => {
  210. const typeMap: Record<string, string> = {
  211. 'inviter': 'type-inviter', // 邀请人推荐奖励
  212. 'invitee': 'type-invitee' // 被邀请人新人券
  213. };
  214. return typeMap[rewardType || ''] || '';
  215. };
  216. const getRewardTypeText = (rewardType?: string) => {
  217. const textMap: Record<string, string> = {
  218. 'inviter': '推荐奖',
  219. 'invitee': '新人券'
  220. };
  221. return textMap[rewardType || ''] || '';
  222. };
  223. const goToInvite = () => {
  224. uni.navigateTo({
  225. url: '/pages/invite/index'
  226. });
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .page {
  231. min-height: 100vh;
  232. background: $bg-color-page;
  233. display: flex;
  234. flex-direction: column;
  235. }
  236. .nav-action {
  237. width: 64rpx;
  238. height: 64rpx;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. }
  243. .invite-icon {
  244. width: 36rpx;
  245. height: 36rpx;
  246. border: 3rpx solid $info-color;
  247. border-radius: 50%;
  248. position: relative;
  249. &::before {
  250. content: '';
  251. position: absolute;
  252. top: -6rpx;
  253. right: -6rpx;
  254. width: 14rpx;
  255. height: 14rpx;
  256. background: $info-color;
  257. border-radius: 50%;
  258. }
  259. &::after {
  260. content: '';
  261. position: absolute;
  262. bottom: -2rpx;
  263. right: -2rpx;
  264. width: 16rpx;
  265. height: 10rpx;
  266. border-left: 3rpx solid $info-color;
  267. border-bottom: 3rpx solid $info-color;
  268. transform: rotate(-45deg);
  269. }
  270. }
  271. .content {
  272. flex: 1;
  273. display: flex;
  274. flex-direction: column;
  275. overflow: hidden;
  276. }
  277. .stats-header {
  278. display: flex;
  279. padding: 24rpx;
  280. background: $bg-color-card;
  281. gap: 20rpx;
  282. }
  283. .dual-reward-notice {
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. padding: 16rpx 24rpx;
  288. background: $primary-color-bg;
  289. margin: 0 24rpx 16rpx;
  290. border-radius: 10rpx;
  291. border: 1rpx solid $primary-color-light;
  292. }
  293. .notice-icon {
  294. font-size: 28rpx;
  295. margin-right: 10rpx;
  296. }
  297. .notice-text {
  298. font-size: 24rpx;
  299. color: $primary-color-dark;
  300. }
  301. .stat-card {
  302. flex: 1;
  303. background: $bg-color-page;
  304. border-radius: 16rpx;
  305. padding: 24rpx 16rpx;
  306. display: flex;
  307. flex-direction: column;
  308. align-items: center;
  309. border: 1rpx solid $border-color;
  310. &.success {
  311. background: $success-color-bg;
  312. border-color: $success-color-bg;
  313. .stat-num {
  314. color: $primary-color-dark;
  315. }
  316. .stat-label {
  317. color: $success-color;
  318. }
  319. }
  320. &.primary {
  321. background: $info-color-bg;
  322. border-color: $info-color-bg;
  323. .stat-num {
  324. color: $info-color;
  325. }
  326. .stat-label {
  327. color: $info-color;
  328. }
  329. }
  330. }
  331. .stat-num {
  332. font-size: 40rpx;
  333. font-weight: 700;
  334. color: $text-color-primary;
  335. margin-bottom: 8rpx;
  336. }
  337. .stat-label {
  338. font-size: 22rpx;
  339. color: $text-color-tertiary;
  340. }
  341. .list-section {
  342. flex: 1;
  343. display: flex;
  344. flex-direction: column;
  345. overflow: hidden;
  346. }
  347. .list-header {
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: center;
  351. padding: 20rpx 24rpx;
  352. background: $bg-color-card;
  353. border-top: 1rpx solid $border-color;
  354. }
  355. .list-title {
  356. font-size: 28rpx;
  357. font-weight: 600;
  358. color: $text-color-primary;
  359. }
  360. .list-count {
  361. font-size: 24rpx;
  362. color: $text-color-muted;
  363. }
  364. .records-list {
  365. flex: 1;
  366. height: 0;
  367. }
  368. .record-list {
  369. padding: 0 24rpx;
  370. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  371. }
  372. .record-item {
  373. display: flex;
  374. align-items: flex-start;
  375. background: $bg-color-card;
  376. border-radius: 16rpx;
  377. padding: 24rpx;
  378. margin-bottom: 16rpx;
  379. border: 1rpx solid $border-color;
  380. }
  381. .record-left {
  382. margin-right: 20rpx;
  383. }
  384. .avatar-placeholder {
  385. width: 80rpx;
  386. height: 80rpx;
  387. background: linear-gradient(135deg, $primary-color 0%, $primary-color-dark 100%);
  388. border-radius: 50%;
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. }
  393. .avatar-text {
  394. font-size: 32rpx;
  395. font-weight: 600;
  396. color: $bg-color-card;
  397. }
  398. .record-content {
  399. flex: 1;
  400. min-width: 0;
  401. }
  402. .record-header {
  403. display: flex;
  404. justify-content: space-between;
  405. align-items: center;
  406. margin-bottom: 12rpx;
  407. }
  408. .invitee-name {
  409. font-size: 28rpx;
  410. font-weight: 600;
  411. color: $text-color-primary;
  412. }
  413. .status-tag {
  414. padding: 4rpx 16rpx;
  415. border-radius: 8rpx;
  416. font-size: 22rpx;
  417. font-weight: 500;
  418. white-space: nowrap;
  419. margin-left: 12rpx;
  420. &.pending {
  421. background: $bg-color-secondary;
  422. color: $text-color-tertiary;
  423. }
  424. &.activated {
  425. background: $success-color-bg;
  426. color: $primary-color-dark;
  427. }
  428. &.rewarded {
  429. background: $info-color-bg;
  430. color: $info-color;
  431. }
  432. &.failed {
  433. background: $error-color-bg;
  434. color: $error-color;
  435. }
  436. }
  437. .record-body {
  438. margin-bottom: 12rpx;
  439. }
  440. .info-row {
  441. display: flex;
  442. align-items: center;
  443. margin-bottom: 8rpx;
  444. &:last-child {
  445. margin-bottom: 0;
  446. }
  447. }
  448. .info-icon {
  449. width: 26rpx;
  450. height: 26rpx;
  451. margin-right: 8rpx;
  452. border-radius: 50%;
  453. &.phone {
  454. background: $info-color-bg;
  455. position: relative;
  456. &::before {
  457. content: '';
  458. position: absolute;
  459. top: 50%;
  460. left: 50%;
  461. transform: translate(-50%, -50%);
  462. width: 10rpx;
  463. height: 16rpx;
  464. border: 2rpx solid $info-color;
  465. border-radius: 3rpx;
  466. }
  467. &::after {
  468. content: '';
  469. position: absolute;
  470. bottom: 3rpx;
  471. left: 50%;
  472. transform: translateX(-50%);
  473. width: 4rpx;
  474. height: 2rpx;
  475. background: $info-color;
  476. border-radius: 1rpx;
  477. }
  478. }
  479. &.time {
  480. background: $primary-color-bg;
  481. position: relative;
  482. &::before {
  483. content: '';
  484. position: absolute;
  485. top: 50%;
  486. left: 50%;
  487. transform: translate(-50%, -50%);
  488. width: 11rpx;
  489. height: 11rpx;
  490. border: 2rpx solid $primary-color;
  491. border-radius: 50%;
  492. }
  493. &::after {
  494. content: '';
  495. position: absolute;
  496. top: 7rpx;
  497. left: 50%;
  498. transform: translateX(-50%);
  499. width: 2rpx;
  500. height: 5rpx;
  501. background: $primary-color;
  502. }
  503. }
  504. &.activate {
  505. background: $success-color-bg;
  506. position: relative;
  507. &::before {
  508. content: '';
  509. position: absolute;
  510. top: 50%;
  511. left: 50%;
  512. transform: translate(-50%, -50%);
  513. width: 12rpx;
  514. height: 8rpx;
  515. border: 2rpx solid $primary-color;
  516. border-radius: 2rpx;
  517. }
  518. &::after {
  519. content: '';
  520. position: absolute;
  521. top: 50%;
  522. left: 50%;
  523. transform: translate(-50%, -50%);
  524. width: 4rpx;
  525. height: 4rpx;
  526. background: $primary-color;
  527. border-radius: 50%;
  528. }
  529. }
  530. &.reward {
  531. background: $warning-color-bg;
  532. position: relative;
  533. &::before {
  534. content: '¥';
  535. position: absolute;
  536. top: 50%;
  537. left: 50%;
  538. transform: translate(-50%, -50%);
  539. font-size: 14rpx;
  540. font-weight: 700;
  541. color: $warning-color;
  542. }
  543. }
  544. }
  545. .info-text {
  546. font-size: 24rpx;
  547. color: $text-color-tertiary;
  548. flex: 1;
  549. overflow: hidden;
  550. text-overflow: ellipsis;
  551. white-space: nowrap;
  552. }
  553. .record-reward {
  554. padding-top: 12rpx;
  555. border-top: 1rpx solid $bg-color-secondary;
  556. }
  557. .reward-badge {
  558. display: inline-flex;
  559. align-items: center;
  560. padding: 8rpx 16rpx;
  561. background: linear-gradient(135deg, $primary-color-bg 0%, $primary-color-light 100%);
  562. border-radius: 8rpx;
  563. gap: 8rpx;
  564. &.type-inviter {
  565. background: linear-gradient(135deg, $info-color-bg 0%, $info-color-bg 100%);
  566. .reward-amount {
  567. color: $info-color;
  568. }
  569. .reward-name {
  570. color: $text-color-primary;
  571. }
  572. }
  573. &.type-invitee {
  574. background: linear-gradient(135deg, $success-color-bg 0%, $success-color-bg 100%);
  575. .reward-amount {
  576. color: $primary-color-dark;
  577. }
  578. .reward-name {
  579. color: $success-color;
  580. }
  581. }
  582. }
  583. .reward-type-tag {
  584. font-size: 20rpx;
  585. font-weight: 600;
  586. padding: 2rpx 10rpx;
  587. background: rgba(255, 255, 255, 0.6);
  588. border-radius: 6rpx;
  589. color: $primary-color-dark;
  590. }
  591. .reward-amount {
  592. font-size: 26rpx;
  593. font-weight: 700;
  594. color: $primary-color-dark;
  595. }
  596. .reward-name {
  597. font-size: 22rpx;
  598. color: $primary-color-dark;
  599. }
  600. .empty-state {
  601. display: flex;
  602. flex-direction: column;
  603. align-items: center;
  604. padding: 100rpx 40rpx;
  605. }
  606. .empty-icon {
  607. width: 160rpx;
  608. height: 160rpx;
  609. background: $bg-color-secondary;
  610. border-radius: 50%;
  611. margin-bottom: 32rpx;
  612. position: relative;
  613. &::before {
  614. content: '';
  615. position: absolute;
  616. top: 50%;
  617. left: 50%;
  618. transform: translate(-50%, -60%);
  619. width: 56rpx;
  620. height: 36rpx;
  621. border: 4rpx solid $text-color-placeholder;
  622. border-radius: 8rpx 8rpx 0 0;
  623. }
  624. &::after {
  625. content: '';
  626. position: absolute;
  627. top: 58%;
  628. left: 50%;
  629. transform: translateX(-50%);
  630. width: 6rpx;
  631. height: 18rpx;
  632. background: $text-color-placeholder;
  633. }
  634. }
  635. .empty-text {
  636. font-size: 30rpx;
  637. color: $text-color-tertiary;
  638. margin-bottom: 12rpx;
  639. }
  640. .empty-tip {
  641. font-size: 26rpx;
  642. color: $text-color-muted;
  643. margin-bottom: 32rpx;
  644. }
  645. .empty-btn {
  646. padding: 20rpx 48rpx;
  647. background: linear-gradient(135deg, $primary-color 0%, $primary-color-dark 100%);
  648. border-radius: 44rpx;
  649. font-size: 28rpx;
  650. font-weight: 500;
  651. color: $bg-color-card;
  652. border: none;
  653. &:active {
  654. opacity: 0.9;
  655. }
  656. }
  657. .loading-more {
  658. display: flex;
  659. align-items: center;
  660. justify-content: center;
  661. padding: 24rpx;
  662. }
  663. .loading-spinner {
  664. width: 32rpx;
  665. height: 32rpx;
  666. border: 3rpx solid $border-color;
  667. border-top-color: $primary-color;
  668. border-radius: 50%;
  669. animation: rotate 0.8s linear infinite;
  670. @keyframes rotate {
  671. from { transform: rotate(0deg); }
  672. to { transform: rotate(360deg); }
  673. }
  674. }
  675. .loading-text {
  676. font-size: 24rpx;
  677. color: $text-color-muted;
  678. margin-left: 12rpx;
  679. }
  680. .no-more {
  681. text-align: center;
  682. padding: 24rpx;
  683. text {
  684. font-size: 24rpx;
  685. color: $text-color-muted;
  686. }
  687. }
  688. </style>