earn-points.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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" :class="{ disabled: rule.ruleType === 1 && isSignedToday }" @click="handleAction(rule)">
  26. {{ rule.ruleType === 1 && isSignedToday ? '已签到' : 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. isSignedToday: false // 今日是否已签到
  54. }
  55. },
  56. onLoad() {
  57. this.initData()
  58. },
  59. onShow() {
  60. // 每次显示页面时刷新数据,确保数据同步
  61. if (this.makerId) {
  62. this.loadBalance()
  63. this.checkSignInStatus()
  64. }
  65. },
  66. methods: {
  67. async initData() {
  68. const userInfo = uni.getStorageSync('userInfo')
  69. if (userInfo && userInfo.matchmakerId) {
  70. this.makerId = userInfo.matchmakerId
  71. } else if (userInfo && userInfo.userId) {
  72. // 如果没有matchmakerId,通过API获取
  73. try {
  74. const res = await api.matchmaker.getByUserId(userInfo.userId)
  75. let matchmaker = res
  76. if (res && res.data) {
  77. matchmaker = res.data
  78. }
  79. if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
  80. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  81. // 保存到userInfo中
  82. userInfo.matchmakerId = this.makerId
  83. uni.setStorageSync('userInfo', userInfo)
  84. }
  85. } catch (e) {
  86. console.error('获取红娘信息失败:', e)
  87. }
  88. }
  89. await Promise.all([
  90. this.loadBalance(),
  91. this.loadRules(),
  92. this.checkSignInStatus()
  93. ])
  94. },
  95. // 检查今日签到状态
  96. async checkSignInStatus() {
  97. if (!this.makerId) return
  98. try {
  99. const res = await api.matchmaker.checkinStatus(this.makerId)
  100. // 解析返回数据
  101. let data = res
  102. if (res && res.data !== undefined) {
  103. data = res.data
  104. }
  105. this.isSignedToday = data === true || data?.isCheckedIn === true || data?.checked === true
  106. } catch (e) {
  107. console.error('检查签到状态失败:', e)
  108. }
  109. },
  110. async loadBalance() {
  111. if (!this.makerId) return
  112. try {
  113. const res = await api.pointsMall.getBalance(this.makerId)
  114. this.balance = res.balance || 0
  115. } catch (e) {
  116. console.error('获取积分余额失败:', e)
  117. }
  118. },
  119. async loadRules() {
  120. try {
  121. const res = await api.pointsMall.getRules()
  122. this.rules = res || []
  123. } catch (e) {
  124. console.error('获取积分规则失败:', e)
  125. }
  126. },
  127. handleBack() {
  128. uni.navigateBack()
  129. },
  130. getIcon(ruleType) {
  131. const icons = {
  132. 1: '📅', // 签到
  133. 2: '📤', // 上传线索
  134. 3: '💕', // 撮合成功
  135. 4: '📚', // 完成培训
  136. 5: '🎁' // 活动奖励
  137. }
  138. return icons[ruleType] || '⭐'
  139. },
  140. getDesc(ruleType) {
  141. const descs = {
  142. 1: '每日签到即可获得积分',
  143. 2: '上传优质客户线索',
  144. 3: '成功撮合一对情侣',
  145. 4: '完成红娘培训课程',
  146. 5: '参与平台活动获得'
  147. }
  148. return descs[ruleType] || '完成任务获得积分'
  149. },
  150. getActionText(ruleType) {
  151. const texts = {
  152. 1: '去签到',
  153. 2: '去上传',
  154. 3: '查看',
  155. 4: '去学习',
  156. 5: '查看'
  157. }
  158. return texts[ruleType] || '去完成'
  159. },
  160. async handleAction(rule) {
  161. if (rule.ruleType === 1) {
  162. // 签到 - 先检查是否已签到
  163. if (this.isSignedToday) {
  164. uni.showToast({ title: '今日已签到', icon: 'none' })
  165. return
  166. }
  167. await this.doSignIn(rule)
  168. } else if (rule.ruleType === 2) {
  169. // 上传线索
  170. uni.navigateTo({
  171. url: '/pages/matchmaker-workbench/add-resource'
  172. })
  173. } else if (rule.ruleType === 4) {
  174. // 培训课程
  175. uni.navigateTo({
  176. url: '/pages/courses/list'
  177. })
  178. } else {
  179. uni.showToast({
  180. title: '功能开发中',
  181. icon: 'none'
  182. })
  183. }
  184. },
  185. async doSignIn(rule) {
  186. if (!this.makerId) {
  187. uni.showToast({ title: '请先登录', icon: 'none' })
  188. return
  189. }
  190. try {
  191. // 使用红娘签到接口
  192. const res = await api.matchmaker.doCheckin(this.makerId)
  193. // 签到成功后更新状态
  194. this.isSignedToday = true
  195. // 刷新积分余额
  196. await this.loadBalance()
  197. uni.showToast({
  198. title: `签到成功,+${rule.pointValue}积分`,
  199. icon: 'success'
  200. })
  201. } catch (e) {
  202. console.error('签到失败:', e)
  203. // 如果是已签到的错误,更新状态
  204. if (e.message && e.message.includes('已签到')) {
  205. this.isSignedToday = true
  206. }
  207. uni.showToast({
  208. title: e.message || '签到失败',
  209. icon: 'none'
  210. })
  211. }
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .earn-points {
  218. min-height: 100vh;
  219. background: #F5F5F5;
  220. }
  221. .header {
  222. display: flex;
  223. align-items: center;
  224. justify-content: space-between;
  225. padding: 25rpx 30rpx;
  226. padding-top: calc(25rpx + env(safe-area-inset-top));
  227. background: #FFFFFF;
  228. .back-icon {
  229. width: 44rpx;
  230. height: 44rpx;
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. font-size: 32rpx;
  235. color: #333;
  236. &::before { content: '‹'; }
  237. }
  238. .header-title {
  239. font-size: 36rpx;
  240. font-weight: bold;
  241. color: #333;
  242. }
  243. .header-right {
  244. width: 44rpx;
  245. }
  246. }
  247. .current-points {
  248. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  249. margin: 30rpx;
  250. padding: 40rpx;
  251. border-radius: 20rpx;
  252. display: flex;
  253. align-items: center;
  254. justify-content: space-between;
  255. .label {
  256. font-size: 30rpx;
  257. color: rgba(255, 255, 255, 0.8);
  258. }
  259. .value {
  260. font-size: 56rpx;
  261. font-weight: bold;
  262. color: #FFFFFF;
  263. }
  264. }
  265. .rules-section {
  266. background: #FFFFFF;
  267. margin: 0 30rpx 30rpx;
  268. border-radius: 20rpx;
  269. padding: 30rpx;
  270. .section-title {
  271. font-size: 30rpx;
  272. font-weight: bold;
  273. color: #333;
  274. margin-bottom: 30rpx;
  275. }
  276. }
  277. .rule-list {
  278. .rule-item {
  279. display: flex;
  280. align-items: center;
  281. padding: 25rpx 0;
  282. border-bottom: 1rpx solid #F0F0F0;
  283. &:last-child {
  284. border-bottom: none;
  285. }
  286. .rule-icon {
  287. font-size: 48rpx;
  288. margin-right: 20rpx;
  289. }
  290. .rule-info {
  291. flex: 1;
  292. .rule-name {
  293. font-size: 28rpx;
  294. font-weight: bold;
  295. color: #333;
  296. margin-bottom: 8rpx;
  297. }
  298. .rule-desc {
  299. font-size: 24rpx;
  300. color: #999;
  301. }
  302. }
  303. .rule-points {
  304. font-size: 32rpx;
  305. font-weight: bold;
  306. color: #FF9800;
  307. margin-right: 20rpx;
  308. }
  309. .rule-action {
  310. padding: 12rpx 24rpx;
  311. background: linear-gradient(135deg, #9C27B0 0%, #E91E63 100%);
  312. color: #FFFFFF;
  313. font-size: 24rpx;
  314. border-radius: 30rpx;
  315. &.disabled {
  316. background: #CCCCCC;
  317. color: #FFFFFF;
  318. }
  319. }
  320. }
  321. }
  322. .tips-section {
  323. background: #FFFFFF;
  324. margin: 0 30rpx 30rpx;
  325. border-radius: 20rpx;
  326. padding: 30rpx;
  327. .section-title {
  328. font-size: 30rpx;
  329. font-weight: bold;
  330. color: #333;
  331. margin-bottom: 20rpx;
  332. }
  333. .tips-content {
  334. .tip-item {
  335. font-size: 26rpx;
  336. color: #666;
  337. line-height: 2;
  338. }
  339. }
  340. }
  341. </style>