index-leader.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination',
  4. ]);
  5. app.controller("indexCtrl", ["$scope", "$http", "$interval", function ($scope, $http, $interval) {
  6. var self = this;
  7. self.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-chineseName");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. var postCfg = {
  11. headers: {
  12. 'Content-Type': 'application/json',
  13. 'Authorization': "Bearer " + self.get_AccessToken
  14. }
  15. };
  16. self.getQXbtn = function () {
  17. var data = {
  18. userid: self.userId,
  19. ntops: 10
  20. };
  21. $http.post(apiurljs.login + "g2work/desktop/queryWorkflowCando", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  22. .success(function (obj) {
  23. var res = strToJson(s4.decryptData_CBC(obj.data));
  24. self.qxBtn = res.data;
  25. $.each(self.qxBtn, function (index, item) {
  26. item.FILEN = item.FILEN + "&dotype=1"
  27. })
  28. })
  29. }
  30. self.getQXbtn()
  31. self.openSwen = function (item) {
  32. window.parent.sp.addTabNav(item.FLOWID, item.FLOWNAME, item.FILEN)
  33. }
  34. self.dbList = [];
  35. self.Activedb = "全部";
  36. self.dbTitleList = [];
  37. self.getdbList = function (n) {
  38. var data = {
  39. userid: self.userId,
  40. ntops: 0
  41. };
  42. $http.post(apiurljs.login + "g2work/desktop/queryDataTodo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  43. .success(function (obj) {
  44. var res = strToJson(s4.decryptData_CBC(obj.data));
  45. if (n == 0) {
  46. self.dbTitleList = [];
  47. self.dbList = [];
  48. self.dbDataList = res.data;
  49. self.dbItemList = { "width": (res.data.length + 4) * ($(".dbItem1").width() / 6 - 10), "height": "120px" }
  50. self.dbTitleList.push(self.Activedb);
  51. $.each(self.dbDataList, function (index, item) {
  52. if (self.dbTitleList.indexOf(item.FLOWNAME) == -1) {
  53. self.dbTitleList.push(item.FLOWNAME)
  54. }
  55. if (item.REMARKS.length == 3) {
  56. item.REMARKS = null;
  57. }
  58. item.day = self.getDay(item.RECEIVEDATE);
  59. item.MD = sp.datefmt("MM-dd", item.RECEIVEDATE);
  60. item.HM = sp.datefmt("HH:mm", item.RECEIVEDATE);
  61. item.USERNAMEFROM1 = "转自:" + item.USERNAMEFROM;
  62. item.width = { "width": $(".dbItem1").width() / 6 - 10 };
  63. item.FILEN = item.FILEN + "&dotype=1";
  64. self.dbList.push(item);
  65. })
  66. //$interval(function () {
  67. // self.getdbList(1)
  68. //}, 5000)
  69. } else {
  70. if (self.dbDataList.length == res.data.length) {
  71. return;
  72. } else {
  73. self.dbItemList = { "width": (res.data.length + 4) * ($(".dbItem1").width() / 6 - 10), "height": "120px" }
  74. var newDate = res.data.concat();
  75. for (var i = res.data.length - 1; i >= 0; i--) {
  76. $.each(self.dbDataList, function (index, item) {
  77. if (res.data[i].ROUTEINFOID == item.ROUTEINFOID) {
  78. newDate.splice(i, 1)
  79. }
  80. })
  81. }
  82. $.each(newDate, function (index, item) {
  83. if (self.dbTitleList.indexOf(item.FLOWNAME) == -1) {
  84. self.dbTitleList.push(item.FLOWNAME)
  85. }
  86. self.dbDataList.unshift(item);
  87. if (item.FLOWNAME == self.Activedb || self.Activedb == "全部") {
  88. if (item.REMARKS.length == 3) {
  89. item.REMARKS = null;
  90. }
  91. item.day = self.getDay(item.RECEIVEDATE);
  92. item.MD = sp.datefmt("MM-dd", item.RECEIVEDATE);
  93. item.HM = sp.datefmt("HH:mm", item.RECEIVEDATE);
  94. item.USERNAMEFROM1 = "转自:" + item.USERNAMEFROM;
  95. item.width = { "width": $(".dbItem1").width() / 6 - 10 };
  96. item.FILEN = item.FILEN + "&dotype=1"
  97. self.dbList.unshift(item);
  98. }
  99. })
  100. }
  101. }
  102. })
  103. }
  104. self.getDay = function (str) {
  105. var a = getDate(new Date());
  106. var b = getDate(new Date(str));
  107. var c = parseInt((a - b) / 86400000);
  108. return c < 0 || c > 2 ? 3 : c;
  109. }
  110. self.getdbList(0)
  111. self.dbItemNo = 0;//待办事项向左平移n个按钮
  112. self.dbpageWidth = 0;//待办事项向左平移距离
  113. self.dbpageLeft = function () {
  114. if (self.dbItemNo > 0 && self.dbList.length > 6) {
  115. //self.dbpageWidth = self.dbpageWidth + $(".dbItem").eq(self.dbItemNo - 1).outerWidth(true) * 6;
  116. //$(".dbItem1").children().first().css("margin-left", (self.dbpageWidth > 0 ? 0 : self.dbpageWidth));
  117. //self.dbItemNo = self.dbItemNo - 6;
  118. self.dbItemNo = self.dbItemNo - 6;
  119. self.dbpageWidth = $(".dbItem1").outerWidth(true) * (self.dbItemNo / 6);
  120. $(".dbItem1").children().first().css("margin-left", self.dbpageWidth * -1);
  121. } else {
  122. return;
  123. }
  124. }
  125. self.dbpageRight = function () {
  126. if (self.dbItemNo < $(".dbItem").length - 6 && self.dbList.length > 6) {
  127. //self.dbpageWidth = self.dbpageWidth - $(".dbItem").eq(self.dbItemNo).outerWidth(true) * 6;
  128. //$(".dbItem1").children().first().css("margin-left", self.dbpageWidth);
  129. //self.dbItemNo = self.dbItemNo + 6;
  130. self.dbItemNo = self.dbItemNo + 6;
  131. self.dbpageWidth = $(".dbItem1").outerWidth(true) * (self.dbItemNo / 6);
  132. $(".dbItem1").children().first().css("margin-left", self.dbpageWidth * -1);
  133. } else {
  134. return;
  135. }
  136. }
  137. self.resetdb = function (str) {
  138. self.dbList = [];
  139. self.Activedb = str;
  140. self.dbItemNo = 0;
  141. self.dbpageWidth = 0;
  142. $(".dbItem1").children().first().css("margin-left", 0);
  143. $.each(self.dbDataList, function (index, item) {
  144. if (item.FLOWNAME == self.Activedb || self.Activedb == "全部") {
  145. self.dbList.push(item);
  146. }
  147. })
  148. }
  149. self.ldrcNo = 0;//领导日程向左平移n个按钮
  150. self.ldrcWidth = 0;//领导日程向左平移距离
  151. self.ldrcLeft = function () {
  152. if (self.ldrcNo > 0) {
  153. self.dbpageWidth = self.dbpageWidth + $(".ldrcItem").eq(self.ldrcNo - 1).outerWidth(true);
  154. $(".ldrcItem").parent().css("margin-left", (self.dbpageWidth > 0 ? 0 : self.dbpageWidth));
  155. self.ldrcNo = self.ldrcNo - 1;
  156. } else {
  157. return;
  158. }
  159. }
  160. self.ldrcRight = function () {
  161. if (self.ldrcNo < $(".ldrcItem").length - 1) {
  162. self.dbpageWidth = self.dbpageWidth - $(".ldrcItem").eq(self.ldrcNo).outerWidth(true);
  163. $(".ldrcItem").parent().css("margin-left", self.dbpageWidth);
  164. self.ldrcNo = self.ldrcNo + 1;
  165. }
  166. }
  167. self.grrcNo = 0;//个人日程向左平移n个按钮
  168. self.grrcWidth = 0;//个人日程向左平移距离
  169. self.grrcLeft = function () {
  170. if (self.grrcNo > 0) {
  171. self.dbpageWidth = self.dbpageWidth + $(".grrcItem").eq(self.grrcNo - 1).outerWidth(true);
  172. $(".grrcItem").parent().css("margin-left", (self.dbpageWidth > 0 ? 0 : self.dbpageWidth));
  173. self.grrcNo = self.grrcNo - 1;
  174. } else {
  175. return;
  176. }
  177. }
  178. self.grrcRight = function () {
  179. if (self.grrcNo < $(".grrcItem").length - 1) {
  180. self.dbpageWidth = self.dbpageWidth - $(".grrcItem").eq(self.grrcNo).outerWidth(true);
  181. $(".grrcItem").parent().css("margin-left", self.dbpageWidth);
  182. self.grrcNo = self.grrcNo + 1;
  183. }
  184. }
  185. self.activeItem1 = "公文督办";
  186. self.activeItem2 = "通知公告";
  187. self.getData = function () {
  188. var data = {}
  189. $http.get("js/leader.txt", data, postCfg)
  190. .success(function (res) {
  191. self.list1 = res.list1;
  192. self.list2 = res.list2;
  193. self.ldzl = res.ldzl;
  194. self.today = {
  195. date: sp.getday(0),
  196. week: getWeek(sp.getday(0))
  197. };
  198. self.week = {
  199. date1: sp.getWeekNumber(new Date()).begin,
  200. date2: sp.getNextDate(sp.getWeekNumber(new Date()).begin, 1),
  201. date3: sp.getNextDate(sp.getWeekNumber(new Date()).begin, 2),
  202. date4: sp.getNextDate(sp.getWeekNumber(new Date()).begin, 3),
  203. date5: sp.getNextDate(sp.getWeekNumber(new Date()).begin, 4)
  204. }
  205. })
  206. }
  207. self.getData()
  208. /*日历开始*/
  209. self.all_year = [];
  210. self.all_month = [];
  211. self.select_year = ''
  212. self.select_month = ''
  213. self.active_day = ''
  214. self.week = ''
  215. //初始化显示 当前年和月
  216. self.show_now = function () {
  217. var now = new Date();
  218. self.select_year = now.getFullYear();
  219. self.select_month = now.getMonth() + 1;
  220. self.active_day = formate(now.getDate());
  221. self.cyear = now.getFullYear();
  222. self.cmonth = now.getMonth() + 1;
  223. self.cday = formate(now.getDate());
  224. self.showTime()
  225. //self.getDateWork(self.select_year, self.select_month, self.active_day)
  226. }
  227. self.showTime = function () {
  228. //在select中填入年份
  229. for (var year = self.select_year - 5; year < self.select_year + 5; year++) {
  230. var obj_1 = { 'value': year, 'id': year }
  231. self.all_year.push(obj_1);
  232. }
  233. //在select中填入月份
  234. for (var month = 1; month < 13; month++) {
  235. var obj_2 = { 'value': month, 'id': month }
  236. self.all_month.push(obj_2);
  237. }
  238. //初始化显示 当前年和月
  239. self.showDays(self.select_year, self.select_month)
  240. }
  241. //返回指定的月份的天数 月份1-12
  242. self.calDays = function (year, month) {
  243. return new Date(year, month, 0).getDate();
  244. }
  245. self.dateLeft = function () {
  246. var date = new Date(self.select_year, self.select_month - 1, 0)
  247. self.select_year = date.getFullYear();
  248. self.select_month = date.getMonth() + 1;
  249. self.showDays(self.select_year, self.select_month)
  250. }
  251. self.dateRight = function () {
  252. var date = new Date(self.select_year, self.select_month + 1, 0)
  253. self.select_year = date.getFullYear();
  254. self.select_month = date.getMonth() + 1;
  255. self.showDays(self.select_year, self.select_month)
  256. }
  257. //展示指定的年和月的所有日期
  258. self.showDays = function (year, month) {
  259. self.days = [];
  260. var days = [];
  261. self.dateWork = [];
  262. self.date_day = self.active_day;
  263. self.getWeek(self.select_year, self.select_month, self.active_day)
  264. //得到表示指定年和月的1日的那个时间对象
  265. var date = new Date(year, month - 1, 1);
  266. //1.先添加响应的空白的li:这个月1号是星期几,就添加几个空白的li
  267. var dayOfWeek = date.getDay(); //得到1日是星期几
  268. for (var i = 0; i < dayOfWeek; i++) {
  269. days.push({ day: "", id: i + 8 });
  270. }
  271. //计算一个月有多少天
  272. var daysOfMonth = self.calDays(year, month);
  273. //2. 从1号开始添加li
  274. for (var i = 1; i <= daysOfMonth; i++) {
  275. days.push({ day: formate(i), id: i + dayOfWeek + 7 });
  276. }
  277. var length = days.length;
  278. for (var i = 42; i > length; i--) {
  279. days.push({ day: "", id: daysOfMonth - i + 50 });
  280. }
  281. for (var i = 0; i < 6 ; i++) {
  282. self.days[i] = [];
  283. $.each(days, function (index, item) {
  284. if (Math.ceil((index + 1) / 7) == i + 1) {
  285. self.days[i].push(item)
  286. }
  287. })
  288. }
  289. if (JSON.stringify(days).indexOf('"day":' + JSON.stringify(self.active_day)) == -1) {
  290. for (var i = days.length - 1; i >= 0; i--) {
  291. if (days[i].day != "") {
  292. self.active_day = days[i].day;
  293. break;
  294. }
  295. }
  296. }
  297. }
  298. self.change_day = function (day) {
  299. if (day.day == "") { return; }
  300. var date = new Date(self.select_year, self.select_month - 1, 1);
  301. var dayOfWeek = date.getDay();
  302. self.active_day = day.day;
  303. self.date_day = self.active_day;
  304. self.getWeek(self.select_year, self.select_month, self.active_day);
  305. }
  306. self.getWeek = function (year, month, day) {
  307. switch (new Date(year, month - 1, day).getDay()) {
  308. case 0: self.week = "星期日"; break;
  309. case 1: self.week = "星期一"; break;
  310. case 2: self.week = "星期二"; break;
  311. case 3: self.week = "星期三"; break;
  312. case 4: self.week = "星期四"; break;
  313. case 5: self.week = "星期五"; break;
  314. case 6: self.week = "星期六"; break;
  315. }
  316. }
  317. /*日历结束*/
  318. self.openSwen = function (item) {
  319. window.parent.sp.addTabNav(item.FLOWID, item.FLOWNAME, item.FILEN)
  320. }
  321. }])
  322. function formate(num) {
  323. return num > 9 ? num : "0" + num;
  324. }
  325. function getWeek(date) {
  326. switch (new Date(date).getDay()) {
  327. case 0: return "星期日"; break;
  328. case 1: return "星期一"; break;
  329. case 2: return "星期二"; break;
  330. case 3: return "星期三"; break;
  331. case 4: return "星期四"; break;
  332. case 5: return "星期五"; break;
  333. case 6: return "星期六"; break;
  334. }
  335. }
  336. function getDate(str) {
  337. var year = str.getFullYear();
  338. var month = str.getMonth();
  339. var day = str.getDate();
  340. return new Date(year, month, day).getTime()
  341. }