duty.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination', ////分页用到的插件
  4. 'ngSanitize'///$sanitize这个服务.此服务依赖于ngSanitize模块.(这个模块需要加载angular-sanitize.js插件)
  5. ////应用ng-bind-html如果不引用此模块,会报安全错误
  6. ]);
  7. app.controller("dutyCtrl", ["$http", function ($http) {
  8. var self = this;
  9. self.userId = $.cookie("GlWorkPlatform-userid");
  10. self.userName = $.cookie("GlWorkPlatform-username");
  11. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  12. var postCfg = {
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. 'Authorization': "Bearer " + self.get_AccessToken
  16. }
  17. };
  18. ////加载本周的值班安排
  19. self.getNowDay = function () {
  20. var objDate = new Date();
  21. var str, colorhead, colorfoot;
  22. var yy = objDate.getFullYear();
  23. var MM = objDate.getMonth() + 1;
  24. var dd = objDate.getDate();
  25. str = yy + "年" + MM + "月" + dd + "日";
  26. return str;
  27. };
  28. var getStart = getWeekNumber(new Date());
  29. self.duty = {
  30. year: sp.currentYear(),
  31. weekNum: getStart.week,
  32. nowDay: self.getNowDay(),
  33. weekday: getStart.weekday
  34. }
  35. //console.log(getStart);
  36. var weekNum = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
  37. self.weekinfo = [];
  38. self.getWeekInfo = function () {
  39. var data = {
  40. year:self.duty.year,
  41. weekNum: self.duty.weekNum
  42. };
  43. $http.get("json/duty1.txt", data, postCfg)
  44. .success(function (res) {
  45. if (res.success) {
  46. self.weekinfo = res.Items;
  47. $.each(self.weekinfo, function (index, item) {
  48. self.weekinfo[index].weekNum = weekNum[index]; ////往数组中插入一个叫weekNum的变量
  49. self.weekinfo[index].day = getStart.dateString.split(",")[index];
  50. });
  51. //console.log(JSON.stringify(self.weekinfo));
  52. }
  53. });
  54. };
  55. self.getWeekInfo();
  56. //数据表格的控制器,动态加载table表格数据
  57. self.noDataTip = 1; //声明没有数据时变量
  58. self.rows = [];
  59. self.pageno = 1;
  60. self.total_count = 0;
  61. self.itemsPerPage = 8;
  62. self.pageOptions = [8, 12, 16, 20, 24, 26];
  63. self.getData = function (pageno) {
  64. self.pageno = pageno;
  65. self.rows = [];
  66. var data = {
  67. pagesize: self.itemsPerPage,
  68. pageno: self.pageno
  69. };
  70. $http.get("json/duty2.txt", data, postCfg)
  71. .success(function (res) {
  72. if (res.Items == null || res.Items == undefined || res.Items == "") {
  73. self.noDataTip = 0;
  74. } else {
  75. self.noDataTip = 1;
  76. self.rows = res.Items;
  77. self.total_count = res.total_count;
  78. $.each(self.rows, function (index,item) {
  79. item.tdate = sp.format(item.tdate);
  80. });
  81. }
  82. });
  83. };
  84. ///先加载该用户设置的分页码,有设置的话就用,没有就用上面的变量
  85. self.loadData = function () {
  86. var data = {
  87. userid: "admin",
  88. gridid: window.location.pathname
  89. };
  90. $http.get("json/getPageNo.txt", data, postCfg)
  91. .success(function (res) {
  92. console.log(res)
  93. if (res.success) {
  94. self.itemsPerPage = parseInt(res.data);
  95. }
  96. ///根据详情页返回的页码,加载该页码的数据
  97. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  98. self.getData(1);// 初始化 当前页为 1
  99. } else {
  100. self.getData(self.get_lastReturnPageno); ///加载接收页码的数据
  101. }
  102. //self.getData(self.pageno);
  103. });
  104. }
  105. self.loadData();
  106. ////保存该用户设置的分页页码数量
  107. self.changePageOption = function () {
  108. var data = {
  109. userid: "admin",
  110. gridid: window.location.pathname,
  111. "value": self.itemsPerPage
  112. };
  113. $http.get("json/savePageNo.txt", data, postCfg)
  114. .success(function (res) {
  115. if (res.success) {
  116. console.log(res.message);
  117. } else {
  118. console.log(res.message);
  119. }
  120. });
  121. };
  122. //数据表格的控制器 end
  123. ///判断是否为闰年
  124. function isLeapYear(year) {
  125. return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
  126. }
  127. //判断每个月的天数
  128. function getMonthDays(year, month) {
  129. return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
  130. }
  131. //格式化
  132. function dateFtt(fmt, date) {
  133. var o = {
  134. "M+": date.getMonth() + 1, //月份
  135. "d+": date.getDate(), //日
  136. "h+": date.getHours(), //小时
  137. "m+": date.getMinutes(), //分
  138. "s+": date.getSeconds(), //秒
  139. "q+": Math.floor((date.getMonth() + 3) / 3), //季度
  140. "S": date.getMilliseconds() //毫秒
  141. };
  142. if (/(y+)/.test(fmt))
  143. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  144. for (var k in o)
  145. if (new RegExp("(" + k + ")").test(fmt)) {
  146. fmt = fmt.replace(RegExp.$1, (o[k]));
  147. }
  148. return fmt;
  149. }
  150. //判断所选日期是第几周 传入时间对象
  151. function getWeekNumber(obj) {
  152. var year = obj.getFullYear(); //年
  153. var month = obj.getMonth(); //月
  154. var days = obj.getDate(); //日
  155. var nowTime = obj.getTime(); //毫秒
  156. var day = obj.getDay(); //星期几
  157. //那一天是那一年中的第多少天
  158. for (var i = 0; i < month; i++) {
  159. days += getMonthDays(year, i);
  160. }
  161. //那一年第一天是星期几
  162. var yearFirstDay = new Date(year, 0, 1).getDay() || 7;
  163. var week = null;
  164. if (yearFirstDay == 1) {
  165. week = Math.ceil(days / 7);
  166. } else {
  167. days -= (7 - yearFirstDay + 1);
  168. week = Math.ceil(days / 7) + 1;
  169. }
  170. var oneDayLong = 24 * 60 * 60 * 1000;
  171. if (day == 0) {
  172. var MondayTime = nowTime - 6 * oneDayLong;
  173. var SundayTime = nowTime;
  174. } else {
  175. var MondayTime = nowTime - (day - 1) * oneDayLong;
  176. var SundayTime = nowTime + (7 - day) * oneDayLong;
  177. }
  178. var dateString="";
  179. for (var i = 0;i<7;i++){
  180. var time = MondayTime + (oneDayLong) * i;
  181. dateString += dateFtt("MM.dd", new Date(time)) + ","
  182. }
  183. var monday = dateFtt("yyyy-MM-dd", new Date(MondayTime));
  184. var sunday = dateFtt("yyyy-MM-dd", new Date(SundayTime));
  185. return {
  186. begin: monday,
  187. end: sunday,
  188. week: week,
  189. dateString: dateString.substring(0, dateString.length - 1),
  190. weekday: ["周日","周一", "周二", "周三", "周四", "周五", "周六"][day]
  191. }
  192. }
  193. //调用方式getWeekNumber(new Date())
  194. self.getSelectedWeekInfo = function (strid) {
  195. self.duty.year = self.rows[strid].tyear
  196. self.duty.weekNum = self.rows[strid].tweek;
  197. self.getWeekInfo();
  198. };
  199. ////声明添加模块的变量
  200. self.add = {
  201. year: sp.currentYear(),
  202. week: getStart.week,
  203. title: "",
  204. ctype:"日常"
  205. };
  206. ////值班安排提交按钮
  207. self.btnAddDuty = function () {
  208. var data = {
  209. tyear: self.add.year,
  210. tweek: self.add.week,
  211. title: self.add.year + "年第" + self.add.week + "周值班安排",
  212. ctype: self.add.ctype,
  213. depart:"办公室",
  214. person: "admin",
  215. tdate: sp.format(sp.getLocalDate())
  216. };
  217. console.log(data);
  218. $http.get("json/message.txt", data, postCfg)
  219. .success(function (res) {
  220. if (res.success) {
  221. sp.layerhide();
  222. sp.dialog("你好,添加成功!");
  223. self.rows.unshift(data); ///json往数组前头添加元素
  224. setTimeout(function () {
  225. sp.dialoghide();
  226. }, 1000);
  227. } else {
  228. sp.dialog("您好,新建失败!");
  229. }
  230. });
  231. }
  232. }]);