123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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/open-market/share.html?shareGoodsCode=D34E5A30A9AC7FC6327AB5E6D2D145418457E59F16C3FC969F1A50AEF2E5E320588012470F1AB045&token=d37751d45abad15178adf60f936d7c28&shareUid=C5EB7B5C85793F3D909B2AC4771E12D7'
- })
- } 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();
- }
- }
- });
|