index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // Snailfish_shop/pages/spike/index.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. currentTab: 0,
  10. endTime: '2018-11-30 14:56:11',
  11. countDown: {
  12. day: '00',
  13. hou: '00',
  14. min: '00',
  15. sec: '00'
  16. },
  17. nav_list:[],
  18. loadover: false,
  19. no_order: 0,
  20. cur_key:'',
  21. cur_type:'',
  22. goods: [],
  23. page: 1,
  24. isHideLoadMore: true,
  25. showTpo: true
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. var that = this;
  32. app.util.request({
  33. 'url': 'entry/wxapp/index',
  34. 'data': {
  35. controller: 'index.spike_index'
  36. },
  37. dataType: 'json',
  38. success: function (res) {
  39. if(res.data.code == 0)
  40. {
  41. var cur_tab = res.data.data[0];
  42. that.setData({
  43. cur_type:cur_tab.type,
  44. cur_key: cur_tab.key,
  45. endTime: cur_tab.end_time,
  46. nav_list:res.data.data
  47. })
  48. that.countDown();
  49. that.getData();
  50. }
  51. }
  52. })
  53. //this.countDown();
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. goLink2: function (e) {
  61. var cur_type = this.data.cur_type;
  62. if(cur_type =='wait')
  63. {
  64. return false;
  65. }
  66. var link = e.currentTarget.dataset.link;
  67. var pages_all = getCurrentPages();
  68. if (pages_all.length > 3) {
  69. wx.redirectTo({
  70. url: link
  71. })
  72. } else {
  73. wx.navigateTo({
  74. url: link
  75. })
  76. }
  77. },
  78. getData: function () {
  79. this.setData({
  80. isHideLoadMore: true
  81. })
  82. this.data.no_order = 1
  83. var page = this.data.page;
  84. var cur_key = this.data.cur_key;
  85. var self = this;
  86. app.util.request({
  87. 'url': 'entry/wxapp/index',
  88. 'data': {
  89. controller: 'index.load_spike_data',
  90. 'cur_key': cur_key,
  91. page: page
  92. },
  93. dataType: 'json',
  94. success: function (data) {
  95. console.log(data);
  96. if (data.data.code == 0) {
  97. var agoData = self.data.goods;
  98. var goods = data.data.data;
  99. goods.map(function (good) {
  100. agoData.push(good);
  101. });
  102. self.setData({
  103. goods: agoData,
  104. 'no_order': 0
  105. });
  106. } else {
  107. self.setData({
  108. isHideLoadMore: true,
  109. showTpo: false
  110. })
  111. return false;
  112. }
  113. }
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 切换Tab
  128. */
  129. changeTab: function (e) {
  130. let idx = e.currentTarget.dataset.index || 0;
  131. console.log(idx);
  132. //data-key='{{item.key}}' data-index="{{index}}" data-type="{{item.type}}"
  133. var cur_key = e.currentTarget.dataset.key;
  134. var cur_type = e.currentTarget.dataset.type;
  135. this.setData({
  136. currentTab: idx,
  137. cur_key: cur_key,
  138. goods: [],
  139. isHideLoadMore:true,
  140. showTpo:true,
  141. page: 1,
  142. cur_type: cur_type
  143. })
  144. this.getData();
  145. },
  146. //小于10的格式化函数
  147. timeFormat: function (param) {
  148. return param < 10 ? '0' + param : param;
  149. },
  150. //倒计时函数
  151. countDown: function () {
  152. let newTime = new Date().getTime();
  153. let o = this.data.endTime;
  154. let endTime = new Date(o).getTime();
  155. let obj = null;
  156. // 如果活动未结束,对时间进行处理
  157. if (endTime - newTime > 0) {
  158. let time = (endTime - newTime) / 1000;
  159. // 获取天、时、分、秒
  160. let day = parseInt(time / (60 * 60 * 24));
  161. let hou = parseInt(time % (60 * 60 * 24) / 3600);
  162. let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
  163. let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
  164. obj = {
  165. day: this.timeFormat(day),
  166. hou: this.timeFormat(hou),
  167. min: this.timeFormat(min),
  168. sec: this.timeFormat(sec)
  169. }
  170. } else {//活动已结束,全部设置为'00'
  171. obj = {
  172. day: '00',
  173. hou: '00',
  174. min: '00',
  175. sec: '00'
  176. }
  177. }
  178. // 渲染,然后每隔一秒执行一次倒计时函数
  179. this.setData({ countDown: obj })
  180. setTimeout(this.countDown, 1000);
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload: function () {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh: function () {
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. onReachBottom: function () {
  196. if (this.data.no_order == 1) return false;
  197. this.data.page += 1;
  198. this.getData();
  199. this.setData({
  200. isHideLoadMore: false
  201. })
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage: function () {
  207. }
  208. })