gzrc.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination',
  4. ]);
  5. app.controller("indexCtrl", ["$scope", "$http", "$interval", "$timeout", function ($scope, $http, $interval, $timeout) {
  6. var self = this;
  7. self.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-username");
  9. self.userChineseName = $.cookie("GlWorkPlatform-chineseName")
  10. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  11. var postCfg = {
  12. headers: {
  13. 'Content-Type': 'application/json',
  14. 'Authorization': "Bearer " + self.get_AccessToken
  15. }
  16. };
  17. /*日历开始*/
  18. self.all_year = [];
  19. self.all_month = [];
  20. self.select_year = ''
  21. self.select_month = ''
  22. self.active_day = ''
  23. self.week = ''
  24. self.DateWork = [];
  25. self.getDateWork = function (year, month, day) {
  26. self.DateWork1 = { own: [], leader: [], przb: [], huiyi: [] };
  27. var data = {
  28. STRATDATE: year + "-" + formate(month) + "-" + day,
  29. ENDDATE: sp.getNextDate(year + "-" + formate(month) + "-" + day,1),
  30. USERID: $.cookie("GlWorkPlatform-username"),//self.userId
  31. ZBUSERID: self.userId
  32. }
  33. $http.post(apiurljs.login + "g2app/deskcalendar/deskQueryDayData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  34. .success(function (obj) {
  35. var res = strToJson(s4.decryptData_CBC(obj.data));
  36. self.DateWork = res.data.Items[0] ? res.data.Items[0].task : [];
  37. $.each(self.DateWork, function (index, item) {
  38. item.STARTIME = formateTime(item.STARTIME);
  39. item.ENDTIME = formateTime(item.ENDTIME);
  40. item.OWNTYPE1 = item.OWNTYPE + "工作日程";
  41. if (item.OWNTYPE == "个人") {
  42. self.DateWork1.own.push(item)
  43. } else if (item.OWNTYPE == "领导") {
  44. self.DateWork1.leader.push(item)
  45. }
  46. })
  47. $.each(res.data.PRZBItems, function (index, item) {
  48. //item.STARTIME = formateTime(item.STARTIME);
  49. //item.ENDTIME = formateTime(item.ENDTIME);
  50. item.STARTIME = item.ZBSJNAME.split("-")[0];
  51. item.ENDTIME = item.ZBSJNAME.split("-")[1];
  52. item.OWNTYPE1 = "值班提醒"
  53. item.MEETINGNAME = item.TITLE;
  54. self.DateWork1.przb.push(item)
  55. })
  56. $.each(res.data.HuiYiItems, function (index, item) {
  57. item.STARTIME = formateTime(item.STARTIME);
  58. item.ENDTIME = formateTime(item.ENDTIME);
  59. item.OWNTYPE1 = "会议提醒";
  60. item.MEETINGNAME = item.TITLE;
  61. self.DateWork1.huiyi.push(item)
  62. })
  63. if (self.DateWork1.leader.length != 0) {
  64. self.selectList = "leader";
  65. } else if (self.DateWork1.own.length != 0) {
  66. self.selectList = "own";
  67. } else if (self.DateWork1.przb.length != 0) {
  68. self.selectList = "przb";
  69. } else {
  70. self.selectList = "huiyi";
  71. }
  72. })
  73. }
  74. self.showDateWork = function (str) {
  75. self.selectList = str;
  76. self.DatePageNo = 0;
  77. self.DateWidth = 0;
  78. $(".Date-page").parent().css("margin-left", 0);
  79. }
  80. self.getDayInfo = function () {
  81. var data = {
  82. DATE: self.select_year + "-" + formate(self.select_month) + "-" + "01",
  83. USERID: self.userName
  84. }
  85. $http.post(apiurljs.login + "g2app/calendar/queryMonthData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  86. .success(function (obj) {
  87. var res = strToJson(s4.decryptData_CBC(obj.data));
  88. if (res) {
  89. self.days.forEach(function (item1) {
  90. item1.forEach(function (item2) {
  91. if (res.data["day_" + item2.day]) {
  92. item2.meets = res.data["day_" + item2.day]
  93. }
  94. })
  95. })
  96. }
  97. });
  98. }
  99. self.DatePageNo = 0;//向左平移n个工作事件
  100. self.DateWidth = 0;//向左平移距离
  101. self.DateLeft = function () {
  102. if (self.DatePageNo > 0) {
  103. self.DateWidth = self.DateWidth + $(".Date-page").eq(self.DatePageNo - 1).outerWidth(true);
  104. $(".Date-page").parent().css("margin-left", (self.DateWidth > 0 ? 0 : self.DateWidth));
  105. self.DatePageNo = self.DatePageNo - 1;
  106. } else {
  107. return;
  108. }
  109. }
  110. self.DateRight = function () {
  111. if (self.DatePageNo < $(".Date-page").length - 1) {
  112. self.DateWidth = self.DateWidth - $(".Date-page").eq(self.DatePageNo).outerWidth(true);
  113. $(".Date-page").parent().css("margin-left", self.DateWidth);
  114. self.DatePageNo = self.DatePageNo + 1;
  115. }
  116. }
  117. //初始化显示 当前年和月
  118. self.show_now = function () {
  119. var now = new Date();
  120. self.select_year = now.getFullYear();
  121. self.select_month = now.getMonth() + 1;
  122. self.active_day = formate(now.getDate());
  123. self.cyear = now.getFullYear();
  124. self.cmonth = now.getMonth() + 1;
  125. self.cday = formate(now.getDate());
  126. self.showTime()
  127. }
  128. self.showTime = function () {
  129. //在select中填入年份
  130. for (var year = self.select_year - 5; year < self.select_year + 5; year++) {
  131. var obj_1 = { 'value': year, 'id': year }
  132. self.all_year.push(obj_1);
  133. }
  134. //在select中填入月份
  135. for (var month = 1; month < 13; month++) {
  136. var obj_2 = { 'value': month, 'id': month }
  137. self.all_month.push(obj_2);
  138. }
  139. //初始化显示 当前年和月
  140. self.showDays(self.select_year, self.select_month)
  141. }
  142. //当select的选中的option发送变化的触发的事件
  143. self.change_year = function () {
  144. self.showDays(self.select_year, self.select_month)
  145. }
  146. self.change_month = function () {
  147. self.showDays(self.select_year, self.select_month)
  148. }
  149. //返回指定的月份的天数 月份1-12
  150. self.calDays = function (year, month) {
  151. return new Date(year, month, 0).getDate();
  152. }
  153. //展示指定的年和月的所有日期
  154. self.showDays = function (year, month) {
  155. self.days = [];
  156. var days = [];
  157. self.dateWork = [];
  158. self.date_day = self.active_day;
  159. self.getWeek(self.select_year, self.select_month, self.active_day)
  160. //得到表示指定年和月的1日的那个时间对象
  161. var date = new Date(year, month - 1, 1);
  162. //1.先添加响应的空白的li:这个月1号是星期几,就添加几个空白的li
  163. var dayOfWeek = date.getDay(); //得到1日是星期几
  164. for (var i = 0; i < dayOfWeek; i++) {
  165. days.push({ day: "", id: i + 8 });
  166. }
  167. //计算一个月有多少天
  168. var daysOfMonth = self.calDays(year, month);
  169. //2. 从1号开始添加li
  170. for (var i = 1; i <= daysOfMonth; i++) {
  171. days.push({ day: formate(i), id: i + dayOfWeek + 7 });
  172. }
  173. var length = days.length;
  174. for (var i = 42; i > length; i--) {
  175. days.push({ day: "", id: daysOfMonth - i + 50 });
  176. }
  177. $.each(days, function (index1, item1) {
  178. $.each(self.DateWork, function (index2, item2) {
  179. if (self.select_year + "-" + formate(self.select_month) + "-" + formate(item1.day) == item2.date) {
  180. item1.data = item2.data;
  181. if (item1.day == self.active_day) {
  182. self.dateWork = item1.data;
  183. }
  184. }
  185. })
  186. })
  187. for (var i = 0; i < 6 ; i++) {
  188. self.days[i] = [];
  189. $.each(days, function (index, item) {
  190. if (Math.ceil((index + 1) / 7) == i + 1) {
  191. self.days[i].push(item)
  192. }
  193. })
  194. }
  195. if (JSON.stringify(days).indexOf('"day":' + JSON.stringify(self.active_day)) == -1) {
  196. for (var i = days.length - 1; i >= 0; i--) {
  197. if (days[i].day != "") {
  198. self.active_day = days[i].day;
  199. break;
  200. }
  201. }
  202. }
  203. self.getDayInfo()
  204. self.getDateWork(self.select_year, self.select_month, self.active_day)
  205. }
  206. self.returnToday = function () {
  207. self.select_year = self.cyear;
  208. self.select_month = self.cmonth;
  209. self.active_day = self.cday;
  210. self.showDays(self.select_year, self.select_month)
  211. }
  212. self.change_day = function (day) {
  213. if (day.day == "") { return; }
  214. var date = new Date(self.select_year, self.select_month - 1, 1);
  215. var dayOfWeek = date.getDay();
  216. self.active_day = day.day;
  217. self.date_day = self.active_day;
  218. self.getWeek(self.select_year, self.select_month, self.active_day);
  219. self.getDateWork(self.select_year, self.select_month, self.active_day)
  220. }
  221. self.getWeek = function (year, month, day) {
  222. switch (new Date(year, month - 1, day).getDay()) {
  223. case 0: self.week = "星期日"; break;
  224. case 1: self.week = "星期一"; break;
  225. case 2: self.week = "星期二"; break;
  226. case 3: self.week = "星期三"; break;
  227. case 4: self.week = "星期四"; break;
  228. case 5: self.week = "星期五"; break;
  229. case 6: self.week = "星期六"; break;
  230. }
  231. }
  232. /*日历结束*/
  233. self.getZBNum = function () {
  234. self.hyNum = 0;
  235. self.zbNum = 0;
  236. var data = {
  237. CNAME: self.userId,
  238. //CNAME: self.userChineseName,
  239. SDATE: sp.dateCount(0) + " 08:00:00",
  240. EDATE: sp.dateCount(0) + " 18:00:00",
  241. NF: sp.currentYear(),
  242. YF: sp.currentMonth(),
  243. RIQI: formate(new Date().getDate())
  244. }
  245. $http.post(apiurljs.login + "g2app/deskcalendar/deskQueryHYandZBCountData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  246. .success(function (obj) {
  247. var res = strToJson(s4.decryptData_CBC(obj.data));
  248. self.hyNum = res.data.HYCOUNT;
  249. self.zbNum = res.data.ZBCOUNT;
  250. })
  251. }
  252. self.getZBNum()
  253. self.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType");
  254. self.openTab = function (n) {
  255. if (self.deviceType == "pad") {
  256. if (n == 1) {
  257. window.top.jumpPageParent("FZF09", "工作日程", "tpl/workschedule/index.html")
  258. } else if (n == 2) {
  259. window.top.jumpPageParent("FZJ06", "会议申请", "tpl/huiyishimgr/list.html")
  260. } else if (n == 3) {
  261. window.top.jumpPageParent("FZJ08-1", "值班表", "tpl/zhibanmgr/zhiban2.html")
  262. } else if (n == 4) {
  263. window.top.sp.addTabNav("FZJ08-2", "值班工作日志", "tpl/zhibanmgr/workList.html")
  264. }
  265. } else {
  266. if (n == 1) {
  267. window.top.sp.addTabNav("FZF09", "工作日程", "tpl/workschedule/index.html")
  268. } else if (n == 2) {
  269. window.top.sp.addTabNav("FZJ06", "会议申请", "tpl/huiyishimgr/list.html")
  270. } else if (n == 3) {
  271. window.top.sp.addTabNav("FZJ08-1", "值班表", "tpl/zhibanmgr/zhiban2.html")
  272. } else if (n == 4) {
  273. window.top.sp.addTabNav("FZJ08-2", "值班工作日志", "tpl/zhibanmgr/workList.html")
  274. }
  275. }
  276. event.stopPropagation();
  277. }
  278. }])
  279. function formate(num) {
  280. return num > 9 ? num : "0" + num;
  281. }
  282. function formateTime(str) {
  283. if (str == "1900-01-01T00:00:00") {
  284. str = "";
  285. return str;
  286. } else if (str == "0001-01-01T00:00:00") {
  287. ///这种情况是在做滨旅建管系统时用sqlserver数据库时遇到的
  288. str = "";
  289. return str;
  290. }
  291. else if (str != undefined && str != "" && str != null) {
  292. /////如果找到"-",不等于负1
  293. if (str.toString().indexOf('-') != -1) {
  294. str = str.replace(/-/g, "/"); //将-替换为/,因为ios与ie浏览器中不支持-和T
  295. }
  296. /////如果找到T,不等于负1
  297. if (str.toString().indexOf('T') != -1) {
  298. str = str.replace(/T/g, ' '); ///去掉日期中的T,因为ios与ie浏览器中不支持-和T
  299. }
  300. /////如果找到".",不等于负1
  301. if (str.toString().indexOf('.') != -1) {
  302. str = str.slice(0, str.indexOf(".")); ///如果含有毫秒,就将毫秒去掉
  303. }
  304. var formatDate = new Date(Date.parse(str));
  305. var MM = formatDate.getMonth() + 1;
  306. if (MM < 10) { MM = '0' + MM; } //去掉前面加0,是为了便于后续的格式化得到年月
  307. var dd = formatDate.getDate();
  308. if (dd < 10) { dd = '0' + dd; } //去掉前面加0,是为了便于后续的格式化得到年月
  309. var hh = formatDate.getHours();
  310. if (hh < 10) { hh = '0' + hh; }
  311. var mm = formatDate.getMinutes();
  312. if (mm < 10) { mm = '0' + mm; }
  313. var setDate = hh + ":" + mm;
  314. return setDate;
  315. } else {
  316. str = "";
  317. return str;
  318. }
  319. }