index.js 3.2 KB

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