index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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({ host_product: res.data });
  56. });
  57. },
  58. /**
  59. * 会员切换
  60. *
  61. */
  62. bindchange(e) {
  63. var index = e.detail.current
  64. this.setData({swiperIndex: index,level_id: this.data.VipList[index].id || 0});
  65. this.getTask();
  66. },
  67. /**
  68. * 关闭说明
  69. */
  70. growthValue:function(){
  71. this.setData({growthValue: true})
  72. },
  73. /**
  74. * 打开说明
  75. */
  76. opHelp:function(e){
  77. var index = e.currentTarget.dataset.index;
  78. this.setData({ growthValue: false, illustrate: this.data.task[index].illustrate});
  79. },
  80. /**
  81. * 设置会员
  82. */
  83. setLeveLComplete:function(){
  84. let that = this;
  85. userLevelDetection().then(res=>{
  86. that.getVipList();
  87. });
  88. },
  89. /**
  90. * 获取会员等级
  91. *
  92. */
  93. getVipList:function(){
  94. let that=this;
  95. userLevelGrade().then(res=>{
  96. that.setData({
  97. VipList: res.data.list,
  98. task: res.data.task.task,
  99. reach_count: res.data.task.reach_count,
  100. level_id: res.data.list[0] ? res.data.list[0].id : 0
  101. });
  102. let arr = [];
  103. res.data.list.forEach(function (item, index) {
  104. if (item.is_clear == true) {
  105. arr.push(item.grade);
  106. }
  107. });
  108. that.setData({
  109. grade: arr[0]
  110. });
  111. });
  112. },
  113. /**
  114. * 获取任务要求
  115. */
  116. getTask:function(){
  117. var that=this;
  118. userLevelTask(that.data.level_id).then(res=>{
  119. that.setData({ task: res.data.task, reach_count: res.data.reach_count });
  120. });
  121. },
  122. })