mycut.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // pages/mycut/mycut.js
  2. var app = getApp();
  3. var wxh = require('../../utils/wxh.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. url: app.globalData.urlImages,
  10. product:[],
  11. timeer:'',
  12. countDownDay:"00",
  13. countDownHour:"00",
  14. countDownMinute:"00",
  15. countDownSecond:"00"
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. app.setBarColor();
  22. var that = this;
  23. var timeStamp = "1912245455"
  24. wxh.time2(timeStamp, that);
  25. },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow: function () {
  35. this.getUserBargainAll();
  36. },
  37. getUserBargainAll:function(){
  38. var that = this;
  39. wx.request({
  40. url: app.globalData.url + '/routine/auth_api/get_user_bargain_all?uid=' + app.globalData.uid,
  41. method: 'GET',
  42. success: function (res) {
  43. console.log(res);
  44. if (res.data.code == 200){
  45. that.setData({
  46. product:res.data.data
  47. })
  48. that.setTime();
  49. }else{
  50. wx.showToast({
  51. title: res.data.msg,
  52. icon: 'none',
  53. duration: 2000
  54. })
  55. }
  56. }
  57. })
  58. },
  59. timeFormat(param) {//小于10的格式化函数
  60. return param < 10 ? '0' + param : param;
  61. },
  62. setTime: function () {//到期时间戳
  63. var that = this;
  64. var newTime = new Date().getTime() / 1000;
  65. var endTimeList = that.data.product;
  66. var countDownArr = [];
  67. for (var i in endTimeList) {
  68. var endTime = endTimeList[i].stop_time;
  69. var obj = [];
  70. if (endTime - newTime > 0) {
  71. var time = endTime - newTime;
  72. var day = parseInt(time / (60 * 60 * 24));
  73. var hou = parseInt(time % (60 * 60 * 24) / 3600);
  74. var min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
  75. var sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
  76. // hou = parseInt(hou) + parseInt(day * 24);
  77. obj = {
  78. day: that.timeFormat(day),
  79. hou: that.timeFormat(hou),
  80. min: that.timeFormat(min),
  81. sec: that.timeFormat(sec)
  82. }
  83. endTimeList[i].time = obj;
  84. that.setData({
  85. product: endTimeList
  86. })
  87. } else {
  88. obj = {
  89. day: '00',
  90. hou: '00',
  91. min: '00',
  92. sec: '00'
  93. }
  94. endTimeList[i].time = obj;
  95. if (endTimeList[i].status == 1) {
  96. that.setBargainStatusError(endTimeList, endTimeList[i].id);
  97. }
  98. }
  99. }
  100. // console.log(that.data.product);
  101. var timeer = setTimeout(that.setTime, 1000);
  102. that.setData({
  103. timeer: timeer
  104. })
  105. },
  106. goCut:function(e){
  107. var bargainId = e.target.dataset.id;
  108. wx.navigateTo({
  109. url: '/pages/cut-one/cut-one?id=' + bargainId,
  110. })
  111. },
  112. goCutList:function(){
  113. wx.navigateTo({
  114. url: '/pages/cut-list/cut-list'
  115. })
  116. },
  117. setBargainStatusError: function (endTimeList,bargainUserTableId){
  118. var that = this;
  119. wx.request({
  120. url: app.globalData.url + '/routine/auth_api/set_user_bargain_status?uid=' + app.globalData.uid,
  121. method: 'GET',
  122. data:{
  123. bargainUserTableId: bargainUserTableId
  124. },
  125. success: function (res) {
  126. if (res.data.code == 200) {
  127. endTimeList.forEach(function (value, index, endTimeList){
  128. if (endTimeList[index].id == bargainUserTableId){
  129. endTimeList[index].status = 2
  130. }
  131. })
  132. that.setData({
  133. product: endTimeList
  134. })
  135. } else {
  136. }
  137. }
  138. })
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })