index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/bargain-record/index.js
  2. import { getBargainUserList, bargainUserCancel } from '../../../api/activity.js';
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. parameter: {
  10. 'navbar': '1',
  11. 'return': '1',
  12. 'title': '砍价记录'
  13. },
  14. bargainList:[],
  15. page:0,
  16. limit:20,
  17. status:false,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  33. this.bargainList();
  34. },
  35. cancelBargain: function (event){
  36. var item = event.currentTarget.dataset.item;
  37. var that = this;
  38. bargainUserCancel(item.bargain_id).then(res=>{
  39. app.Tips({ title: res.msg, icon: 'success' });
  40. clearInterval(that.data.timer);
  41. that.setData({
  42. timer: '',
  43. page: 0,
  44. status: false,
  45. bargainList: []
  46. });
  47. that.bargainList();
  48. })
  49. },
  50. toBargainList: function () {
  51. wx.navigateTo({
  52. url: '/pages/activity/goods_bargain/index',
  53. })
  54. },
  55. toBargain:function(event){
  56. wx.navigateTo({
  57. url: '/pages/activity/goods_bargain_details/index?id='+event.currentTarget.dataset.item.bargain_id+'&bargain='+event.currentTarget.dataset.item.uid,
  58. })
  59. },
  60. bargainList: function () {
  61. var that = this;
  62. var bargainList = that.data.bargainList;
  63. var timer = that.data.timer;
  64. var page = that.data.page;
  65. var limit = that.data.limit;
  66. var status = that.data.status;
  67. var bargainListNew = [];
  68. if (status == true) return ;
  69. getBargainUserList({ page: page, limit: limit }).then(res=>{
  70. var len = res.data.length;
  71. var bargainListData = res.data;
  72. bargainListNew = bargainList.concat(bargainListData);
  73. if (timer != 0) clearInterval(timer);
  74. that.setData({
  75. bargainList: bargainListNew,
  76. timer: 0,
  77. status: limit > len,
  78. page: Number(page) + Number(limit)
  79. });
  80. that.setTime();
  81. })
  82. },
  83. setTime:function(){
  84. var that = this;
  85. var bargainList = that.data.bargainList;
  86. var len = bargainList.length;//时间数据长度
  87. function nowTime() {//时间函数
  88. for (var i = 0; i < len; i++) {
  89. var intDiff = bargainList[i].datatime - Date.parse(new Date()) / 1000;
  90. //获取数据中的时间戳的时间差;
  91. var day = 0, hour = 0, minute = 0, second = 0;
  92. if (intDiff > 0) {//转换时间
  93. day = Math.floor(intDiff / (60 * 60 * 24));
  94. hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
  95. minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
  96. second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
  97. if (hour <= 9) hour = '0' + hour;
  98. if (minute <= 9) minute = '0' + minute;
  99. if (second <= 9) second = '0' + second;
  100. day = day;
  101. hour = hour;
  102. minute = minute;
  103. second = second;
  104. } else {
  105. day = "00";
  106. hour = "00";
  107. minute = "00";
  108. second = "00";
  109. }
  110. bargainList[i].day = day;//在数据中添加difftime参数名,把时间放进去
  111. bargainList[i].hour = hour;
  112. bargainList[i].minute = minute;
  113. bargainList[i].second = second;
  114. }
  115. that.setData({ bargainList: bargainList });
  116. }
  117. nowTime();
  118. var timer = setInterval(nowTime, 1000);
  119. that.setData({ timer: timer });
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. clearInterval(this.data.timer);
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. },
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage: function () {
  146. }
  147. })