123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- // pages/ucenter/charginglog/charginglog.js
- let Util = require("../../../utils/util");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- charginglogs: []
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let that = this;
- // 页面显示
- if (userInfo && isLogin) {
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/wechatuserallcharglog',
- data: {
- userId: userInfo.userId
- },
- method: 'POST',
- success(res) {
- console.log(res);
- if (res.data.result) {
- let {
- result: charginglogs
- } = res.data;
- that.startTimeOrder(charginglogs);
- that.formatCharginglogs(charginglogs);
- that.setData({
- charginglogs
- });
- }
- }
- });
- }
- },
- formatCharginglogs(charginglogs) {
- charginglogs.forEach((item, index) => {
- try {
- var startDate = new Date(item.chargstarttime);
- var endDate = new Date(item.chargendtime);
- var totalTime = Math.round((endDate.getTime() - startDate.getTime()) / 60000);
- var totalTimeHour = Math.floor(totalTime / 60);
- var totalTimeMinute = totalTime % 60;
- 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());
- 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());
- totalTime = Util.formatNumber(totalTimeHour) + "时" + Util.formatNumber(totalTimeMinute) + "分";
- item.startTime = startTime;
- item.endTime = endTime;
- item.totalTime = totalTime;
- item.chargallmoney = item.chargallmoney.toFixed(2);
- item.chargservice = item.chargservice.toFixed(2);
- item.chargmoney = item.chargmoney.toFixed(2);
- //console.log(item.chargPile);
- } catch (err) {
- //在这里处理错误
- }
- });
- },
- startTimeOrder(charginglogs) {
- if (charginglogs && 0 != charginglogs.length) {
- charginglogs.sort(function(ma, mb) {
- return mb.chargstarttime.localeCompare(ma.chargstarttime);
- });
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|