charginglog.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // pages/ucenter/charginglog/charginglog.js
  2. let Util = require("../../../utils/util");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. charginglogs: [],
  9. pagesize:10,
  10. pagenum:1,
  11. total:-1,
  12. loadTotal: 0,
  13. dataLoading: false,
  14. finishedLoadTap: 0,
  15. finishedLoadShowTimes: 0,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function(options) {
  21. let userInfo = wx.getStorageSync('userInfo');
  22. let isLogin = wx.getStorageSync('isLogin');
  23. let that = this;
  24. // 页面显示
  25. if (userInfo && isLogin) {
  26. this.getPage();
  27. }
  28. },
  29. getPage(){
  30. console.info(this.data.charginglogs.length + " MMM " + this.data.total)
  31. if(this.data.charginglogs.length == this.data.total){
  32. this.setData({
  33. finishedLoadTap:this.data.finishedLoadTap+1
  34. })
  35. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  36. this.setData({
  37. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  38. })
  39. wx.showToast({
  40. title: '全部加载完毕',
  41. icon: 'success',
  42. duration: 2000
  43. })
  44. }
  45. return
  46. }
  47. if(this.data.dataLoading){
  48. return
  49. }
  50. this.setData({
  51. dataLoading: true
  52. })
  53. wx.showLoading({
  54. title: '数据加载中....',
  55. })
  56. let that = this;
  57. wx.request({
  58. url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/wechatuserallcharglog',
  59. data: {
  60. userId: wx.getStorageSync('userInfo').userId,
  61. pagenum: this.data.pagenum++,
  62. pagesize: 10,
  63. },
  64. method: 'POST',
  65. success(res) {
  66. console.log(res);
  67. if (res.data.result.rows) {
  68. let {
  69. rows: charginglogs
  70. } = res.data.result;
  71. // that.startTimeOrder(charginglogs);
  72. that.formatCharginglogs(charginglogs);
  73. wx.hideLoading()
  74. that.setData({
  75. charginglogs: that.data.charginglogs.concat(charginglogs),
  76. total: res.data.result.total,
  77. dataLoading: false
  78. });
  79. }
  80. }
  81. });
  82. },
  83. formatCharginglogs(charginglogs) {
  84. charginglogs.forEach((item, index) => {
  85. try {
  86. var startDate = Util.parseDate(item.chargstarttime);
  87. var endDate = Util.parseDate(item.chargendtime)
  88. var totalTime = Math.round((endDate.getTime() - startDate.getTime()) / 60000);
  89. var totalTimeHour = Math.floor(totalTime / 60);
  90. var totalTimeMinute = totalTime % 60;
  91. var startTime = startDate.getFullYear() + "年" + Util.formatNumber(startDate.getMonth() + 1) + '月' + Util.formatNumber(startDate.getDate()) + '日 ' + Util.formatNumber(startDate.getHours()) + ':' + Util.formatNumber(startDate.getMinutes()) + ':' + Util.formatNumber(startDate.getSeconds());
  92. var endTime = endDate.getFullYear() + "年" + Util.formatNumber(endDate.getMonth() + 1) + '月' + Util.formatNumber(endDate.getDate()) + '日 ' + Util.formatNumber(endDate.getHours()) + ':' + Util.formatNumber(endDate.getMinutes()) + ':' + Util.formatNumber(endDate.getSeconds());
  93. totalTime = Util.formatNumber(totalTimeHour) + "时" + Util.formatNumber(totalTimeMinute) + "分";
  94. item.startTime = startTime;
  95. item.endTime = endTime;
  96. item.totalTime = totalTime;
  97. item.chargallmoney = item.chargallmoney.toFixed(2);
  98. item.chargservice = item.chargservice.toFixed(2);
  99. item.chargmoney = item.chargmoney.toFixed(2);
  100. //console.log(item.chargPile);
  101. } catch (err) {
  102. //在这里处理错误
  103. }
  104. });
  105. },
  106. startTimeOrder(charginglogs) {
  107. if (charginglogs && 0 != charginglogs.length) {
  108. charginglogs.sort(function(ma, mb) {
  109. return mb.chargstarttime.localeCompare(ma.chargstarttime);
  110. });
  111. }
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function() {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function() {
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function() {
  142. },
  143. bindScrollTolowerEvent: function(){
  144. this.getPage();
  145. },
  146. /**
  147. * 用户点击右上角分享
  148. */
  149. onShareAppMessage: function() {
  150. }
  151. })