'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_TFNZZGZB" 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.code1 = item.code; if (item.code == "FFNY") { item.code = "FFNY_MM" } if (item.code == "CJGZSJ") { item.code = "CJGZSJ_MM" } self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind, code1: item.code1 }) } }) 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.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[4]; ////excel的头部数据 self.excelHeadData[0] = self.excelData[3][0]; self.excelHeadData[1] = self.excelData[3][1]; self.excelHeadData[2] = self.excelData[3][2]; self.excelHeadData[3] = self.excelData[3][3]; 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) { //console.log(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.tablename, headarry: loc1, arr: JSON.stringify(self.excelData1), startdata:5 } $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) { if (res.data > 0) { sp.dialog("导入成功"); self.getData() $("#xlfile").val(""); self.uploadFile = ""; $timeout(function () { sp.dialoghide() }, 1000) } else { sp.dialog("导入失败!") } } else { sp.dialog(res.message); } }) .error(function (obj) { sp.layerhide() sp.dialog("导入失败!") }) }; self.noDataTip = 1;//没有数据时赋变量为0,先默认为1 self.getData = function () { self.loading = true; self.list = []; self.checkedAll = false; var data = { tablename: self.tablename, colums: "*,to_char(FFNY,'yyyy-MM') as FFNY_MM,to_char(CJGZSJ,'yyyy-MM-dd') as CJGZSJ_MM", order: "ID", sqlwhere: "", sqlorwhere: "", sqlinwhere: "", sqllikewhere: { FFNY: self.date } }; $http.post(apiurljs.login + "g2app/dataabase/queryDataByColT", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (res) { //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" && item1.code != "FFNY_MM") { 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: "SX_TFNZZGZB", 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()) }