ProfileStats.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view>
  3. <!-- 行动数据 -->
  4. <view class="section">
  5. <view class="section-header">
  6. <text class="section-title">🎯 行动数据</text>
  7. </view>
  8. <view class="wealth-card">
  9. <view class="wealth-item">
  10. <text class="wealth-value">{{ actionData.taskCount }}</text>
  11. <text class="wealth-label">完成任务</text>
  12. </view>
  13. <view class="wealth-divider"></view>
  14. <view class="wealth-item">
  15. <text class="wealth-value">{{ actionData.purchaseCount }}</text>
  16. <text class="wealth-label">购买商品</text>
  17. </view>
  18. <view class="wealth-divider"></view>
  19. <view class="wealth-item">
  20. <text class="wealth-value">{{ actionData.activityCount }}</text>
  21. <text class="wealth-label">参加活动</text>
  22. </view>
  23. <view class="wealth-divider"></view>
  24. <view class="wealth-item">
  25. <text class="wealth-value">{{ actionData.courseCount }}</text>
  26. <text class="wealth-label">学习课程</text>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 财富数据(推广收益) -->
  31. <view class="section">
  32. <view class="section-header">
  33. <text class="section-title">💰 财富数据</text>
  34. <text class="section-more" @click="goToPromotion">全部 ›</text>
  35. </view>
  36. <view class="wealth-card">
  37. <view class="wealth-item">
  38. <text class="wealth-value">{{ formatPriceWithSymbol(wealthData.totalEarnings) }}</text>
  39. <text class="wealth-label">累计收益</text>
  40. </view>
  41. <view class="wealth-divider"></view>
  42. <view class="wealth-item">
  43. <text class="wealth-value">{{ formatPriceWithSymbol(wealthData.availableAmount) }}</text>
  44. <text class="wealth-label">可提现</text>
  45. </view>
  46. <view class="wealth-divider"></view>
  47. <view class="wealth-item">
  48. <text class="wealth-value">{{ wealthData.referralCount }}</text>
  49. <text class="wealth-label">邀请人数</text>
  50. </view>
  51. </view>
  52. <view class="referral-code-bar" @click="copyReferralCode" v-if="wealthData.referralCode">
  53. <text class="referral-code-label">邀请码</text>
  54. <text class="referral-code-value">{{ wealthData.referralCode }}</text>
  55. <text class="referral-code-copy">复制</text>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import { getUserActionStats, getReferralCode, getReferralSummary, getCommissionSummary } from '../../../utils/api.js'
  62. export default {
  63. name: 'ProfileStats',
  64. data() {
  65. return {
  66. actionData: {
  67. purchaseCount: 0,
  68. activityCount: 0,
  69. taskCount: 0,
  70. courseCount: 0
  71. },
  72. wealthData: {
  73. totalEarnings: '0.00',
  74. availableAmount: '0.00',
  75. referralCount: 0,
  76. referralCode: ''
  77. }
  78. }
  79. },
  80. onShow() {
  81. if (!uni.getStorageSync('token')) return
  82. this.loadActionData()
  83. this.loadWealthData()
  84. },
  85. methods: {
  86. formatPriceWithSymbol(val) {
  87. if (val === null || val === undefined) return '0.00'
  88. return String(val)
  89. },
  90. async loadActionData() {
  91. try {
  92. const res = await getUserActionStats()
  93. if (res.code === 200 && res.data) {
  94. this.actionData.purchaseCount = res.data.purchaseCount || 0
  95. this.actionData.activityCount = res.data.activityCount || 0
  96. this.actionData.taskCount = res.data.taskCount || 0
  97. this.actionData.courseCount = res.data.courseCount || 0
  98. }
  99. } catch (e) {
  100. this.actionData.taskCount = parseInt(uni.getStorageSync('completedTasks') || 0)
  101. }
  102. },
  103. async loadWealthData() {
  104. try {
  105. const codeRes = await getReferralCode()
  106. if (codeRes.data) {
  107. this.wealthData.referralCode = codeRes.data.referralCode || codeRes.data.code || ''
  108. }
  109. } catch (e) {}
  110. try {
  111. const summaryRes = await getReferralSummary()
  112. if (summaryRes.data) {
  113. this.wealthData.totalEarnings = summaryRes.data.totalEarnings || '0.00'
  114. this.wealthData.referralCount = summaryRes.data.referredCount || summaryRes.data.totalCount || 0
  115. }
  116. } catch (e) {}
  117. try {
  118. const comRes = await getCommissionSummary()
  119. if (comRes.data) {
  120. this.wealthData.availableAmount = comRes.data.availableAmount || '0.00'
  121. }
  122. } catch (e) {}
  123. },
  124. goToPromotion() {
  125. uni.navigateTo({ url: '/pages/promotion/index' })
  126. },
  127. copyReferralCode() {
  128. if (!this.wealthData.referralCode) return
  129. uni.setClipboardData({
  130. data: this.wealthData.referralCode,
  131. success: () => { uni.showToast({ title: '邀请码已复制', icon: 'success' }) }
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. .section {
  139. margin: 20rpx 30rpx;
  140. }
  141. .section-header {
  142. display: flex;
  143. justify-content: space-between;
  144. align-items: center;
  145. margin-bottom: 20rpx;
  146. }
  147. .section-title {
  148. font-size: 30rpx;
  149. font-weight: bold;
  150. color: #333;
  151. }
  152. .section-more {
  153. font-size: 24rpx;
  154. color: #999;
  155. }
  156. .wealth-card {
  157. background: #fff;
  158. border-radius: 20rpx;
  159. padding: 30rpx 20rpx;
  160. display: flex;
  161. align-items: center;
  162. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  163. }
  164. .wealth-item {
  165. flex: 1;
  166. display: flex;
  167. flex-direction: column;
  168. align-items: center;
  169. }
  170. .wealth-value {
  171. font-size: 40rpx;
  172. font-weight: bold;
  173. color: #F97316;
  174. }
  175. .wealth-label {
  176. font-size: 24rpx;
  177. color: #999;
  178. margin-top: 8rpx;
  179. }
  180. .wealth-divider {
  181. width: 1rpx;
  182. height: 60rpx;
  183. background: #f0f0f0;
  184. }
  185. .referral-code-bar {
  186. display: flex;
  187. align-items: center;
  188. background: #fff;
  189. border-radius: 16rpx;
  190. padding: 20rpx 24rpx;
  191. margin-top: 16rpx;
  192. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  193. }
  194. .referral-code-label {
  195. font-size: 26rpx;
  196. color: #999;
  197. margin-right: 16rpx;
  198. }
  199. .referral-code-value {
  200. flex: 1;
  201. font-size: 28rpx;
  202. font-weight: bold;
  203. color: #F97316;
  204. letter-spacing: 4rpx;
  205. }
  206. .referral-code-copy {
  207. font-size: 24rpx;
  208. color: #5B9BD5;
  209. padding: 4rpx 16rpx;
  210. border: 1rpx solid #5B9BD5;
  211. border-radius: 8rpx;
  212. }
  213. </style>