// pages/clock/clock-tongji/index.js import { monthTotalSettlement, currentSettlement, daySettlement } from '../../../services/index.js' import { imgServerUrl } from '../../../config/config.js' Page({ /** * 页面的初始数据 */ data: { wsPunchClockList: [], currentSettlement: {}, imgServerUrl, next: `${imgServerUrl}/images/clock/clock-arrow-righr-disabled.png`, last: `${imgServerUrl}/images/clock/clock-arrow-left.png`, text: '', currentDuration: 0, punckClockList: [], nextMoney: 0 }, toList() { wx.navigateTo({ url: './list', }) }, getList(month_type) { monthTotalSettlement({ month_type }).then(data => { this.setData({ wsPunchClockList: data.data.wsPunchClockList }) }) }, getCurrent() { currentSettlement().then(data => { const month = Number(data.data.currentSettlement.date.split('-')[1]) this.setData({ currentSettlement: data.data.currentSettlement, text: month, mouth: month, }) }) }, next() { if (this.data.text !== this.data.mouth) { this.selectComponent('.calendar').next() this.getList(1) this.setData({ text: this.data.mouth, next: `${imgServerUrl}/images/clock/clock-arrow-righr-disabled.png`, last: `${imgServerUrl}/images/clock/clock-arrow-left.png`, }, _ => { let { year, text } = this.data const search_date = [year, text, 1].map(val => { const number = val.toString() return number[1] ? number : '0' + number }).join('-') this.getDay(search_date) }) } }, last() { if (this.data.text === this.data.mouth) { this.selectComponent('.calendar').last() this.getList(2) if (this.data.mouth - 1 <= 0) { this.setData({ text: 12 }, _ => { let { year, text } = this.data const search_date = [year - 1, text, 1].map(val => { const number = val.toString() return number[1] ? number : '0' + number }).join('-') this.getDay(search_date) }) } else { this.setData({ text: this.data.mouth - 1 }, _ => { let { year, text } = this.data const search_date = [year, text, 1].map(val => { const number = val.toString() return number[1] ? number : '0' + number }).join('-') this.getDay(search_date) }) } this.setData({ next: `${imgServerUrl}/images/clock/clock-arrow-righr.png`, last: `${imgServerUrl}/images/clock/clock-arrow-left-disabled.png`, }) } }, getDay(search_date) { daySettlement({ search_date }).then(data => { this.setData({ punckClockList: data.data.punckClockList, nextMoney: data.data.nextMoney, currentDuration: data.data.currentDuration, }) }) }, day(e) { let { year, month, date } = e.detail const search_date = [year, month, date].map(val => { const number = val.toString() return number[1] ? number : '0' + number }).join('-') this.getDay(search_date) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const date = new Date() let year = date.getFullYear() let month = date.getMonth() + 1 let day = date.getDate() const search_date = [year, month, day].map(val => { const number = val.toString() return number[1] ? number : '0' + number }).join('-') this.getList(1) this.getCurrent() this.getDay(search_date) this.setData({ year }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })