charginglog.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // pages/ucenter/charginglog/charginglog.js
  2. let Util = require("../../../utils/util");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. charginglogs: []
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function(options) {
  14. let userInfo = wx.getStorageSync('userInfo');
  15. let isLogin = wx.getStorageSync('isLogin');
  16. let that = this;
  17. // 页面显示
  18. if (userInfo && isLogin) {
  19. wx.request({
  20. url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/wechatuserallcharglog',
  21. data: {
  22. userId: userInfo.userId
  23. },
  24. method: 'POST',
  25. success(res) {
  26. console.log(res);
  27. if (res.data.result) {
  28. let {
  29. result: charginglogs
  30. } = res.data;
  31. that.startTimeOrder(charginglogs);
  32. that.formatCharginglogs(charginglogs);
  33. that.setData({
  34. charginglogs
  35. });
  36. }
  37. }
  38. });
  39. }
  40. },
  41. formatCharginglogs(charginglogs) {
  42. charginglogs.forEach((item, index) => {
  43. try {
  44. var startDate = new Date(item.chargstarttime);
  45. var endDate = new Date(item.chargendtime);
  46. var totalTime = Math.round((endDate.getTime() - startDate.getTime()) / 60000);
  47. var totalTimeHour = Math.floor(totalTime / 60);
  48. var totalTimeMinute = totalTime % 60;
  49. 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());
  50. 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());
  51. totalTime = Util.formatNumber(totalTimeHour) + "时" + Util.formatNumber(totalTimeMinute) + "分";
  52. item.startTime = startTime;
  53. item.endTime = endTime;
  54. item.totalTime = totalTime;
  55. item.chargallmoney = item.chargallmoney.toFixed(2);
  56. item.chargservice = item.chargservice.toFixed(2);
  57. item.chargmoney = item.chargmoney.toFixed(2);
  58. //console.log(item.chargPile);
  59. } catch (err) {
  60. //在这里处理错误
  61. }
  62. });
  63. },
  64. startTimeOrder(charginglogs) {
  65. if (charginglogs && 0 != charginglogs.length) {
  66. charginglogs.sort(function(ma, mb) {
  67. return mb.chargstarttime.localeCompare(ma.chargstarttime);
  68. });
  69. }
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function() {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function() {
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function() {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function() {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function() {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function() {
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function() {
  105. }
  106. })