gzrc.js 13 KB

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