123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
- app.controller("holidayCtrl", ["$http", "$scope", function ($http, $scope) {
- var self = this;
- self.userId = $.cookie("GlWorkPlatform-userid");
- self.userName = $.cookie("GlWorkPlatform-username");
- self.userChineseName = $.cookie("GlWorkPlatform-chineseName");
- self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno") || 1; ///接收传过来的第几页
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- };
- self.yearAndMonth = "";
- self.currentYear = sp.currentYear();
- self.currentMonth = sp.currentMonth();
- self.currentDay = sp.getday(0);
- ////检索指定年月的节假日记录
- self.workdayArray = [];
-
-
- self.noDataTip = 1;
- self.queryDataWorkday = function (cyear, cmonth) {
-
- self.yearAndMonth = cyear + "年" + cmonth + "月";
- self.currentYear = cyear;
- self.currentMonth = cmonth;
-
- self.workdayArray = [];
- var postData = {
- "cyear": cyear,
- "cmonth": cmonth
- };
- $http.post(apiurljs.login + "g2work/workday/queryDataWorkday", postData, postCfg).success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- //console.log(JSON.stringify(res));
- if (sp.isval(res.data)) {
- var dayArray_init = res.data;
- var dayArray = res.data;
- angular.forEach(dayArray, function (item) {
- item.isDisabled = false;
- })
- var dayLength = res.data.length;
-
- /////判断第一个是周几,然后将前面不齐,凑够每组7个---start
- var firstArrayData = dayArray_init[0];
- for (var i = parseInt(firstArrayData.WEEKS) ; i > 0 ; i--) {
- if (i != 0) {
- var set_1 = parseInt(firstArrayData.WEEKS) + 1;
- var jianDayNum = i - set_1;
- //console.log(i, jianDayNum);
- var setJson = {
- "WEEKS": parseInt(i - 1).toString(), "DATES": self.getday(firstArrayData.DATES, jianDayNum), "ISWORKDAY": "1", "isDisabled": true
- }
- dayArray.unshift(setJson);
- } else {
- var setJson = {
- "WEEKS": "0", "DATES": self.getday(firstArrayData.DATES, -parseInt(firstArrayData.WEEKS)), "ISWORKDAY": "0", "isDisabled": true
- }
- dayArray.unshift(setJson);
- }
- }
- /////判断第一个是周几,然后将前面不齐,凑够每组7个---start
- //判断最后一个日期是周几,然后补齐---start
- //console.log(dayArray_init[dayArray_init.length - 1].WEEKS);
- var lastBuNum = 6 - parseInt(res.data[res.data.length - 1].WEEKS);
- var lastArrayData = res.data[res.data.length - 1];
- //console.log(lastBuNum);
- for (var k = 1; k < lastBuNum + 1; k++) {
- //console.log(k, lastArrayData.DATES);
- if (parseInt(lastArrayData.WEEKS) + k != 6) {
- var setJson = {
- "WEEKS": (parseInt(lastArrayData.WEEKS) + k).toString(), "DATES": self.getday(lastArrayData.DATES, k), "ISWORKDAY": "1", "isDisabled": true
- }
- //console.log(setJson);
- dayArray.push(setJson);
- } else {
- var setJson = {
- "WEEKS": "6", "DATES": self.getday(lastArrayData.DATES, k), "ISWORKDAY": "0", "isDisabled": true
- }
- //console.log(setJson);
- dayArray.push(setJson);
- }
-
- }
- //判断最后一个日期是周几,然后补齐---end
- //console.log(JSON.stringify(dayArray));
- //console.log(dayArray.length);
-
- angular.forEach(dayArray, function (item2) {
- item2.DATES_set = sp.datefmt("MM-dd", item2.DATES);
- if (!item2.isDisabled ) {
- if (item2.ISWORKDAY == '0') {
- ///节假日
- item2.xiu = true;
- } else {
- ///工作日 item2.ISWORKDAY 为1
- if (item2.WEEKS == "0" || item2.WEEKS == "6") {
- item2.ban = true;
- } else {
- item2.ban = false;
- }
- }
- }
- })
-
- var arryPartIndex = Math.ceil(dayArray.length / 7);
- //console.log(arryPartIndex);
- for (var j = 0; j < arryPartIndex; j++) {
- //console.log(j);
- var set_array_1 = dayArray.splice(0, 7);
- self.workdayArray.push({ "data": set_array_1 });
- }
-
- //console.log(JSON.stringify(self.workdayArray));
- self.noDataTip = 1;
- } else {
- ///没有数据时
- //console.log(JSON.stringify(res));
- self.workdayArray = [];
- self.noDataTip = 0;
- }
- });
- };
- self.queryDataWorkday(sp.currentYear(),self.currentMonth);
- //self.queryDataWorkday("2023", "1");
- ///得到几天前和几天后的日期 getday(7);//7天后的日期 getday(17);//7天前的日期
- self.getday = function (datestr,aa) {
- var date1 = new Date(datestr),
- time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();//time1表示当前时间
- var date2 = new Date(date1);
- date2.setDate(date1.getDate() + aa);
- var y = date2.getFullYear();
- var m = (date2.getMonth() + 1) < 10 ? "0" + (date2.getMonth() + 1) : (date2.getMonth() + 1);//获取当前月份的日期,不足10补0
- var d = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();//获取当前几号,不足10补0
- var time2 = y + "-" + m + "-" + d;
- return time2;
- }
- self.info = {
- DATES: "",
- ISWORKDAY:"1"
- }
- self.btnUpdateDay = function (itemdata) {
- if (!itemdata.isDisabled) {
- self.info = {
- DATES: itemdata.DATES,
- ISWORKDAY: itemdata.ISWORKDAY
- }
- sp.layer("#layer_holiday");
- }
- }
- self.btnSubmit = function () {
- var postData = {
- "dates": self.info.DATES,
- "isworkday": self.info.ISWORKDAY
- };
- $http.post(apiurljs.login + "g2work/workday/updateDataWorkdayStatus", postData, postCfg).success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- //console.log(JSON.stringify(res));
- if (res.success) {
- sp.layerhide();
- self.queryDataWorkday(self.currentYear,self.currentMonth);
- }
- });
- }
- ///上个月
- self.btnPrevMonth = function () {
- ////上个月的某个日期
- var get_prevMonthDay = sp.getPreMonthDay(self.currentYear + "-" + self.currentMonth + "-01", -1);
- self.queryDataWorkday(sp.formatGetYear(get_prevMonthDay), sp.formatGetMonth(get_prevMonthDay));
-
- }
- ///下个月
- self.btnNextMonth = function () {
- ////下个月的某个日期
- var get_nextMonthDay = sp.getPreMonthDay(self.currentYear + "-" + self.currentMonth + "-01", 1);
- self.queryDataWorkday(sp.formatGetYear(get_nextMonthDay), sp.formatGetMonth(get_nextMonthDay));
- }
- ////今天
- self.btnCurentMonth = function () {
- self.currentMonth = sp.currentMonth();
- self.queryDataWorkday(sp.currentYear(), self.currentMonth);
- }
- ///没有数据时--初始化当月
- self.btnInitMonth = function () {
- if (confirm("您确定要初始化当月数据吗?")) {
- var postData = {
- "cyear": self.currentYear,
- "cmonth": self.currentMonth
- };
- $http.post(apiurljs.login + "g2work/workday/initDataWorkday", postData, postCfg).success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- //console.log(JSON.stringify(res));
- if (res.success) {
- self.queryDataWorkday(self.currentYear, self.currentMonth);///再次加载数据
- }
- });
- }
- }
- ///没有数据时--初始化当年
- self.btnInitYear = function () {
- if (confirm("您确定要初始化当月数据吗?")) {
- var postData = {
- "cyear": self.currentYear,
- "cmonth": ""
- };
- $http.post(apiurljs.login + "g2work/workday/initDataWorkday", postData, postCfg).success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- //console.log(JSON.stringify(res));
- if (res.success) {
- self.queryDataWorkday(self.currentYear, self.currentMonth);///再次加载数据
- }
- });
- }
- }
- }]);
|