index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {
  2. getUserInfo,
  3. getVipInfo
  4. } from '~/api/user'
  5. import {
  6. getProducts,
  7. getTasks,
  8. submitTask
  9. } from '~/api/global'
  10. import {
  11. getOpenidNoLogin
  12. } from '~/utils/httpUtilNoLogin';
  13. import httpRequestApi from '~/utils/APIClient';
  14. let app = getApp()
  15. Page({
  16. data: {
  17. userInfo: {},
  18. vipTime: '',
  19. isIos: false,
  20. tasks: [],
  21. // isIos: app.globalData.isIOS,
  22. productNum: {},
  23. productVip: {}
  24. },
  25. onLoad() {
  26. this.getProducts()
  27. },
  28. async onShow() {
  29. let uid = wx.getStorageSync('uid') || ''
  30. // 没登陆先走静默登录,登录后直接获取用户信息
  31. if (!uid) {
  32. getOpenidNoLogin(async () => {
  33. this.setUserInfo()
  34. })
  35. } else {
  36. this.setUserInfo()
  37. }
  38. },
  39. // 设置用户信息及vip状态和任务完成情况
  40. async setUserInfo() {
  41. let userInfo = await getUserInfo()
  42. let vipTime = await getVipInfo()
  43. this.getTasks()
  44. this.setData({
  45. userInfo,
  46. vipTime,
  47. })
  48. console.log(userInfo);
  49. // 如果用户没有头像及昵称的话就提醒获取
  50. if (!userInfo.user.avatar && !userInfo.user.wechatName) {
  51. wx.navigateTo({
  52. url: `/pages/login/login`
  53. });
  54. }
  55. },
  56. async getTasks() {
  57. let tasks = await getTasks()
  58. this.setData({
  59. tasks
  60. })
  61. },
  62. async getProducts() {
  63. let products = await getProducts()
  64. let productVip = products.find(item => {
  65. return item.type == 1
  66. })
  67. let productNum = products.find(item => {
  68. return item.type == 2
  69. })
  70. console.log(productNum, productVip);
  71. this.setData({
  72. productNum,
  73. productVip
  74. })
  75. },
  76. // 支付
  77. toPay({
  78. currentTarget
  79. }) {
  80. let type = currentTarget.dataset.type
  81. },
  82. // 提交任务
  83. async submitTask({
  84. currentTarget
  85. }) {
  86. let id = currentTarget.dataset.type
  87. await submitTask({
  88. id
  89. })
  90. wx.showToast({
  91. title: id == '1' ? '签到成功!' : id == 3 ? "观看成功!" : "",
  92. icon: "none"
  93. })
  94. this.getTasks()
  95. },
  96. jump({
  97. currentTarget
  98. }) {
  99. let url = currentTarget.dataset.url
  100. wx.navigateTo({
  101. url: url
  102. });
  103. },
  104. goToService() {
  105. httpRequestApi.userEvent('SERVICE');
  106. },
  107. switcher({
  108. currentTarget
  109. }) {
  110. wx.reLaunch({
  111. url: `/pages/index/index?tabbarIndx=${currentTarget.dataset.index}`
  112. });
  113. },
  114. rewardedVideo() {
  115. if (this.data.tasks.length != 3 || this.data.tasks[2].completed) {
  116. return
  117. }
  118. this.selectComponent('#advert').rewardedVideo();
  119. }
  120. })