var app = getApp() Page({ /** * 页面的初始数据 */ data: { showCal: false, // start: '', // startTime: false, // end: '', // endTime: false, // dayStyle: [{ // month: 'current', // day: new Date().getDate(), // color: 'white', // background: '#AAD4F5' // }, // { // month: 'current', // day: new Date().getDate(), // color: 'white', // background: '#AAD4F5' // } // ], list: {} }, start: function() { var that = this; that.calendar = that.selectComponent("#calendar") var starTime = '' var day = '' var endTime = '' that.calendar.xianShi({ data: function(res) { console.log(res) //选择的日期 if (res != null) { if (res.length == 1) { starTime = res[0].data } else if (res.length == 2) { starTime = res[0].data endTime = res[1].data day = res[1].chaDay console.log(endTime) let data = { " pay_time_between[0]": starTime, " pay_time_between[1]": endTime, } app.request('order/profitDetail', data, 'GET').then(res => { console.log(res); if (res.statusCode == 200) { console.log(res) that.setData({ list: res.data }) } }) } } else { starTime = '' day = '' endTime = '' } that.setData({ starTime: starTime, endTime: endTime, day: day, }) } }) }, getState() { let day = new Date(); day.setTime(day.getTime()); let today = day.getFullYear() + "-" + (day.getMonth() + 1) + "-" + day.getDate(); var day1 = new Date(); day1.setTime(day1.getTime() + 24 * 60 * 60 * 1000); var tommorw = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate(); this.setData({ starTime: today, endTime: tommorw }) let data = { " pay_time_between[0]": this.data.starTime, " pay_time_between[1]": this.data.endTime, } app.request('order/profitDetail', data, 'GET').then(res => { if (res.statusCode == 200) { console.log(res) this.setData({ list: res.data }) } }) }, inquire() { let that = this; let begin = Date.parse(new Date(that.data.start)); let finish = Date.parse(new Date(that.data.end)); if (!that.data.start) { wx.showToast({ title: '开始日期不能为空', icon: 'none' }) } else if (!that.data.end) { wx.showToast({ title: '结束日期不能为空', icon: 'none' }) } else if (begin > finish) { wx.showToast({ title: '结束日期不能大于开始日期', icon: 'none' }) } else { let data = { " pay_time_between[0]": that.data.starTime, " pay_time_between[1]": that.data.endTime, } app.request('order/profitDetail', data, 'GET').then(res => { if (res.statusCode == 200) { console.log(res) this.setData({ list: res.data }) } }) } }, //给点击的日期设置一个背景颜色 dayClick: function(e) { let that = this; console.log(that.data.startTime) if (that.data.startTime == true) { that.setData({ start: e.detail.year + "-" + e.detail.month + "-" + e.detail.day, showCal: false }) } if (that.data.endTime == true) { that.setData({ end: e.detail.year + "-" + e.detail.month + "-" + e.detail.day, showCal: false }) } let clickDay = e.detail.day; let changeDay = `dayStyle[1].day`; let changeBg = `dayStyle[1].background`; this.setData({ [changeDay]: clickDay, [changeBg]: "#84e7d0" }) }, onLoad: function() { this.getState(); } })