'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination', ]); app.controller("indexCtrl", ["$scope", "$http", "$interval", "$timeout", function ($scope, $http, $interval, $timeout) { var self = this; self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-username"); self.userChineseName = $.cookie("GlWorkPlatform-chineseName") self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; /*日历开始*/ self.all_year = []; self.all_month = []; self.select_year = '' self.select_month = '' self.active_day = '' self.week = '' self.DateWork = []; self.getDateWork = function (year, month, day) { self.DateWork1 = { own: [], leader: [], przb: [], huiyi: [] }; var data = { STRATDATE: year + "-" + formate(month) + "-" + day, ENDDATE: sp.getNextDate(year + "-" + formate(month) + "-" + day,1), USERID: $.cookie("GlWorkPlatform-username"),//self.userId ZBUSERID: self.userId } $http.post(apiurljs.login + "g2app/deskcalendar/deskQueryDayData", data, postCfg) .success(function (obj) { //var res = strToJson(s4.decryptData_CBC(obj.data)); var res = obj; self.DateWork = res.data.Items[0] ? res.data.Items[0].task : []; $.each(self.DateWork, function (index, item) { item.STARTIME = formateTime(item.STARTIME); item.ENDTIME = formateTime(item.ENDTIME); item.OWNTYPE1 = item.OWNTYPE + "工作日程"; if (item.OWNTYPE == "个人") { self.DateWork1.own.push(item) } else if (item.OWNTYPE == "领导") { self.DateWork1.leader.push(item) } }) $.each(res.data.PRZBItems, function (index, item) { //item.STARTIME = formateTime(item.STARTIME); //item.ENDTIME = formateTime(item.ENDTIME); item.STARTIME = item.ZBSJNAME.split("-")[0]; item.ENDTIME = item.ZBSJNAME.split("-")[1]; item.OWNTYPE1 = "值班提醒" item.MEETINGNAME = item.TITLE; self.DateWork1.przb.push(item) }) $.each(res.data.HuiYiItems, function (index, item) { item.STARTIME = formateTime(item.STARTIME); item.ENDTIME = formateTime(item.ENDTIME); item.OWNTYPE1 = "会议提醒"; item.MEETINGNAME = item.TITLE; self.DateWork1.huiyi.push(item) }) if (self.DateWork1.leader.length != 0) { self.selectList = "leader"; } else if (self.DateWork1.own.length != 0) { self.selectList = "own"; } else if (self.DateWork1.przb.length != 0) { self.selectList = "przb"; } else { self.selectList = "huiyi"; } }) } self.showDateWork = function (str) { self.selectList = str; self.DatePageNo = 0; self.DateWidth = 0; $(".Date-page").parent().css("margin-left", 0); } self.getDayInfo = function () { var data = { DATE: self.select_year + "-" + formate(self.select_month) + "-" + "01", USERID: self.userName } $http.post(apiurljs.login + "g2app/calendar/queryMonthData", data, postCfg) .success(function (obj) { // var res = strToJson(s4.decryptData_CBC(obj.data)); var res = obj; if (res) { self.days.forEach(function (item1) { item1.forEach(function (item2) { if (res.data["day_" + item2.day]) { item2.meets = res.data["day_" + item2.day] } }) }) } }); } self.DatePageNo = 0;//向左平移n个工作事件 self.DateWidth = 0;//向左平移距离 self.DateLeft = function () { if (self.DatePageNo > 0) { self.DateWidth = self.DateWidth + $(".Date-page").eq(self.DatePageNo - 1).outerWidth(true); $(".Date-page").parent().css("margin-left", (self.DateWidth > 0 ? 0 : self.DateWidth)); self.DatePageNo = self.DatePageNo - 1; } else { return; } } self.DateRight = function () { if (self.DatePageNo < $(".Date-page").length - 1) { self.DateWidth = self.DateWidth - $(".Date-page").eq(self.DatePageNo).outerWidth(true); $(".Date-page").parent().css("margin-left", self.DateWidth); self.DatePageNo = self.DatePageNo + 1; } } //初始化显示 当前年和月 self.show_now = function () { var now = new Date(); self.select_year = now.getFullYear(); self.select_month = now.getMonth() + 1; self.active_day = formate(now.getDate()); self.cyear = now.getFullYear(); self.cmonth = now.getMonth() + 1; self.cday = formate(now.getDate()); self.showTime() } self.showTime = function () { //在select中填入年份 for (var year = self.select_year - 5; year < self.select_year + 5; year++) { var obj_1 = { 'value': year, 'id': year } self.all_year.push(obj_1); } //在select中填入月份 for (var month = 1; month < 13; month++) { var obj_2 = { 'value': month, 'id': month } self.all_month.push(obj_2); } //初始化显示 当前年和月 self.showDays(self.select_year, self.select_month) } //当select的选中的option发送变化的触发的事件 self.change_year = function () { self.showDays(self.select_year, self.select_month) } self.change_month = function () { self.showDays(self.select_year, self.select_month) } //返回指定的月份的天数 月份1-12 self.calDays = function (year, month) { return new Date(year, month, 0).getDate(); } //展示指定的年和月的所有日期 self.showDays = function (year, month) { self.days = []; var days = []; self.dateWork = []; self.date_day = self.active_day; self.getWeek(self.select_year, self.select_month, self.active_day) //得到表示指定年和月的1日的那个时间对象 var date = new Date(year, month - 1, 1); //1.先添加响应的空白的li:这个月1号是星期几,就添加几个空白的li var dayOfWeek = date.getDay(); //得到1日是星期几 for (var i = 0; i < dayOfWeek; i++) { days.push({ day: "", id: i + 8 }); } //计算一个月有多少天 var daysOfMonth = self.calDays(year, month); //2. 从1号开始添加li for (var i = 1; i <= daysOfMonth; i++) { days.push({ day: formate(i), id: i + dayOfWeek + 7 }); } var length = days.length; for (var i = 42; i > length; i--) { days.push({ day: "", id: daysOfMonth - i + 50 }); } $.each(days, function (index1, item1) { $.each(self.DateWork, function (index2, item2) { if (self.select_year + "-" + formate(self.select_month) + "-" + formate(item1.day) == item2.date) { item1.data = item2.data; if (item1.day == self.active_day) { self.dateWork = item1.data; } } }) }) for (var i = 0; i < 6 ; i++) { self.days[i] = []; $.each(days, function (index, item) { if (Math.ceil((index + 1) / 7) == i + 1) { self.days[i].push(item) } }) } if (JSON.stringify(days).indexOf('"day":' + JSON.stringify(self.active_day)) == -1) { for (var i = days.length - 1; i >= 0; i--) { if (days[i].day != "") { self.active_day = days[i].day; break; } } } self.getDayInfo() self.getDateWork(self.select_year, self.select_month, self.active_day) } self.returnToday = function () { self.select_year = self.cyear; self.select_month = self.cmonth; self.active_day = self.cday; self.showDays(self.select_year, self.select_month) } self.change_day = function (day) { if (day.day == "") { return; } var date = new Date(self.select_year, self.select_month - 1, 1); var dayOfWeek = date.getDay(); self.active_day = day.day; self.date_day = self.active_day; self.getWeek(self.select_year, self.select_month, self.active_day); self.getDateWork(self.select_year, self.select_month, self.active_day) } self.getWeek = function (year, month, day) { switch (new Date(year, month - 1, day).getDay()) { case 0: self.week = "星期日"; break; case 1: self.week = "星期一"; break; case 2: self.week = "星期二"; break; case 3: self.week = "星期三"; break; case 4: self.week = "星期四"; break; case 5: self.week = "星期五"; break; case 6: self.week = "星期六"; break; } } /*日历结束*/ self.getZBNum = function () { self.hyNum = 0; self.zbNum = 0; var data = { CNAME: self.userId, //CNAME: self.userChineseName, SDATE: sp.dateCount(0) + " 08:00:00", EDATE: sp.dateCount(0) + " 18:00:00", NF: sp.currentYear(), YF: sp.currentMonth(), RIQI: formate(new Date().getDate()) } $http.post(apiurljs.login + "g2app/deskcalendar/deskQueryHYandZBCountData", data, postCfg) .success(function (obj) { //var res = strToJson(s4.decryptData_CBC(obj.data)); var res = obj; self.hyNum = res.data.HYCOUNT; self.zbNum = res.data.ZBCOUNT; }) } self.getZBNum() self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType"); self.openTab = function (n) { if (self.deviceType == "pad") { if (n == 1) { window.top.jumpPageParent("FZF09", "工作日程", "tpl/workschedule/index.html") } else if (n == 2) { window.top.jumpPageParent("FZJ06", "会议申请", "tpl/huiyishimgr/list.html") } else if (n == 3) { window.top.jumpPageParent("FZJ08-1", "值班表", "tpl/zhibanmgr/zhiban.html") } else if (n == 4) { window.top.sp.addTabNav("FZJ08-2", "值班工作日志", "tpl/zhibanmgr/workList.html") } } else { if (n == 1) { window.top.sp.addTabNav("FZF09", "工作日程", "tpl/workschedule/index.html") } else if (n == 2) { window.top.sp.addTabNav("FZJ06", "会议申请", "tpl/huiyishimgr/list.html") } else if (n == 3) { window.top.sp.addTabNav("FZJ08-1", "值班表", "tpl/zhibanmgr/zhiban.html") } else if (n == 4) { window.top.sp.addTabNav("FZJ08-2", "值班工作日志", "tpl/zhibanmgr/workList.html") } } event.stopPropagation(); } }]) function formate(num) { return num > 9 ? num : "0" + num; } function formateTime(str) { if (str == "1900-01-01T00:00:00") { str = ""; return str; } else if (str == "0001-01-01T00:00:00") { ///这种情况是在做滨旅建管系统时用sqlserver数据库时遇到的 str = ""; return str; } else if (str != undefined && str != "" && str != null) { /////如果找到"-",不等于负1 if (str.toString().indexOf('-') != -1) { str = str.replace(/-/g, "/"); //将-替换为/,因为ios与ie浏览器中不支持-和T } /////如果找到T,不等于负1 if (str.toString().indexOf('T') != -1) { str = str.replace(/T/g, ' '); ///去掉日期中的T,因为ios与ie浏览器中不支持-和T } /////如果找到".",不等于负1 if (str.toString().indexOf('.') != -1) { str = str.slice(0, str.indexOf(".")); ///如果含有毫秒,就将毫秒去掉 } var formatDate = new Date(Date.parse(str)); var MM = formatDate.getMonth() + 1; if (MM < 10) { MM = '0' + MM; } //去掉前面加0,是为了便于后续的格式化得到年月 var dd = formatDate.getDate(); if (dd < 10) { dd = '0' + dd; } //去掉前面加0,是为了便于后续的格式化得到年月 var hh = formatDate.getHours(); if (hh < 10) { hh = '0' + hh; } var mm = formatDate.getMinutes(); if (mm < 10) { mm = '0' + mm; } var setDate = hh + ":" + mm; return setDate; } else { str = ""; return str; } }