charginglog.js 4.3 KB

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