'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("totalCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) { 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.get_lastReturnPageno = sp.getUrlName("lastReturnPageno"); self.dateParam = sp.getUrlName("date"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } self.loading = false; self.search = self.dateParam == "" ? { DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end } : { DATE1: self.dateParam, DATE2: self.dateParam } self.getData = function () { self.list = []; self.loading = false; var data = { tablename: "SX_YZAPTZ", colums: "*,TO_CHAR(YZAPDATE,'MM-dd')as YZAPDATE1", order: "YZAPDATE ASC,CTIME ASC,LDSORTID ASC,CNAME ASC", //sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59' and USERID='" + self.userId + "'" sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59'" } $http.post(apiurljs.login + "g2app/dataabase/queryDataByColStr", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.loading = false; self.addFlag = false; self.editFlag = false; self.addList = []; self.list = res.data; self.list.forEach(function (item) { item.CTIME1 = item.CTIME.slice(11, 16); item.CNAME = item.CNAME == "null" ? "" : item.CNAME item.ATTENDANCESCOPE = item.ATTENDANCESCOPE == "null" ? "" : item.ATTENDANCESCOPE item.ADDR = item.ADDR == "null" ? "" : item.ADDR item.TIMEPERIOD1 = item.TIMEPERIOD; item.CTIME2 = item.CTIME1; item.CNAME1 = item.CNAME; item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE; item.ADDR1 = item.ADDR; }) }) } self.getData(); self.openLayer = function () { sp.layer("#Search") } self.doSearch = function () { sp.layerhide() if (self.search.DATE1 == "" || self.search.DATE2 == "") { sp.dialog("时间为可为空!"); return } $.cookie("GlWorkPlatform-yzaptotal", JSON.stringify(self.search), { path: '/', expires: 1 }); self.getData(); } self.cancal = function () { self.search = { DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end } $.cookie("GlWorkPlatform-yzaptotal", null, { path: '/', expires: 1 }); self.getData(); sp.layerhide() } self.refresh = function () { self.getData(); } self.printOut = function () { if (self.canExportExcel) { $('#table 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('#table'), cell, "一周安排台账") //设置表格的样式 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' }), '一周安排台账.xlsx') } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) } return wbout } else { sp.dialog('数据还未加载完成,请稍等...') } } //头部下滚冻结 $(function () { //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } }, 1) }) }]) app.directive("repeatFinish", function () { return { link: function (scope) { if (scope.$last == true) { scope.$parent.ctl.canExportExcel = true; setTimeout(function () { $("#table").rowspan(7) $("#table").rowspan(6) $("#table").rowspan(5) $("#table").rowspan(3) $("#table").rowspan(2) $("#table").rowspan(1) $("#table").rowspan(0) }, 10); } } }; }); 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; } }); }); }); }