index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  2. app.controller("holidayCtrl", ["$http", "$scope", function ($http, $scope) {
  3. var self = this;
  4. self.userId = $.cookie("GlWorkPlatform-userid");
  5. self.userName = $.cookie("GlWorkPlatform-username");
  6. self.userChineseName = $.cookie("GlWorkPlatform-chineseName");
  7. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  8. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno") || 1; ///接收传过来的第几页
  9. var postCfg = {
  10. headers: {
  11. 'Content-Type': 'application/json',
  12. 'Authorization': "Bearer " + self.get_AccessToken
  13. }
  14. };
  15. self.yearAndMonth = "";
  16. self.currentYear = sp.currentYear();
  17. self.currentMonth = sp.currentMonth();
  18. self.currentDay = sp.getday(0);
  19. ////检索指定年月的节假日记录
  20. self.workdayArray = [];
  21. self.noDataTip = 1;
  22. self.queryDataWorkday = function (cyear, cmonth) {
  23. self.yearAndMonth = cyear + "年" + cmonth + "月";
  24. self.currentYear = cyear;
  25. self.currentMonth = cmonth;
  26. self.workdayArray = [];
  27. var postData = {
  28. "cyear": cyear,
  29. "cmonth": cmonth
  30. };
  31. $http.post(apiurljs.login + "g2work/workday/queryDataWorkday", postData, postCfg).success(function (obj) {
  32. var res = strToJson(s4.decryptData_CBC(obj.data));
  33. //console.log(JSON.stringify(res));
  34. if (sp.isval(res.data)) {
  35. var dayArray_init = res.data;
  36. var dayArray = res.data;
  37. angular.forEach(dayArray, function (item) {
  38. item.isDisabled = false;
  39. })
  40. var dayLength = res.data.length;
  41. /////判断第一个是周几,然后将前面不齐,凑够每组7个---start
  42. var firstArrayData = dayArray_init[0];
  43. for (var i = parseInt(firstArrayData.WEEKS) ; i > 0 ; i--) {
  44. if (i != 0) {
  45. var set_1 = parseInt(firstArrayData.WEEKS) + 1;
  46. var jianDayNum = i - set_1;
  47. //console.log(i, jianDayNum);
  48. var setJson = {
  49. "WEEKS": parseInt(i - 1).toString(), "DATES": self.getday(firstArrayData.DATES, jianDayNum), "ISWORKDAY": "1", "isDisabled": true
  50. }
  51. dayArray.unshift(setJson);
  52. } else {
  53. var setJson = {
  54. "WEEKS": "0", "DATES": self.getday(firstArrayData.DATES, -parseInt(firstArrayData.WEEKS)), "ISWORKDAY": "0", "isDisabled": true
  55. }
  56. dayArray.unshift(setJson);
  57. }
  58. }
  59. /////判断第一个是周几,然后将前面不齐,凑够每组7个---start
  60. //判断最后一个日期是周几,然后补齐---start
  61. //console.log(dayArray_init[dayArray_init.length - 1].WEEKS);
  62. var lastBuNum = 6 - parseInt(res.data[res.data.length - 1].WEEKS);
  63. var lastArrayData = res.data[res.data.length - 1];
  64. //console.log(lastBuNum);
  65. for (var k = 1; k < lastBuNum + 1; k++) {
  66. //console.log(k, lastArrayData.DATES);
  67. if (parseInt(lastArrayData.WEEKS) + k != 6) {
  68. var setJson = {
  69. "WEEKS": (parseInt(lastArrayData.WEEKS) + k).toString(), "DATES": self.getday(lastArrayData.DATES, k), "ISWORKDAY": "1", "isDisabled": true
  70. }
  71. //console.log(setJson);
  72. dayArray.push(setJson);
  73. } else {
  74. var setJson = {
  75. "WEEKS": "6", "DATES": self.getday(lastArrayData.DATES, k), "ISWORKDAY": "0", "isDisabled": true
  76. }
  77. //console.log(setJson);
  78. dayArray.push(setJson);
  79. }
  80. }
  81. //判断最后一个日期是周几,然后补齐---end
  82. //console.log(JSON.stringify(dayArray));
  83. //console.log(dayArray.length);
  84. angular.forEach(dayArray, function (item2) {
  85. item2.DATES_set = sp.datefmt("MM-dd", item2.DATES);
  86. if (!item2.isDisabled ) {
  87. if (item2.ISWORKDAY == '0') {
  88. ///节假日
  89. item2.xiu = true;
  90. } else {
  91. ///工作日 item2.ISWORKDAY 为1
  92. if (item2.WEEKS == "0" || item2.WEEKS == "6") {
  93. item2.ban = true;
  94. } else {
  95. item2.ban = false;
  96. }
  97. }
  98. }
  99. })
  100. var arryPartIndex = Math.ceil(dayArray.length / 7);
  101. //console.log(arryPartIndex);
  102. for (var j = 0; j < arryPartIndex; j++) {
  103. //console.log(j);
  104. var set_array_1 = dayArray.splice(0, 7);
  105. self.workdayArray.push({ "data": set_array_1 });
  106. }
  107. //console.log(JSON.stringify(self.workdayArray));
  108. self.noDataTip = 1;
  109. } else {
  110. ///没有数据时
  111. //console.log(JSON.stringify(res));
  112. self.workdayArray = [];
  113. self.noDataTip = 0;
  114. }
  115. });
  116. };
  117. self.queryDataWorkday(sp.currentYear(),self.currentMonth);
  118. //self.queryDataWorkday("2023", "1");
  119. ///得到几天前和几天后的日期 getday(7);//7天后的日期 getday(17);//7天前的日期
  120. self.getday = function (datestr,aa) {
  121. var date1 = new Date(datestr),
  122. time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();//time1表示当前时间
  123. var date2 = new Date(date1);
  124. date2.setDate(date1.getDate() + aa);
  125. var y = date2.getFullYear();
  126. var m = (date2.getMonth() + 1) < 10 ? "0" + (date2.getMonth() + 1) : (date2.getMonth() + 1);//获取当前月份的日期,不足10补0
  127. var d = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();//获取当前几号,不足10补0
  128. var time2 = y + "-" + m + "-" + d;
  129. return time2;
  130. }
  131. self.info = {
  132. DATES: "",
  133. ISWORKDAY:"1"
  134. }
  135. self.btnUpdateDay = function (itemdata) {
  136. if (!itemdata.isDisabled) {
  137. self.info = {
  138. DATES: itemdata.DATES,
  139. ISWORKDAY: itemdata.ISWORKDAY
  140. }
  141. sp.layer("#layer_holiday");
  142. }
  143. }
  144. self.btnSubmit = function () {
  145. var postData = {
  146. "dates": self.info.DATES,
  147. "isworkday": self.info.ISWORKDAY
  148. };
  149. $http.post(apiurljs.login + "g2work/workday/updateDataWorkdayStatus", postData, postCfg).success(function (obj) {
  150. var res = strToJson(s4.decryptData_CBC(obj.data));
  151. //console.log(JSON.stringify(res));
  152. if (res.success) {
  153. sp.layerhide();
  154. self.queryDataWorkday(self.currentYear,self.currentMonth);
  155. }
  156. });
  157. }
  158. ///上个月
  159. self.btnPrevMonth = function () {
  160. ////上个月的某个日期
  161. var get_prevMonthDay = sp.getPreMonthDay(self.currentYear + "-" + self.currentMonth + "-01", -1);
  162. self.queryDataWorkday(sp.formatGetYear(get_prevMonthDay), sp.formatGetMonth(get_prevMonthDay));
  163. }
  164. ///下个月
  165. self.btnNextMonth = function () {
  166. ////下个月的某个日期
  167. var get_nextMonthDay = sp.getPreMonthDay(self.currentYear + "-" + self.currentMonth + "-01", 1);
  168. self.queryDataWorkday(sp.formatGetYear(get_nextMonthDay), sp.formatGetMonth(get_nextMonthDay));
  169. }
  170. ////今天
  171. self.btnCurentMonth = function () {
  172. self.currentMonth = sp.currentMonth();
  173. self.queryDataWorkday(sp.currentYear(), self.currentMonth);
  174. }
  175. ///没有数据时--初始化当月
  176. self.btnInitMonth = function () {
  177. if (confirm("您确定要初始化当月数据吗?")) {
  178. var postData = {
  179. "cyear": self.currentYear,
  180. "cmonth": self.currentMonth
  181. };
  182. $http.post(apiurljs.login + "g2work/workday/initDataWorkday", postData, postCfg).success(function (obj) {
  183. var res = strToJson(s4.decryptData_CBC(obj.data));
  184. //console.log(JSON.stringify(res));
  185. if (res.success) {
  186. self.queryDataWorkday(self.currentYear, self.currentMonth);///再次加载数据
  187. }
  188. });
  189. }
  190. }
  191. ///没有数据时--初始化当年
  192. self.btnInitYear = function () {
  193. if (confirm("您确定要初始化当月数据吗?")) {
  194. var postData = {
  195. "cyear": self.currentYear,
  196. "cmonth": ""
  197. };
  198. $http.post(apiurljs.login + "g2work/workday/initDataWorkday", postData, postCfg).success(function (obj) {
  199. var res = strToJson(s4.decryptData_CBC(obj.data));
  200. //console.log(JSON.stringify(res));
  201. if (res.success) {
  202. self.queryDataWorkday(self.currentYear, self.currentMonth);///再次加载数据
  203. }
  204. });
  205. }
  206. }
  207. }]);