'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("listCtrl", ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) { var self = this; var s4 = new SM4Util(); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-chineseName"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); self.dateParam = sp.getUrlName("date"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } self.search = { type: 1, dw: "", date: self.dateParam == "" ? sp.currentYear() + "-" + formate(sp.currentMonth()) : self.dateParam } self.showType = 1; self.getYF = function () { var data = { ckey: "CODE_ZBYF", routeinfoid: self.routeinfoid } $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.YF = res.data.CODE_ZBYF; self.getXQ() }) } self.getXQ = function () { var data = { ckey: "CODE_ZBXQ", routeinfoid: self.routeinfoid } $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.XQ = res.data.CODE_ZBXQ; self.getType() }) } self.getType = function () { var data = { userid: self.userId } $http.post(apiurljs.login + "g2app/dataabase/queryDPParentName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); for (var i in res.data[0]) { if (res.data[0][i][0].PARENT_DATA.length > 0){ self.search.type = res.data[0][i][0].PARENT_DATA[0].SECTION != "直属单位" ? 1 : 2; } else { self.search.type = 1; } } //self.search.type == res.data; if (self.search.type == 1) { self.getZBSJ() } else { self.getZBSJ1() } }) } //委机关 self.getZBSJ = function () { var data = { ckey: "CODE_ZHIBANTIME", routeinfoid: self.routeinfoid } $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.ZBSJ = res.data.CODE_ZHIBANTIME; self.getData() }) } //直属单位 self.getZBSJ1 = function () { var data = { ckey: "CODE_ZHIBANTIMEZSDW", routeinfoid: self.routeinfoid } $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.ZBSJ = res.data.CODE_ZHIBANTIMEZSDW; self.getDP() }) } self.getDP = function () { var data = { userid: self.userId } $http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION; self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE; self.getData(); }) } self.getYF() self.getData = function () { var year = self.search.date.split("-")[0], month = ""; self.YF.forEach(function (item) { if (formate(item.CNAME) == self.search.date.split("-")[1]) { month = item.CODE; } }) self.list = []; self.list1 = []; self.list2 = []; var data = { tablename: self.search.type == 1 ? "SX_PRZBB" : "SX_YFZBB", colums: "*", order: "ID desc", sqlwhere: { NF: year, YF: month, STOPMARK: 1 }, sqlorwhere: "", sqlinwhere: "", sqllikewhere: self.search.type == 1 ? "" : { SQDWCODE: self.userDpCode } } $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.canExportExcel = true; if (res.data == null || res.data == undefined || res.data == "") { } else { self.parentID = res.data[0].ID; if (self.search.type == 1) { self.ZBREMARK = res.data[0].ZBREMARK; } else { self.ZBSJREMARK = res.data[0].ZBSJREMARK; self.ZBDH = res.data[0].ZBDH; self.ZBCZ = res.data[0].ZBCZ; self.YJJJRZBDH = res.data[0].YJJJRZBDH; self.YJJJRZBCZ = res.data[0].YJJJRZBCZ; self.ZBDD = res.data[0].ZBDD; self.TBR = res.data[0].TBR; self.REMARK = res.data[0].REMARK; } if (self.search.type == 1) { var data = { tablename: "SX_PRZBB_01", colums: "*", order: "ID", sqlwhere: { PID: self.parentID }, sqlinwhere: "", sqllikewhere: "" } $http.post(apiurljs.login + "/g2app/ZhiBan/queryPRZBList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.data.indexmark.start_index == 0) { self.table1 = 4; self.table2 = 1 } if (res.data.indexmark.start_index2 == 0) { self.table1 = 1; self.table2 = 4 } if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) { self.table1 = 1; self.table2 = 0 } console.log(self.table1) $.each(res.data.data, function (index, item) { item.editFlag = false; item.RIQI = formate(item.RIQI); self.ZBSJ.forEach(function (item1) { if (item.ZBSJ == item1.CODE) { item.ZBSJ = item1.CNAME } }) if (res.data.indexmark.start_index == 0 && res.data.indexmark.start_index2 > 0) { if (index < res.data.indexmark.start_index2) { self.list1.push(item) } else { self.list2.push(item) } } if (res.data.indexmark.start_index2 == 0 && res.data.indexmark.start_index > 0) { if (index < res.data.indexmark.start_index) { self.list1.push(item) } else { self.list2.push(item) } } if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) { self.list1.push(item) } }) }) } else { var data1 = { tablename: "SX_YFZBB_01", colums: "*", order: "ID", sqlwhere: { PID: self.parentID }, sqlinwhere: "", sqllikewhere: "" } $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg) .success(function (obj1) { var res1 = strToJson(s4.decryptData_CBC(obj1.data)); self.list1 = res1.data; self.list1.forEach(function (item) { item.RIQI = formate(item.RIQI); self.XQ.forEach(function (item1) { if (item.XINGQI == item1.CODE) { item.XINGQI = item1.CNAME } }) self.ZBSJ.forEach(function (item1) { if (item.ZBSJ == item1.CODE) { item.ZBSJ = item1.CNAME } }) }) }) } } }) } self.printOut = function () { if (self.canExportExcel) { $('#printOut td').attr('t', 's') var defaultCellStyle = { font: { name: 'Times New Roman', sz: 12, color: { rgb: "000000" }, bold: false, italic: false, underline: false }, alignment: { vertical: "center", horizontal: "center", indent: 0, wrapText: true }, border: { top: { style: "thin", color: { rgb: "000000" } }, right: { style: "thin", color: { rgb: "000000" } }, bottom: { style: "thin", color: { rgb: "000000" } }, left: { style: "thin", color: { rgb: "000000" } } } }; var cell = { defaultCellStyle: defaultCellStyle }; var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, (self.search.type == 1 ? "委机关值班表" : "直属单位值班表")) //设置表格的样式 var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: false, type: 'binary', cellStyles: true, defaultCellStyle: defaultCellStyle, showGridLines: false }); var s2ab = function (s) { var buf = new ArrayBuffer(s.length); var view = new Uint8Array(buf); for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; return buf; }; try { saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), (self.search.type == 1 ? "委机关值班表" : "直属单位值班表") + '.xlsx') } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) } return wbout } else { sp.dialog('数据还未加载完成,请稍等...') } } //委机关查看直属单位 self.getZSDW = function () { var data = { nf: self.search.date.split("-")[0], yfname: parseInt(self.search.date.split("-")[1]), columns: "*" } $http.post(apiurljs.login + "g2app/ZhiBan/queryZSDWList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.zsdwList = res.data; self.zsdwList.forEach(function (item) { item.BSDATE1 = sp.datefmt("yyyy-MM-dd", item.BSDATE) }) }) } self.goDetail = function (item) { if (item.STOPMARK == '1' || item.WNCKBS == '1') { sp.openNewWindow("detail.html?id=" + item.ID + "&bssj=" + new Date(item.BSDATE1).getTime(), item.CNAME + self.search.date.slice(5) + "月值班表") } else { } } //头部下滚冻结 $(function () { //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } }, 1) }) }]) app.filter('trustHtml', function ($sce) { return function (input) { return $sce.trustAsHtml(input.replace(/\n/g, '
').replace(/\s/g, ' ')); }; }); app.directive("repeatFinish", function () { return { link: function (scope) { if (scope.$last == true) { setTimeout(function () { $(".sp-table").rowspan(1) $(".sp-table").rowspan(0) }, 10); } } }; }); function formate(d) { return d * 1 > 9 ? d * 1 : "0" + d * 1 } jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件 return this.each(function () { var that; $('tr', this).each(function (row) { $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) { if (that != null && $(this).html() == $(that).html()) { var rowspan = $(that).attr("rowSpan"); if (rowspan == undefined) { $(that).attr("rowSpan", 1); rowspan = $(that).attr("rowSpan"); } rowspan = Number(rowspan) + 1; $(that).attr("rowSpan", rowspan); $(this).remove(); } else { that = this; } }); }); }); }