downTimer.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. this.setData({ isPrizetable: newVal });
  20. }
  21. },
  22. isShareGroup: {
  23. type: Boolean,
  24. observer: function (newVal) {
  25. this.setData({ isShareGroup: newVal });
  26. }
  27. },
  28. listData: {
  29. type: Object,
  30. observer: function (newVal) {
  31. this.setData({ listData: newVal });
  32. }
  33. },
  34. },
  35. data: {
  36. cardOverUsers: [],
  37. source: 0,
  38. downTimer: null,
  39. inTimer: null,
  40. index: 0,
  41. show: false,
  42. isShow: false,
  43. isPrizetable: false, //是否在大转盘页面
  44. isShareGroup: false, //是否为分享家或者机构轮播
  45. listData: {},//大转盘或分享家页面传递数据
  46. },
  47. pageLifetimes: {
  48. show() {
  49. this.getSold();
  50. },
  51. hide() {
  52. clearTimeout(this.data.downTimer);
  53. clearTimeout(this.data.inTimer);
  54. }
  55. },
  56. methods: {
  57. downTime() {
  58. let that = this;
  59. that.data.downTimer = setTimeout(() => {
  60. // 首页使用:order/soldRecord返回数据大于index;分享家页面或大转盘页面展示:对应状态值为true且传过来的的数据大于1
  61. if (that.data.index < that.data.cardOverUsers.length - 1 || ((that.data.isPrizetable || this.data.isShareGroup) && that.data.index < that.data.listData.length - 1)) {
  62. that.data.index++;
  63. } else {
  64. // index等于数据数组长度-1时重置index
  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. // 大转盘或者分享家
  88. if (that.data.isPrizetable || this.data.isShareGroup) {
  89. that.setData({ show: false, isShow: false, index: 0, downTimer: null, inTimer: null });
  90. that.downTime();
  91. setTimeout(function () {
  92. that.setData({ isShow: true });
  93. }, 3000);
  94. } else {
  95. util.ajax({
  96. func: "order/soldRecord",
  97. data: { "source": that.data.source, "aid": that.data.aid },
  98. load: false
  99. }, function (res) {
  100. if (res.code == 0) {
  101. // 有数据
  102. if (res.data && res.data.length > 0) {
  103. that.setData({ show: false, isShow: false, index: 0, downTimer: null, inTimer: null, cardOverUsers: res.data });
  104. that.downTime();
  105. setTimeout(function () {
  106. that.setData({ isShow: true });
  107. }, 3000);
  108. }
  109. }
  110. })
  111. }
  112. }
  113. }
  114. })