189 lines
3.5 KiB
JavaScript
189 lines
3.5 KiB
JavaScript
// pages/state/state.js
|
|
const app = getApp();
|
|
const { count } = require('../../utils/qrPay.js');
|
|
const { timeStr } = require('../../utils/util.js');
|
|
|
|
const origData = {
|
|
allCount: '-',
|
|
allMoney: '-',
|
|
cardCount: '-',
|
|
cardMoney: '-',
|
|
userCount: '-',
|
|
walletCount: '-',
|
|
walletMoney: '-',
|
|
wxCount: '-',
|
|
wxMoney: '-'
|
|
}
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.height,
|
|
select: '0',
|
|
startTime: '-',
|
|
endTime: '-',
|
|
countData: origData,
|
|
end: ''
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.defaultTime()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
defaultTime () {
|
|
const date = new Date()
|
|
let time
|
|
if (this.data.select === '0') {
|
|
time = timeStr(date, 'YYYY-MM-DD')
|
|
} else if (this.data.select === '1') {
|
|
time = timeStr(date, 'YYYY-MM')
|
|
} else {
|
|
return
|
|
}
|
|
this.setData({
|
|
startTime: time,
|
|
endTime: time
|
|
})
|
|
if (this.data.end === '') {
|
|
this.setData({
|
|
end: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
|
})
|
|
}
|
|
this.handleRequst()
|
|
},
|
|
|
|
changeStartTime (e) {
|
|
this.setData({
|
|
startTime: e.detail.value
|
|
})
|
|
this.handleRequst()
|
|
},
|
|
|
|
changeEndTime (e) {
|
|
this.setData({
|
|
endTime: e.detail.value
|
|
})
|
|
this.handleRequst()
|
|
},
|
|
|
|
handleRequst () {
|
|
if (this.data.startTime === '-' || this.data.endTime === '-') return;
|
|
if (this.data.startTime > this.data.endTime) {
|
|
this.setData({
|
|
startTime: this.data.endTime,
|
|
endTime: this.data.startTime,
|
|
})
|
|
}
|
|
wx.showLoading()
|
|
let data;
|
|
if (this.data.select === '0') {
|
|
// 日报
|
|
data = {
|
|
type: '1',
|
|
startDay: this.data.startTime,
|
|
endDay: this.data.endTime,
|
|
}
|
|
} else if (this.data.select === '1' ) {
|
|
// 月报
|
|
data = {
|
|
type: '2',
|
|
startMonth: this.data.startTime,
|
|
endMonth: this.data.endTime,
|
|
}
|
|
} else {
|
|
// 历史综合
|
|
data = { type: '0' }
|
|
}
|
|
// console.log(data)
|
|
this.getCountData(data)
|
|
},
|
|
|
|
getCountData (data) {
|
|
count(data)
|
|
.then(e => {
|
|
wx.hideLoading()
|
|
console.log(e);
|
|
this.setData({
|
|
countData: e.data.data
|
|
})
|
|
})
|
|
.catch(e => {
|
|
wx.hideLoading()
|
|
console.error(e)
|
|
wx.showModal({
|
|
title: '错误',
|
|
showCancel: false,
|
|
content: e.msg ? e.msg : '您的系统存在未知异常,请联系客服处理',
|
|
})
|
|
})
|
|
},
|
|
|
|
switchSelect (e) {
|
|
if (e.target.dataset.i && e.target.dataset.i !== this.data.select) {
|
|
this.setData({
|
|
select: e.target.dataset.i,
|
|
countData: origData
|
|
})
|
|
this.defaultTime()
|
|
if (e.target.dataset.i === '2') {
|
|
// this.getCountData({ type: 0 })
|
|
this.handleRequst()
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.defaultTime()
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |