downTimer.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. const util = require("../../utils/util.js");
  2. Component({
  3. properties: {
  4. aid: {
  5. type: String,
  6. observer: function (aid) {
  7. this.setData({ aid });
  8. }
  9. },
  10. source:{
  11. type:Number,
  12. observer: function (source){
  13. this.setData({ source});
  14. }
  15. },
  16. isPrizetable:{
  17. type:Boolean,
  18. observer: function (newVal){
  19. console.log(newVal)
  20. this.setData({ isPrizetable:newVal});
  21. }
  22. },
  23. isShareGroup:{
  24. type:Boolean,
  25. observer: function (newVal){
  26. console.log(newVal)
  27. this.setData({ isShareGroup:newVal});
  28. }
  29. },
  30. listData:{
  31. type:Object,
  32. observer: function (newVal){
  33. this.setData({ listData:newVal});
  34. }
  35. },
  36. },
  37. data: {
  38. cardOverUsers:[],
  39. source: 0,
  40. downTimer:null,
  41. inTimer:null,
  42. index: 0,
  43. show:false,
  44. isShow:false,
  45. isPrizetable:false, //是否在大转盘页面
  46. isShareGroup:false, //是否为分享家或者机构轮播
  47. listData:{}
  48. },
  49. pageLifetimes:{
  50. show(){
  51. this.getSold();
  52. },
  53. hide() {
  54. clearTimeout(this.data.downTimer);
  55. clearTimeout(this.data.inTimer);
  56. }
  57. },
  58. methods: {
  59. downTime() {
  60. let that = this;
  61. that.data.downTimer = setTimeout(() => {
  62. if (that.data.index < ((that.data.cardOverUsers.length && (!that.data.isPrizetable || !that.data.isShareGroup)) || that.data.listData.length) - 1) {
  63. that.data.index++;
  64. } else {
  65. that.data.index = 0;
  66. }
  67. that.setData({ show: true, index: that.data.index });
  68. that.data.inTimer = setTimeout(() => {
  69. that.setData({ show: false });
  70. that.downTime();
  71. }, 3000);
  72. }, 2000);
  73. },
  74. img(e){
  75. let index = e.currentTarget.dataset.index;
  76. this.data.cardOverUsers[index].avatar = '/images/default_logo.jpg';
  77. this.setData({ cardOverUsers: this.data.cardOverUsers});
  78. },
  79. goActivity(e){
  80. if (this.data.source == 1) return false;
  81. wx.navigateTo({
  82. url: '/pages/product/activity/index?aid=' + e.currentTarget.dataset.aid,
  83. });
  84. },
  85. getSold(){
  86. let that = this;
  87. if (that.data.isPrizetable || this.data.isShareGroup) {
  88. that.setData({ show: false, isShow: false, index: 0, downTimer: null, inTimer: null});
  89. that.downTime();
  90. setTimeout(function(){
  91. that.setData({ isShow: true});
  92. }, 3000);
  93. } else {
  94. util.ajax({
  95. func:"order/soldRecord",
  96. data: { "source": that.data.source, "aid": that.data.aid},
  97. load:false
  98. },function(res){
  99. if(res.code == 0){
  100. that.setData({ show: false, isShow: false, index: 0, downTimer: null, inTimer: null, cardOverUsers: res.data });
  101. that.downTime();
  102. setTimeout(function(){
  103. that.setData({ isShow: true});
  104. }, 3000);
  105. }
  106. })
  107. }
  108. }
  109. }
  110. })