earn-points.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <view class="earn-points">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-icon" @click="handleBack"></view>
  6. <text class="header-title">赚取积分</text>
  7. <view class="header-right"></view>
  8. </view>
  9. <!-- 当前积分 -->
  10. <view class="current-points">
  11. <text class="label">当前积分</text>
  12. <text class="value">{{ balance }}</text>
  13. </view>
  14. <!-- 积分规则列表 -->
  15. <view class="rules-section">
  16. <view class="section-title">积分获取方式</view>
  17. <view class="rule-list">
  18. <view class="rule-item" v-for="(rule, index) in rules" :key="index">
  19. <view class="rule-icon">{{ getIcon(rule.ruleType) }}</view>
  20. <view class="rule-info">
  21. <view class="rule-name">{{ rule.ruleName }}</view>
  22. <view class="rule-desc">{{ getDesc(rule.ruleType) }}</view>
  23. </view>
  24. <view class="rule-points">+{{ rule.pointValue }}</view>
  25. <view class="rule-action" @click="handleAction(rule)">
  26. {{ getActionText(rule.ruleType) }}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 积分说明 -->
  32. <view class="tips-section">
  33. <view class="section-title">积分说明</view>
  34. <view class="tips-content">
  35. <view class="tip-item">1. 积分可在积分商城兑换精美礼品</view>
  36. <view class="tip-item">2. 每日签到可获得积分奖励</view>
  37. <view class="tip-item">3. 上传优质线索可获得额外积分</view>
  38. <view class="tip-item">4. 撮合成功可获得大量积分奖励</view>
  39. <view class="tip-item">5. 积分永久有效,请放心使用</view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import api from '@/utils/api.js'
  46. export default {
  47. name: 'earn-points',
  48. data() {
  49. return {
  50. balance: 0,
  51. rules: [],
  52. makerId: null
  53. }
  54. },
  55. onLoad() {
  56. this.initData()
  57. },
  58. methods: {
  59. async initData() {
  60. const userInfo = uni.getStorageSync('userInfo')
  61. if (userInfo && userInfo.matchmakerId) {
  62. this.makerId = userInfo.matchmakerId
  63. } else if (userInfo && userInfo.userId) {
  64. this.makerId = userInfo.userId
  65. }
  66. await Promise.all([
  67. this.loadBalance(),
  68. this.loadRules()
  69. ])
  70. },
  71. async loadBalance() {
  72. if (!this.makerId) return
  73. try {
  74. const res = await api.pointsMall.getBalance(this.makerId)
  75. this.balance = res.balance || 0
  76. } catch (e) {
  77. console.error('获取积分余额失败:', e)
  78. }
  79. },
  80. async loadRules() {
  81. try {
  82. const res = await api.pointsMall.getRules()
  83. this.rules = res || []
  84. } catch (e) {
  85. console.error('获取积分规则失败:', e)
  86. }
  87. },
  88. handleBack() {
  89. uni.navigateBack()
  90. },
  91. getIcon(ruleType) {
  92. const icons = {
  93. 1: '📅', // 签到
  94. 2: '📤', // 上传线索
  95. 3: '💕', // 撮合成功
  96. 4: '📚', // 完成培训
  97. 5: '🎁' // 活动奖励
  98. }
  99. return icons[ruleType] || '⭐'
  100. },
  101. getDesc(ruleType) {
  102. const descs = {
  103. 1: '每日签到即可获得积分',
  104. 2: '上传优质客户线索',
  105. 3: '成功撮合一对情侣',
  106. 4: '完成红娘培训课程',
  107. 5: '参与平台活动获得'
  108. }
  109. return descs[ruleType] || '完成任务获得积分'
  110. },
  111. getActionText(ruleType) {
  112. const texts = {
  113. 1: '去签到',
  114. 2: '去上传',
  115. 3: '查看',
  116. 4: '去学习',
  117. 5: '查看'
  118. }
  119. return texts[ruleType] || '去完成'
  120. },
  121. async handleAction(rule) {
  122. if (rule.ruleType === 1) {
  123. // 签到
  124. await this.doSignIn(rule)
  125. } else if (rule.ruleType === 2) {
  126. // 上传线索
  127. uni.navigateTo({
  128. url: '/pages/matchmaker-workbench/add-resource'
  129. })
  130. } else if (rule.ruleType === 4) {
  131. // 培训课程
  132. uni.navigateTo({
  133. url: '/pages/courses/list'
  134. })
  135. } else {
  136. uni.showToast({
  137. title: '功能开发中',
  138. icon: 'none'
  139. })
  140. }
  141. },
  142. async doSignIn(rule) {
  143. if (!this.makerId) {
  144. uni.showToast({ title: '请先登录', icon: 'none' })
  145. return
  146. }
  147. try {
  148. const res = await api.pointsMall.addPoints(this.makerId, rule.ruleType, '每日签到')
  149. uni.showToast({
  150. title: `签到成功,+${res.addedPoints}积分`,
  151. icon: 'success'
  152. })
  153. this.balance = res.newBalance
  154. } catch (e) {
  155. console.error('签到失败:', e)
  156. uni.showToast({
  157. title: e.message || '签到失败',
  158. icon: 'none'
  159. })
  160. }
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .earn-points {
  167. min-height: 100vh;
  168. background: #F5F5F5;
  169. }
  170. .header {
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. padding: 25rpx 30rpx;
  175. padding-top: calc(25rpx + env(safe-area-inset-top));
  176. background: #FFFFFF;
  177. .back-icon {
  178. width: 44rpx;
  179. height: 44rpx;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. font-size: 32rpx;
  184. color: #333;
  185. &::before { content: '‹'; }
  186. }
  187. .header-title {
  188. font-size: 36rpx;
  189. font-weight: bold;
  190. color: #333;
  191. }
  192. .header-right {
  193. width: 44rpx;
  194. }
  195. }
  196. .current-points {
  197. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  198. margin: 30rpx;
  199. padding: 40rpx;
  200. border-radius: 20rpx;
  201. display: flex;
  202. align-items: center;
  203. justify-content: space-between;
  204. .label {
  205. font-size: 30rpx;
  206. color: rgba(255, 255, 255, 0.8);
  207. }
  208. .value {
  209. font-size: 56rpx;
  210. font-weight: bold;
  211. color: #FFFFFF;
  212. }
  213. }
  214. .rules-section {
  215. background: #FFFFFF;
  216. margin: 0 30rpx 30rpx;
  217. border-radius: 20rpx;
  218. padding: 30rpx;
  219. .section-title {
  220. font-size: 30rpx;
  221. font-weight: bold;
  222. color: #333;
  223. margin-bottom: 30rpx;
  224. }
  225. }
  226. .rule-list {
  227. .rule-item {
  228. display: flex;
  229. align-items: center;
  230. padding: 25rpx 0;
  231. border-bottom: 1rpx solid #F0F0F0;
  232. &:last-child {
  233. border-bottom: none;
  234. }
  235. .rule-icon {
  236. font-size: 48rpx;
  237. margin-right: 20rpx;
  238. }
  239. .rule-info {
  240. flex: 1;
  241. .rule-name {
  242. font-size: 28rpx;
  243. font-weight: bold;
  244. color: #333;
  245. margin-bottom: 8rpx;
  246. }
  247. .rule-desc {
  248. font-size: 24rpx;
  249. color: #999;
  250. }
  251. }
  252. .rule-points {
  253. font-size: 32rpx;
  254. font-weight: bold;
  255. color: #FF9800;
  256. margin-right: 20rpx;
  257. }
  258. .rule-action {
  259. padding: 12rpx 24rpx;
  260. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  261. color: #FFFFFF;
  262. font-size: 24rpx;
  263. border-radius: 30rpx;
  264. }
  265. }
  266. }
  267. .tips-section {
  268. background: #FFFFFF;
  269. margin: 0 30rpx 30rpx;
  270. border-radius: 20rpx;
  271. padding: 30rpx;
  272. .section-title {
  273. font-size: 30rpx;
  274. font-weight: bold;
  275. color: #333;
  276. margin-bottom: 20rpx;
  277. }
  278. .tips-content {
  279. .tip-item {
  280. font-size: 26rpx;
  281. color: #666;
  282. line-height: 2;
  283. }
  284. }
  285. }
  286. </style>