index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const util = require("../../utils/util.js");
  2. const config = require("../../utils/config.js");
  3. const app = getApp();
  4. var updateTimer;
  5. Page({
  6. data: {
  7. swiperIndex:0,
  8. swiperList:[],
  9. equity:{},
  10. swiper:{
  11. next: 0,
  12. previous: 0
  13. },
  14. questionShow:false
  15. },
  16. onLoad: function () {
  17. clearTimeout(updateTimer);
  18. this.getList();
  19. },
  20. getList(){
  21. let that = this;
  22. util.ajax({
  23. func: "v2/user/growthCard/list",
  24. }, function (res) {
  25. if (res.code == 0) {
  26. if(res.data.list.length > 1){
  27. that.data.swiper.next = 150;
  28. }
  29. that.setData({ swiperList: res.data.list, swiper: that.data.swiper });
  30. that.getEquity();
  31. }else{
  32. util.showTips(res.reason)
  33. }
  34. })
  35. },
  36. getEquity() {
  37. let that = this;
  38. util.ajax({
  39. func: "v2/user/growthCard/equity",
  40. data:{id:that.data.swiperList[that.data.swiperIndex].id}
  41. }, function (res) {
  42. if (res.code == 0) {
  43. that.setData({equity:res.data});
  44. if(!util.isObjEmpty(res.data.equityThree)){
  45. that.updateTime();
  46. }
  47. } else {
  48. util.showTips(res.reason)
  49. }
  50. })
  51. },
  52. updateTime() {
  53. let that = this, equity = this.data.equity, i = 0;
  54. equity.equityThree.forEach((item, index) => {
  55. let lag = item.saleTime/ 1000;
  56. if (lag > 0) {
  57. equity.equityThree[index].updateTime = util.isTimeLeng(Math.floor((lag / 3600) % 60)) + ":" + util.isTimeLeng(Math.floor((lag / 60) % 60)) + ":" + util.isTimeLeng(Math.floor(lag % 60));
  58. equity.equityThree[index].saleTime = item.saleTime-1000;
  59. i = 1;
  60. } else {
  61. equity.equityThree[index].updateTime = null;
  62. }
  63. });
  64. that.setData({ equity: equity });
  65. if (i == 0){
  66. clearTimeout(updateTimer);
  67. }else{
  68. updateTimer = setTimeout(function () {
  69. that.updateTime();
  70. }, 1000);
  71. }
  72. },
  73. swiperChange(e){
  74. let index = e.detail.current, count = this.data.swiperList.length - 1;
  75. if (index == 0) {
  76. this.data.swiper.next = 150;
  77. this.data.swiper.previous = 0;
  78. }
  79. if (index > 0 && index < count){
  80. this.data.swiper.next = 75;
  81. this.data.swiper.previous = 75;
  82. }
  83. if (index == count) {
  84. this.data.swiper.next = 0;
  85. this.data.swiper.previous = 150;
  86. }
  87. this.setData({ swiperIndex: index, swiper: this.data.swiper });
  88. clearTimeout(updateTimer);
  89. this.getEquity();
  90. },
  91. questionClick(){
  92. wx.showModal({
  93. title:"赠送说明",
  94. content: "券全部未使用时,可赠送亲友;券部分已使用,则不允许赠送;赠送后,在个人中心不再显示。",
  95. showCancel:false,
  96. confirmText:"知道了"
  97. })
  98. },
  99. vouche(e){
  100. if (e.currentTarget.dataset.status == 1){
  101. wx.navigateTo({
  102. url: '/pages/growthCard/activity?vid=' + e.currentTarget.dataset.vid
  103. });
  104. }
  105. },
  106. binderror(e){
  107. var index = e.currentTarget.dataset.index;
  108. this.data.equity.equityThree[index].logo = '/images/noimg.png';
  109. this.setData({ equity: this.data.equity });
  110. },
  111. onShareAppMessage: function (options) {
  112. let that = this, data = that.data.swiperList[that.data.swiperIndex];
  113. if(options.from=="button"){
  114. return {
  115. title: '送你一张冬夏令营成长卡,让宝贝去探索、去挑战、去成长!',
  116. path: '/pages/growthCard/give?id='+data.id,
  117. imageUrl: util.config.imgUrl + '/img/group_card_share.jpg'
  118. }
  119. }
  120. }
  121. })