'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("listCtrl", ["$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.tablename = "SX_TFWZZGZB" var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } self.loading = false; self.getHead = function () { self.loading = true; var data = { tablename: self.tablename, order: "sortid" } $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)) self.thead = []; $.each(res.data, function (index, item) { if (item.code != "ID" && item.code != "ROUTEINFOID" && item.code != "SORTID" && item.code != "APPCODE" && item.code != "CTIME" && item.code != "CJGZSJ") { self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind }) } }) self.thead_left = self.thead.slice(0, 4) self.thead_right = self.thead.slice(4) self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) self.uploadFile = ""; self.getData() }) } self.getHead() self.changeDate = function () { if (self.date > sp.currentYear() + "-" + formate(sp.currentMonth())) { $timeout(function () { self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) }, 1) } } self.changeTB = function (tablename) { if (self.tablename == tablename) { return; } else { self.tablename = tablename; self.getHead() } } self.setPrintIn = function () { self.inport = { tablename: "SX_TFWZZGZB", thead: "" } self.getInportTable() sp.layer("#importDivPart") } self.getInportTable = function () { var data = { tablename: self.inport.tablename, order: "sortid" } $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)) self.inport.thead = []; $.each(res.data, function (index, item) { if (item.code != "ID" && item.code != "ROUTEINFOID" && item.code != "SORTID" && item.code != "APPCODE" && item.code != "CTIME") { self.inport.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind }) } }) console.log(self.inport.thead) }) } ////导入文件按钮操作事件 self.btnFileChange = function () { self.excelData = []; ///定义excel中的数组 self.excelHeadData = []; var X = XLSX; var XW = { msg: 'xlsx', worker: './js/xlsxworker.js' }; var global_wb; var process_wb = (function () { var OUT = document.getElementById('out'); var to_json = function to_json(workbook) { var result = {}; workbook.SheetNames.forEach(function (sheetName) { var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName], { header: 1 }); if (roa.length) result[sheetName] = roa; }); for (var i in result) { var sheet = i; } //console.log(result[sheet]); self.excelData = result[sheet]; /////声明excel中的数据变量 //console.log(JSON.stringify(self.excelData)); self.excelHeadData = self.excelData[0]; ////excel的头部数据 //console.log(self.excelHeadData); return JSON.stringify(result[sheet], 2, 2); }; return function process_wb(wb) { global_wb = wb; var output = to_json(wb); if (OUT.innerText === undefined) OUT.textContent = output; else OUT.innerText = output; //console.log(self.excelData); if (typeof console !== 'undefined') console.log("output", new Date()); }; })(); var setfmt = window.setfmt = function setfmt() { if (global_wb) process_wb(global_wb); }; var do_file = (function () { var rABS = typeof FileReader !== "undefined" && (FileReader.prototype || {}).readAsBinaryString; var domrabs = document.getElementsByName("userabs")[0]; if (!rABS) domrabs.disabled = !(domrabs.checked = false); var use_worker = typeof Worker !== 'undefined'; var domwork = document.getElementsByName("useworker")[0]; if (!use_worker) domwork.disabled = !(domwork.checked = false); var xw = function xw(data, cb) { var worker = new Worker(XW.worker); worker.onmessage = function (e) { switch (e.data.t) { case 'ready': break; case 'e': console.error(e.data.d); break; case XW.msg: cb(JSON.parse(e.data.d)); break; } }; worker.postMessage({ d: data, b: rABS ? 'binary' : 'array' }); }; return function do_file(files) { rABS = domrabs.checked; use_worker = domwork.checked; var f = files[0]; $timeout(function () { self.uploadFile = f.name; },1) var reader = new FileReader(); reader.onload = function (e) { if (typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker); var data = e.target.result; if (!rABS) data = new Uint8Array(data); if (use_worker) xw(data, process_wb); else process_wb(X.read(data, { type: rABS ? 'binary' : 'array' })); }; if (rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); }; })(); (function () { var xlfile = document.getElementById('xlfile'); if (!xlfile.addEventListener) return; function handleFile(e) { do_file(e.target.files); } xlfile.addEventListener('change', handleFile, false); })(); var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-36810333-1']); _gaq.push(['_trackPageview']); (function () { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); }; self.btnFileChange(); self.printIn = function () { if (self.uploadFile == "") { sp.dialog("请先上传文件"); } else { self.getImportData = self.excelData; sp.layer("#importDivPart") } } /////确定导入数据 self.btnTrueImportData = function () { //$("#btnTrueImportData").attr("disabled", "disabled"); //$("#btnTrueImportData span").text("正在导入中..."); var loc = ""; $("#table_excelHead table tbody tr").each(function () { var getcode = $("td:eq(0)", this).attr("data-code"); var getcol = $("td:eq(1) select", this).val() == "? undefined:undefined ?" ? "''" : $("td:eq(1) select", this).val(); var getckind = $("td:eq(0)", this).attr("data-ckind"); var loastr = '{"tcode":"' + getcode + '","excelCol":"' + getcol + '","ckind":"' + getckind + '"},'; loc += loastr; }); loc = "[" + loc.substring(0, loc.length - 1) + "]"; var loc1 = JSON.parse(loc.replace(/\n/g, "")); var num = 0; self.excelData1 = [] for (var i = 0; i < self.excelData.length; i++) { self.excelData1[i] = []; if (self.excelData[i].length != 0) { for (var j = 0; j < loc1.length; j++) { for (var x = 0; x < self.excelHeadData.length; x++) { if (loc1[j].excelCol == self.excelHeadData[x]) { if (loc1[j].ckind == "datetime" && i > 0) { if (loc1[j].tcode == "FFNY" && self.excelData[i][x] != undefined) { self.excelData1[i].push(self.excelData[i][x] + "01") } else { //self.excelData1[i].push(sp.format(self.excelData[i][x])) self.excelData1[i].push(self.excelData[i][x]) } } else { self.excelData1[i].push(self.excelData[i][x]) } } } } } } var data = { tablename: self.inport.tablename, headarry: loc1, arr: JSON.stringify(self.excelData1), startdata:1 } console.log(data) $http.post(apiurljs.login + "g2app/richang/impGongZiData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); sp.layerhide() if (res.success == true) { sp.dialog("导入成功"); self.getData() $("#xlfile").val(""); self.uploadFile = ""; $timeout(function () { sp.dialoghide() }, 1000) } else { sp.dialog(res.message); } }); }; self.printOut = function () { var title = self.date.split("-")[0] + "年" + self.date.split("-")[1] + "月" + (self.tablename == "SX_TFWZZGZB" ? "统发外在职工资单" : self.tablename == "SX_TFWTXGZB" ? "统发外退休工资单" : "统发外离休工资单") 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, title) //设置表格的样式 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' }), title + '.xlsx') } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) } return wbout } else { sp.dialog('数据还未加载完成,请稍等...') } } self.YINHANG = function () { self.yhList = []; var data = { cname: "SX_TFWZZGZB", ffny: self.date } $http.post(apiurljs.login + "g2app/richang/queryDataToBank", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)) self.yhList = res.data; sp.layer("#YINHANG") }) } self.downloadYH = function () { var title = "统发外在职工资银行表格" if (self.canExportExcel) { $('#yh 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('#yh'), cell, title) //设置表格的样式 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('数据还未加载完成,请稍等...') } } self.noDataTip = 1;//没有数据时赋变量为0,先默认为1 self.getData = function () { self.list = []; self.checkedAll = false; self.loading = true; if (self.tablename == "SX_TFWZZGZB") { var data = { ffny: self.date, sfzhm: "", xm: "" } $http.post(apiurljs.login + "g2app/richang/querytfwzzgzbDataT", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { //var res = strToJson(s4.decryptData_CBC(obj.data)); var res = obj.data; self.canExportExcel = true; self.loading = false; //if (res.data == null || res.data == undefined || res.data == "") { if (res== null || res== undefined || res.length==0) { self.noDataTip = 0; } else { self.noDataTip = 1; //res.data.forEach(function (item) { res.forEach(function (item) { item.DATA.forEach(function (item1) { self.list.push(item1) }) }); self.list.forEach(function (item) { item.checked = false; self.thead.forEach(function (item1) { if (item1.ckind == "datetime") { item[item1.code] = item[item1.code] ? sp.minsToDate("yyyy-MM", item[item1.code]) : ""; } if (item.NAMETYPE == "合计") { item.XM = "合计"; } }) }) } }) } else { self.list = []; var data = { tablename: self.tablename, colums: "*", order: "ID", sqlwhere: "", sqlorwhere: "", sqlinwhere: "", sqllikewhere: { FFNY: self.date } }; $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; self.loading = false; if (res.data == null || res.data == undefined || res.data == "") { self.noDataTip = 0; } else { self.noDataTip = 1; self.list = res.data; self.list.forEach(function (item) { item.checked = false; self.thead.forEach(function (item1) { if (item1.ckind == "datetime") { item[item1.code] = sp.format(item[item1.code]).slice(0, 10) } }) }) } }) } } self.checkAll = function () { //self.checkedAll = !self.checkedAll; self.list.forEach(function (item) { item.checked = self.checkedAll }) } self.checkItem = function (obj) { //obj.checked = !obj.checked; var n = 0; self.list.forEach(function (item) { if (item.checked == true) { n++ } }) self.checkedAll = n == self.list.length; } self.btnDelete = function () { var ids = []; self.list.forEach(function (item) { if (item.checked == true) { ids.push(item.ID) } }) if (ids.length == 0) { sp.dialog("请选择要删除的数据!") return; } var dialogHead = "温馨提示×"; var dialogBody = "
删除后不可恢复,确定要删除吗
"; 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 () { var data = { tablename: self.tablename, sqlwhere: "id IN (" + ids.join(",") + ")" }; $http.post(apiurljs.login + "g2app/dataabase/deletBywhere", { 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() } else { sp.dialog(res.message) } }) }); } //头部下滚冻结 $(function () { //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } $(".table-body-left").css("max-height", $(".ibox-content").height() - 69) $(".table-body-right").css("max-height", $(".ibox-content").height() - 54) }, 1) }) }]) function formate(d) { return d > 9 ? d : "0" + d } function scrollTableL() { $(".table-body-right").scrollTop($(".table-body-left").scrollTop()) } function scrollTableR() { $(".table-head-right").scrollLeft($(".table-body-right").scrollLeft()) $(".table-body-left").scrollTop($(".table-body-right").scrollTop()) }