invite.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="container">
  3. <!-- 邀请统计 -->
  4. <view class="stats-card">
  5. <view class="stats-item">
  6. <text class="stats-num" v-if="summary">{{ summary.totalInvited || 0 }}</text>
  7. <text class="stats-num" v-else>0</text>
  8. <text class="stats-label">已邀请</text>
  9. </view>
  10. <view class="stats-divider"></view>
  11. <view class="stats-item">
  12. <text class="stats-num" v-if="summary">{{ summary.activeCount || 0 }}</text>
  13. <text class="stats-num" v-else>0</text>
  14. <text class="stats-label">活跃</text>
  15. </view>
  16. <view class="stats-divider"></view>
  17. <view class="stats-item">
  18. <text class="stats-num" v-if="summary">{{ '¥' + (summary.totalEarnings || '0.00') }}</text>
  19. <text class="stats-num" v-else>¥0.00</text>
  20. <text class="stats-label">总收益</text>
  21. </view>
  22. </view>
  23. <!-- 邀请码展示 -->
  24. <view class="code-card">
  25. <text class="code-title">我的邀请码</text>
  26. <text class="code-value">{{ referralCode || '加载中...' }}</text>
  27. <view class="code-actions">
  28. <button class="action-btn" @click="copyCode">复制邀请码</button>
  29. <button class="action-btn share" @click="shareInvite">分享给好友</button>
  30. </view>
  31. </view>
  32. <!-- 绑定推荐人 -->
  33. <view class="bind-card">
  34. <text class="bind-title">我有推荐人</text>
  35. <view class="bind-row">
  36. <input v-model="bindCode" type="text" placeholder="输入推荐人的邀请码" class="bind-input" />
  37. <button class="bind-btn" @click="bindReferral">绑定</button>
  38. </view>
  39. </view>
  40. <!-- 已邀请列表 -->
  41. <view class="list-section">
  42. <text class="section-title">已邀请好友 ({{ total || 0 }})</text>
  43. <view class="empty-state" v-if="!loading && list.length === 0">
  44. <text>还没有邀请好友,快去分享吧</text>
  45. </view>
  46. <view class="invite-item" v-for="item in list" :key="item.id">
  47. <view class="invite-avatar-wrap">
  48. <text class="invite-avatar">{{ item.avatar ? '' : '👤' }}</text>
  49. </view>
  50. <view class="invite-info">
  51. <text class="invite-name">{{ item.nickname || '好友' }}</text>
  52. <text class="invite-time">{{ formatTime(item.createdAt) }}</text>
  53. </view>
  54. </view>
  55. <view class="loading-state" v-if="loading">
  56. <text>加载中...</text>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { getReferralCode, bindReferral, getReferralList, getReferralSummary } from '../../utils/api.js'
  63. export default {
  64. data() {
  65. return {
  66. referralCode: '',
  67. bindCode: '',
  68. list: [],
  69. total: 0,
  70. page: 1,
  71. loading: false,
  72. hasMore: true,
  73. summary: null
  74. }
  75. },
  76. onLoad() {
  77. this.loadCode()
  78. this.loadSummary()
  79. this.loadList()
  80. },
  81. onReachBottom() {
  82. if (this.hasMore && !this.loading) {
  83. this.page++
  84. this.loadList()
  85. }
  86. },
  87. methods: {
  88. async loadCode() {
  89. try {
  90. const res = await getReferralCode()
  91. if (res.data) {
  92. this.referralCode = res.data.referralCode || res.data.code || ''
  93. }
  94. } catch (e) {
  95. console.error('获取邀请码失败', e)
  96. }
  97. },
  98. async loadSummary() {
  99. try {
  100. const res = await getReferralSummary()
  101. if (res.data) {
  102. this.summary = res.data
  103. }
  104. } catch (e) {
  105. console.error('获取邀请统计失败', e)
  106. }
  107. },
  108. async loadList() {
  109. this.loading = true
  110. try {
  111. const res = await getReferralList(this.page)
  112. if (res.data) {
  113. if (res.data.records) {
  114. this.list = this.page === 1 ? res.data.records : this.list.concat(res.data.records)
  115. }
  116. this.total = res.data.total || 0
  117. if (res.data.records) {
  118. this.hasMore = res.data.records.length >= 10
  119. } else {
  120. this.hasMore = false
  121. }
  122. }
  123. } catch (e) {
  124. console.error('获取邀请列表失败', e)
  125. }
  126. this.loading = false
  127. },
  128. copyCode() {
  129. if (!this.referralCode) return
  130. uni.setClipboardData({
  131. data: this.referralCode,
  132. success: function() {
  133. uni.showToast({ title: '已复制邀请码', icon: 'success' })
  134. }
  135. })
  136. },
  137. shareInvite() {
  138. uni.showToast({ title: '即将上线', icon: 'none' })
  139. },
  140. async bindReferral() {
  141. if (!this.bindCode) {
  142. uni.showToast({ title: '请输入邀请码', icon: 'none' })
  143. return
  144. }
  145. if (this.bindCode === this.referralCode) {
  146. uni.showToast({ title: '不能绑定自己的邀请码', icon: 'none' })
  147. return
  148. }
  149. try {
  150. await bindReferral(this.bindCode)
  151. uni.showToast({ title: '绑定成功', icon: 'success' })
  152. this.bindCode = ''
  153. } catch (e) {
  154. uni.showToast({ title: e.message || '绑定失败', icon: 'none' })
  155. }
  156. },
  157. formatTime(time) {
  158. if (!time) return ''
  159. var t = new Date(time)
  160. return t.getFullYear() + '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + String(t.getDate()).padStart(2, '0')
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. .container {
  167. padding: 30rpx;
  168. min-height: 100vh;
  169. background: #FFF7ED;
  170. }
  171. /* ===== 邀请统计 ===== */
  172. .stats-card {
  173. background: #fff;
  174. border-radius: 20rpx;
  175. padding: 32rpx 24rpx;
  176. display: flex;
  177. align-items: center;
  178. margin-bottom: 24rpx;
  179. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  180. }
  181. .stats-item {
  182. flex: 1;
  183. text-align: center;
  184. }
  185. .stats-num {
  186. font-size: 36rpx;
  187. font-weight: bold;
  188. color: #F97316;
  189. display: block;
  190. }
  191. .stats-label {
  192. font-size: 22rpx;
  193. color: #94A3B8;
  194. margin-top: 4rpx;
  195. display: block;
  196. }
  197. .stats-divider {
  198. width: 1rpx;
  199. height: 48rpx;
  200. background: #FED7AA;
  201. }
  202. .code-card {
  203. background: linear-gradient(135deg, #F97316, #EA580C);
  204. border-radius: 20rpx;
  205. padding: 40rpx;
  206. text-align: center;
  207. color: #fff;
  208. margin-bottom: 24rpx;
  209. }
  210. .code-title {
  211. font-size: 24rpx;
  212. opacity: 0.85;
  213. }
  214. .code-value {
  215. font-size: 48rpx;
  216. font-weight: bold;
  217. letter-spacing: 8rpx;
  218. margin: 20rpx 0 30rpx;
  219. display: block;
  220. }
  221. .code-actions {
  222. display: flex;
  223. gap: 20rpx;
  224. }
  225. .action-btn {
  226. flex: 1;
  227. background: rgba(255,255,255,0.2);
  228. color: #fff;
  229. font-size: 26rpx;
  230. border-radius: 40rpx;
  231. height: 64rpx;
  232. line-height: 64rpx;
  233. border: 1rpx solid rgba(255,255,255,0.3);
  234. }
  235. .action-btn::after { border: none; }
  236. .action-btn:active { opacity: 0.8; }
  237. .bind-card {
  238. background: #fff;
  239. border-radius: 20rpx;
  240. padding: 30rpx;
  241. margin-bottom: 24rpx;
  242. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  243. }
  244. .bind-title {
  245. font-size: 28rpx;
  246. font-weight: 600;
  247. color: #1E293B;
  248. display: block;
  249. margin-bottom: 16rpx;
  250. }
  251. .bind-row {
  252. display: flex;
  253. gap: 20rpx;
  254. }
  255. .bind-input {
  256. flex: 1;
  257. border: 1rpx solid #CBD5E1;
  258. border-radius: 12rpx;
  259. padding: 20rpx;
  260. font-size: 28rpx;
  261. }
  262. .bind-btn {
  263. background: #F97316;
  264. color: #fff;
  265. font-size: 26rpx;
  266. border-radius: 12rpx;
  267. height: 64rpx;
  268. line-height: 64rpx;
  269. padding: 0 30rpx;
  270. font-weight: 500;
  271. }
  272. .bind-btn::after { border: none; }
  273. .bind-btn:active { opacity: 0.9; }
  274. .list-section {
  275. background: #fff;
  276. border-radius: 20rpx;
  277. padding: 30rpx;
  278. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  279. }
  280. .section-title {
  281. font-size: 28rpx;
  282. font-weight: 600;
  283. color: #1E293B;
  284. display: block;
  285. margin-bottom: 20rpx;
  286. }
  287. .invite-item {
  288. display: flex;
  289. align-items: center;
  290. padding: 20rpx 0;
  291. border-bottom: 1rpx solid #FED7AA;
  292. }
  293. .invite-item:last-child { border-bottom: none; }
  294. .invite-avatar-wrap {
  295. width: 60rpx;
  296. height: 60rpx;
  297. border-radius: 50%;
  298. background: #FEF3C7;
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. margin-right: 20rpx;
  303. }
  304. .invite-avatar {
  305. font-size: 32rpx;
  306. }
  307. .invite-info { flex: 1; }
  308. .invite-name {
  309. font-size: 28rpx;
  310. color: #1E293B;
  311. display: block;
  312. }
  313. .invite-time {
  314. font-size: 22rpx;
  315. color: #94A3B8;
  316. margin-top: 4rpx;
  317. }
  318. .empty-state, .loading-state {
  319. text-align: center;
  320. padding: 60rpx;
  321. color: #94A3B8;
  322. font-size: 28rpx;
  323. }
  324. </style>