'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("listCtrl", ["$scope", "$http", "$timeout", "$interval", function ($scope, $http, $timeout, $interval) { 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.deviceType = localStorage.getItem("tjJxtGoldenlinkWork-deviceType"); self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno"); self.get_type = sp.getUrlName("type"); self.params = sp.getUrlName("params"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } self.type = self.get_type != "" ? self.get_type : "todo"; self.Url = getUrl(self.type); self.CrossPage = window.parent.CrossPage; self.loading = false; self.search = null//JSON.parse($.cookie("GlWorkPlatform-shouwenbg")); self.noDataTip = 1;//没有数据时赋变量为0,先默认为1 self.pageno = 1; self.total_count = 0; self.itemsPerPage = 10; self.pageOptions = [10, 20, 30, 40, 50, 100, 300, 500]; self.getJJQK = function () { var data = { ckey: "CODE_EMERGENCY", 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.JJQK = res.data.CODE_EMERGENCY; self.load() }) } self.ordercondition = []; self.flowids = [{ ID: "AA18", NAME: "一般收文", checked: false }, { ID: "AA16", NAME: "领导批示", checked: false }] self.getData = function (pageno) { if (self.search == null) { self.search = { FLOW: [], TITLE: "", JJCD: "", DATE1: "", DATE2: "", SWBH: '', LWDW: '', LWWH: '', LWRQ: '' } } var flowids = self.search.FLOW.join("|"); var querycondition = []; var columnscondition = [ { COLID: "JJCD", COLUMNS: "SW_LDPSCBD.JJCD|SW_ZJWWJCBD.JJCD" }, { COLID: "SWBH", COLUMNS: "SW_LDPSCBD.SWBH|SW_ZJWWJCBD.SWBH" }, { COLID: "LWDW", COLUMNS: "SW_LDPSCBD.LWDW|SW_ZJWWJCBD.LWDW" }, { COLID: "LWWH", COLUMNS: "SW_LDPSCBD.LWWH|SW_ZJWWJCBD.LWWH" }, { COLID: "LWRQ", COLUMNS: "SW_LDPSCBD.TO_CHAR(LWRQ)|SW_ZJWWJCBD.TO_CHAR(LWRQ)" }, { COLID: "DBSX", COLUMNS: "SW_LDPSCBD.DBSX|SW_ZJWWJCBD.DBSX" }, { COLID: "DBLX", COLUMNS: "SW_LDPSCBD.ZDDB|SW_ZJWWJCBD.DBLX" } ] if (self.search.TITLE != "") { querycondition.push({ "CKIND": "VARCHAR", "TABLEID": "SYS_ROUTE_VIEW", "COLID": "TITLE", "VALUEA": self.search.TITLE, "VALUEB": "" }) } if (self.search.JJCD != "") { querycondition.push({ "CKIND": "VARLIST", "TABLEID": "CODETABLE", "COLID": "JJCD", "VALUEA": self.search.JJCD.join(","), "VALUEB": "" }) } if (self.search.SWBH != "") { querycondition.push({ "CKIND": "VARCHAR", "TABLEID": "CODETABLE", "COLID": "SWBH", "VALUEA": self.search.SWBH, "VALUEB": "" }) } if (self.search.LWDW != "") { querycondition.push({ "CKIND": "VARCHAR", "TABLEID": "CODETABLE", "COLID": "LWDW", "VALUEA": self.search.LWDW, "VALUEB": "" }) } if (self.search.LWWH != "") { querycondition.push({ "CKIND": "VARCHAR", "TABLEID": "CODETABLE", "COLID": "LWWH", "VALUEA": self.search.LWWH, "VALUEB": "" }) } if (self.search.LWRQ != "") { querycondition.push({ "CKIND": "VARCHAR", "TABLEID": "CODETABLE", "COLID": "LWRQ", "VALUEA": self.search.LWRQ, "VALUEB": "" }) } if (self.params != "") { querycondition.push({ "CKIND": "VARLIST", "TABLEID": "SYS_ROUTE", "COLID": "ROUTEID", "VALUEA": self.params, "VALUEB": "" }) } if (self.search.DATE1 != "" && self.search.DATE2 != "") { querycondition.push({ "CKIND": "DATETIME", "TABLEID": "SYS_ROUTE_VIEW", "COLID": "RECEIVEDATE", "VALUEA": self.search.DATE1, "VALUEB": self.search.DATE2 }) } else if (self.search.DATE1 != "" && self.search.DATE2 == "") { querycondition.push({ "CKIND": "DATETIME", "TABLEID": "SYS_ROUTE_VIEW", "COLID": "RECEIVEDATE", "VALUEA": self.search.DATE1, "VALUEB": ""}) } else if (self.search.DATE1 == "" && self.search.DATE2 != "") { querycondition.push({ "CKIND": "DATETIME", "TABLEID": "SYS_ROUTE_VIEW", "COLID": "RECEIVEDATE", "VALUEA": "", "VALUEB": self.search.DATE2 }) } self.list = []; self.loading = true; self.pageno = pageno; $scope.__default__currentPage = self.pageno; //设置页面样式在第几页 var data = { flowid: flowids == "" ? "AA18|AA16" : flowids, userid: self.userId, pageno: self.pageno, pagesize: self.itemsPerPage, columnscondition: JSON.stringify(columnscondition), querycondition: JSON.stringify(querycondition), ordercondition: self.ordercondition.length == 0 ? "" : JSON.stringify(self.ordercondition) } //$http.post(apiurljs.login + "g2work/routeinfo/" + self.Url, { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) $http.post(apiurljs.login + "g2work/routeinfo/" + self.Url, data, postCfg) .success(function (obj) { var res = obj; //var res = strToJson(s4.decryptData_CBC(obj.data)); self.loading = false; if (res.data == null || res.data == undefined || res.data == "") { self.noDataTip = 0; if (self.params != "") { self.params = ""; self.getData(1) } } else { self.noDataTip = 1; self.list = res.data; self.total_count = res.totalCount; $.each(self.list, function (index, item) { item.LWRQ = sp.format(item.LWRQ); self.JJQK.forEach(function (item1) { if (item.JJCD == item1.CODE) { item.JJCD = item1.CNAME } }) if (item.FILEN != "") { item.FILEN = item.FILEN.indexOf("dotype") > -1 ? item.FILEN.replace("dotype=1", "dotype=" + getDoType(self.type)) + "&type=" + self.type + "&lastReturnPageno=" + self.pageno + "&flowid=" + item.FLOWID : item.FILEN + "&dotype=" + getDoType(self.type) + "&type=" + self.type + "&lastReturnPageno=" + self.pageno + "&flowid=" + item.FLOWID; } else { item.FILEN = "#"; } if (self.type == "finish") { item.RECEIVEDATE = item.FINISHEDDATE; } }) } }) } self.load = function () { if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") { self.getData(self.pageno); } else { $timeout(function () { self.getData(self.get_lastReturnPageno); }, 1) } } self.sortFiled = function (str) { var n = 0, obj, x = -1; self.ordercondition.forEach(function (item, index) { if (item.COLID == str) { n++ item.SORTTYPE = item.SORTTYPE == "" || item.SORTTYPE == "asc" ? "desc" : "asc" obj = item; x = index } }) if (n == 0) { self.ordercondition.unshift({ COLID: str, SORTTYPE: "desc" }) } if (x != -1) { self.ordercondition.splice(x, 1) self.ordercondition.unshift(obj) } self.getData(1); } self.getJJQK(); self.openLayer = function () { self.params = ""; if (self.search == null) { self.search = { FLOW: [], TITLE: "", JJCD: "", DATE1: "", DATE2: "", SWBH: '', LWDW: '', LWWH: '', LWRQ: '' } } else { self.flowids.forEach(function (item) { item.checked = false; if (self.search.FLOW.indexOf(item.ID) > -1) { item.checked = true; } }) self.JJQK.forEach(function (item) { item.checked = false; if (self.search.JJCD.indexOf(item.CODE) > -1) { item.checked = true; } }) } sp.layer("#Search") } self.doSearch = function () { self.search.FLOW = []; self.flowids.forEach(function (item) { if (item.checked == true) { self.search.FLOW.push(item.ID) } }) self.search.JJCD = []; self.JJQK.forEach(function (item) { if (item.checked == true) { self.search.JJCD.push(item.CODE) } }) self.getData(self.pageno) sp.layerhide() } self.cancal = function () { self.search = { FLOW: [], TITLE: "", JJCD: "", DATE1: "", DATE2: "", SWBH: '', LWDW: '', LWWH: '', LWRQ: '' } $.cookie("GlWorkPlatform-shouwenbg", null, { path: '/', expires: 1 }); self.getData(1) sp.layerhide() } self.refresh = function () { self.CrossPage.type = null; self.getData(self.pageno); } self.goUrl = function (item) { if (item.TODOLIST && item.TODOLIST.length > 1) { self.todoTitle = item.TITLE; self.todoList = item.TODOLIST; sp.layer("#todolist") } else { if (self.deviceType == "pad") { window.location.href = item.FILEN + "&dotype=" + getDoType(self.type) } else { sp.openNewWindow(item.FILEN + "&dotype=" + getDoType(self.type), item.TITLE) } sp.layerhide(); } } self.btnDel = function (item) { var data = { routeinfoid: item.ROUTEINFOID, userid: self.userId } $http.post(apiurljs.login + "g2work/routeinfo/deleteDraftByRouteinfoid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success == true) { self.getData(self.pageno) } else { sp.dialog(res.message) } }) } self.btnRecall = function (routeid,kind) { var data = { routeid: routeid, kind:kind, userid: self.userId } $http.post(apiurljs.login + "g2work/routeinfo/queryDataRecallDoneByRouteid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); var dialogHead = "温馨提示×"; var dialogBody = "
" + res.data.REMARK + "
"; var dialogFoot = "
"; $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot); sp.openCenter(".sp-dialog"); ///取消按钮 $('.sp-closeDialog').click(function (event) { sp.closeCenter(".sp-dialog"); event.preventDefault(); event.stopPropagation(); }); //post消息的id $("#delDataTrue").click(function () { $http.post(apiurljs.login + "g2work/routeinfo/recallDoneByRouteid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); sp.dialoghide() if (res.success == true) { self.getData(self.pageno) } else { sp.dialog(res.message) } }) }); }) } self.changeType = function (str) { if (self.type == str) { return; } else { var time1 = sp.getLocalDate1(); self.journalRecord(time1, sp.getLocalDate1(), "查询", "查询日志", "/g2work/routeinfo/" + self.Url) self.type = str; self.Url = getUrl(self.type); self.getData(1) } } self.getAddFlag = function () { var data = { userid: self.userId, ntops: 0 } $http.post(apiurljs.login + "g2work/desktop/queryWorkflowCando", data, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.lcList = []; self.activeLC = {}; res.data.forEach(function (item) { if ("AA18|AA16|AA02|AA17".indexOf(item.FLOWID) > -1) { self.lcList.push(item); } }) }) } self.getAddFlag() self.addLC = function () { if (self.lcList.length == 1) { sp.openNewWindow(self.lcList[0].FILEN + "&dotype=1&flowid=" + self.lcList[0].FLOWID, self.lcList[0].FLOWNAME) } else { sp.layer("#addLC"); } } self.seeLCT = function (item,event) { event.preventDefault(); event.stopPropagation(); } self.goAddUrl = function (obj) { sp.openNewWindow(obj.FILEN + "&dotype=1&flowid=" + obj.FLOWID, obj.FLOWNAME) sp.layerhide() } self.printEXCEL = function () { self.columns = [ { header: "紧急程度", key: "JJCD", width: 20 }, { header: "收文类别", key: "FLOWNAME", width: 20 }, { header: "收文编号", key: "SWBH", width: 20 }, { header: "标题", key: "TITLE", width: 100 }, { header: "来文单位", key: "LWDW", width: 20 }, { header: "来文文号", key: "LWWH", width: 20 }, { header: "来文日期", key: "LWRQ", width: 25 }, { header: "上一节点转办时间", key: "RECEIVEDATE", width: 25 } ] self.listExcel = self.list.map(function (item) { return { JJCD: item.JJCD, FLOWNAME: item.FLOWNAME, SWBH: item.SWBH, TITLE: item.TITLE, LWDW: item.LWDW, LWWH: item.LWWH, LWRQ: item.LWRQ, RECEIVEDATE: item.RECEIVEDATE } }) // 创建工作簿 var workbook = new ExcelJS.Workbook() // 添加工作表 var worksheet = workbook.addWorksheet('sheet1') // 设置表头 worksheet.columns = self.columns // 添加表体数据 self.listExcel.forEach(function (item) { worksheet.addRow(item) }) /** * 设置样式 */ // 1、设置标题行样式 var headerRow = worksheet.getRow(1) // 连续遍历所有非空单元格 headerRow.eachCell(function (cell) { // 边框 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E8%BE%B9%E6%A1%86 cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' }, } // 填充 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E5%A1%AB%E5%85%85 cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: '4f81bd' } } // 字体 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E5%AD%97%E4%BD%93 cell.font = { name: '微软雅黑', size: 11, bold: true, color: { argb: '000000' } } // 对齐 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E5%AF%B9%E9%BD%90 cell.alignment = { vertical: 'middle', horizontal: 'center' } }) // 2、设置内容行样式 const bodyRow = worksheet.getRows(2, self.listExcel.length + 1) bodyRow.forEach(function (row) { //遍历此列中的所有当前单元格,包括空单元格 row.eachCell({ includeEmpty: true }, function (cell) { // 边框 cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' }, } // 字体 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E5%AD%97%E4%BD%93 cell.font = { name: '微软雅黑', size: 11, color: { argb: '000000' } } // 对齐 https://github.com/exceljs/exceljs/blob/HEAD/README_zh.md#%E5%AF%B9%E9%BD%90 cell.alignment = { vertical: 'middle', horizontal: 'center' } }) }) // 导出表格 workbook.xlsx.writeBuffer().then(function (buffer) { const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) const link = document.createElement('a') link.href = URL.createObjectURL(blob) link.download = '收文' + sp.format(sp.getLocalDate()) + '.xlsx' link.click() URL.revokeObjectURL(link.href) // 下载完成释放掉blob对象 }) //}) } //记录日志 self.journalRecord = function (time1, time2, title, func, url) { if (!self.CrossPage || !self.CrossPage.cname) { return; } var data = { tablename: "SYS_CLICKLOG", data: { CTIME: time1 == null ? sp.getLocalDate1() : time1, TITLE: (title != "" ? self.CrossPage.cname + "/" + title : self.CrossPage.cname), REQUESTURL: url, REQUESTHEADERURL: window.location.origin, LOGTYPE: func, USERTYPE: $.cookie("GlWorkPlatform-userType"), ADMIN: $.cookie("GlWorkPlatform-userTypeEng"), CLIENTIP: sp.myIP(), PCNAME: sp.detectOS(), BROWSERNAME: sp.browser(), RESPONSETIME: time2 == null ? sp.getLocalDate1() : time2, USERID: self.userId, USERNAME: self.userName } } $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (res) { self.CrossPage.type = 1; }) } var width = 0, height = 0; $interval(function () { if (localStorage.getItem("GlWorkPlatform-shouwenbg-refresh") == 1) { localStorage.removeItem("GlWorkPlatform-shouwenbg-refresh") self.refresh() } }, 1000) //头部下滚冻结 $(function () { width = window.outerWidth; height = window.outerHeight; //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } }, 1) }) }]) function getUrl(str) { switch (str) { case "todo": return "queryDataTodoWithPage"; break; case "done": return "queryDataDoneWithPage"; break; case "finish": return "queryDataFinishWithPage"; break; } } function getDoType(str) { switch (str) { case "todo": return 1; break; default: return 0; break; } }