index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/member-center/index.js
  2. import { userLevelGrade, userLevelTask, userLevelDetection } from '../../api/user.js'
  3. import { getProductHot } from '../../api/store.js'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. parameter: {
  11. navbar: '1',
  12. return: '1',
  13. title: '会员中心',
  14. class: '1',
  15. color: true
  16. },
  17. VipList: [],
  18. indicatorDots: false,
  19. circular: true,
  20. autoplay: false,
  21. interval: 3000,
  22. duration: 500,
  23. swiperIndex: 0,
  24. growthValue: true,
  25. task: [], //任务列表
  26. illustrate: '', //任务说明
  27. level_id: 0, //任务id,
  28. host_product: [],
  29. grade: 0
  30. },
  31. /**
  32. * 授权回调
  33. */
  34. onLoadFun: function () {
  35. this.setLeveLComplete()
  36. this.get_host_product()
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. var that = this
  43. setTimeout(function () {
  44. that.setData({
  45. loading: true
  46. })
  47. }, 500)
  48. },
  49. /**
  50. * 获取我的推荐
  51. */
  52. get_host_product: function () {
  53. var that = this
  54. getProductHot().then(res => {
  55. that.setData({
  56. host_product: res.data
  57. })
  58. })
  59. },
  60. /**
  61. * 会员切换
  62. */
  63. bindchange(e) {
  64. var index = e.detail.current
  65. this.setData({
  66. swiperIndex: index,
  67. level_id: this.data.VipList[index].id || 0
  68. })
  69. this.getTask()
  70. },
  71. /**
  72. * 关闭说明
  73. */
  74. growthValue: function () {
  75. this.setData({
  76. growthValue: true
  77. })
  78. },
  79. /**
  80. * 打开说明
  81. */
  82. opHelp: function (e) {
  83. var index = e.currentTarget.dataset.index
  84. this.setData({
  85. growthValue: false,
  86. illustrate: this.data.task[index].illustrate
  87. })
  88. },
  89. /**
  90. * 设置会员
  91. */
  92. setLeveLComplete: function () {
  93. let that = this
  94. userLevelDetection().then(res => {
  95. that.getVipList()
  96. })
  97. },
  98. /**
  99. * 获取会员等级
  100. */
  101. getVipList: function () {
  102. let that = this
  103. userLevelGrade().then(res => {
  104. that.setData({
  105. VipList: res.data.list,
  106. task: res.data.task.task,
  107. reach_count: res.data.task.reach_count,
  108. level_id: res.data.list[0] ? res.data.list[0].id : 0
  109. })
  110. let arr = []
  111. res.data.list.forEach(function (item, index) {
  112. if (item.is_clear == true) {
  113. arr.push(item.grade)
  114. }
  115. })
  116. that.setData({
  117. grade: arr[0]
  118. })
  119. })
  120. },
  121. /**
  122. * 获取任务要求
  123. */
  124. getTask: function () {
  125. var that = this
  126. userLevelTask(that.data.level_id).then(res => {
  127. that.setData({
  128. task: res.data.task,
  129. reach_count: res.data.reach_count
  130. })
  131. })
  132. }
  133. })