123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- // pages/ucenter/charginglog/charginglog.js
- let Util = require("../../../utils/util");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- charginglogs: [],
- pagesize:10,
- pagenum:1,
- total:-1,
- loadTotal: 0,
- dataLoading: false,
- finishedLoadTap: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let that = this;
- // 页面显示
- if (userInfo && isLogin) {
- this.getPage();
- }
- },
- getPage(){
- console.info(this.data.charginglogs.length + " MMM " + this.data.total)
-
- if(this.data.charginglogs.length == this.data.total){
- this.setData({
- finishedLoadTap:this.data.finishedLoadTap+1
- })
- if(this.data.finishedLoadTap>0){
- wx.showToast({
- title: '全部加载完毕',
- icon: 'success',
- duration: 2000
- })
- }
- return
- }
- if(this.data.dataLoading){
- return
- }
- this.setData({
- dataLoading: true
- })
- wx.showLoading({
- title: '数据加载中....',
- })
- let that = this;
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/wechatuserallcharglog',
- data: {
- userId: wx.getStorageSync('userInfo').userId,
- pagenum: this.data.pagenum++,
- pagesize: 10,
- },
- method: 'POST',
- success(res) {
- console.log(res);
- if (res.data.result.rows) {
- let {
- rows: charginglogs
- } = res.data.result;
- // that.startTimeOrder(charginglogs);
- that.formatCharginglogs(charginglogs);
- wx.hideLoading()
- that.setData({
- charginglogs: that.data.charginglogs.concat(charginglogs),
- total: res.data.result.total,
- dataLoading: false
- });
- }
- }
- });
- },
- formatCharginglogs(charginglogs) {
- charginglogs.forEach((item, index) => {
- try {
- var startDate = Util.parseDate(item.chargstarttime);
- var endDate = Util.parseDate(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() {
- },
- bindScrollTolowerEvent: function(){
- this.getPage();
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|