var app = getApp(); var that; import 'dingtalk-jsapi/entry/mobile'; import openLink from 'dingtalk-jsapi/api/biz/util/openLink'; Page({ data: { showIndex: 1, thisweek: { end_day: '', start_day: '' }, employee_id: '', isUrl: true, start: '',//查看周开始时间 allDate: '', }, onLoad(e) { that = this; dd.setNavigationBar({ title: "积分周报" }); if (e.employee_id) { this.setData({ employee_id: e.employee_id }) } if (e.start) { this.setData({ start: e.start, }) } if (e.isUrl) { this.setData({ isUrl: false, }) } this.setData({ allDate: app.globalData.allDate, }) this.setDate(); dd.showLoading({ content: '加载中...', }); setTimeout(() => { dd.hideLoading(); }, 1000) }, onShareAppMessage() { let userId = this.data.employee_id ? this.data.employee_id : app.globalData.userData.id return { title: '积分周报', desc: that.data.result.employee.name + '的积分周报分享', path: 'pages/reportBox/report/report?employee_id=' + userId + '&isUrl=123&start' + that.data.result.date.start }; }, onShow() { this.opneWebSocket() }, //跳转 openView(e) { let index = e.target.dataset.index if (!this.data.isUrl && index != 6) { return false } if (index == 1) { dd.navigateTo({ url: '../../statistics/my_task/my_task' }) } else if (index == 2) { dd.navigateTo({ url: '../../statistics/my_issue/my_issue' }) } else if (index == 3) { dd.navigateTo({ url: '../../workbench/prize_buckle/prize_buckle' }) } else if (index == 4) { let data = { type: 'week_statistics', employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id, start_date: this.data.start ? this.data.start : this.data.thisweek.start_day, method: 'ruleList', page_size: 1000, rule_item_id: e.target.dataset.item.rule_item_id } dd.navigateTo({ url: '../moreE/moreE?data=' + JSON.stringify(data) }) } else if (index == 5) { dd.navigateTo({ url: '../noUser/noUser?list=' + JSON.stringify(this.data.result.rank.free_man) }) } else if (index == 6) { openLink({ url: 'https://h5.dingtalk.com/appcenter/detail.html?showmenu=false&dd_share=false&goodsCode=DT_GOODS_881607043109331&funnelsource=guangchangzhibodaihuo' }) } else if (index == 7) { let data = { type: 'week_statistics', employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id, start_date: this.data.start ? this.data.start : this.data.thisweek.start_day, method: 'myTaskList', page_size: 1000, range: 'all' } dd.navigateTo({ url: '../newspaperTask/newspaperTask?data=' + JSON.stringify(data) }) } else if (index == 8) { let data = { type: 'week_statistics', employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id, start_date: this.data.start ? this.data.start : this.data.thisweek.start_day, method: 'taskList', page_size: 1000, range: 'all' } dd.navigateTo({ url: '../newspaperTask/newspaperTask?data=' + JSON.stringify(data) }) } }, getTime(n) { var now = new Date(); var year = now.getFullYear(); //因为月份是从0开始的,所以获取这个月的月份数要加1才行 var month = now.getMonth() + 1; var date = now.getDate(); var day = now.getDay(); console.log(date); //判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1) if (day !== 0) { n = n + (day - 1); } else { n = n + day; } if (day) { //这个判断是为了解决跨年的问题 if (month > 1) { month = month; } //这个判断是为了解决跨年的问题,月份是从0开始的 else { year = year - 1; month = 12; } } now.setDate(now.getDate() - n); year = now.getFullYear(); month = now.getMonth() + 1; date = now.getDate(); // console.log(n); var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date); return s; }, setDate() { this.setData({ thisweek: { start_day:this.getTime(7), end_day:this.getTime(7) } }) return false var thisweek = {}; var date = new Date(); // 本周一的日期 date.setDate(date.getDate() - date.getDay() + 1); let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1) let getDate = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate() thisweek.start_day = date.getFullYear() + "-" + month + "-" + getDate; // 本周日的日期 date.setDate(date.getDate() + 6); let month2 = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1) let getDate2 = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate() thisweek.end_day = date.getFullYear() + "-" + month2 + "-" + getDate2; this.setData({ thisweek: thisweek }) }, // 页面被关闭 onUnload() { app.globalData.socketApi.closewebsocket(); }, opneWebSocket() { let data = { type: 'week_statistics', employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id, start_date: this.data.start ? this.data.start : this.data.thisweek.start_day } app.globalData.socketApi.sendData(data, this.onmessageWS); }, onmessageWS(e) { // 因为作用域问题,这个函数不能使用this if (e.type == 'week_statistics' && e.msg == 'all') { let result = e.result that.setData({ result: result }) // app.globalData.socketApi.closewebsocket(); } } });