list1.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("listCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  6. var self = this;
  7. var s4 = new SM4Util();
  8. self.userId = $.cookie("GlWorkPlatform-userid");
  9. self.userName = $.cookie("GlWorkPlatform-chineseName");
  10. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  11. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  12. self.tablename = "SX_TFNZZGZB"
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. self.loading = false;
  20. self.getHead = function () {
  21. self.loading = true;
  22. var data = {
  23. tablename: self.tablename,
  24. order: "sortid"
  25. }
  26. $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  27. .success(function (obj) {
  28. var res = strToJson(s4.decryptData_CBC(obj.data))
  29. self.thead = [];
  30. $.each(res.data, function (index, item) {
  31. if (item.code != "ID" && item.code != "ROUTEINFOID" &&
  32. item.code != "SORTID" && item.code != "APPCODE" &&
  33. item.code != "CTIME") {
  34. item.code1 = item.code;
  35. if (item.code == "FFNY") {
  36. item.code = "FFNY_MM"
  37. }
  38. if (item.code == "CJGZSJ") {
  39. item.code = "CJGZSJ_MM"
  40. }
  41. self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind, code1: item.code1 })
  42. }
  43. })
  44. self.thead_left = self.thead.slice(0, 4)
  45. self.thead_right = self.thead.slice(4)
  46. self.date = sp.currentYear() + "-" + formate(sp.currentMonth())
  47. self.uploadFile = "";
  48. self.getData()
  49. })
  50. }
  51. self.getHead()
  52. self.changeDate = function () {
  53. if (self.date > sp.currentYear() + "-" + formate(sp.currentMonth())) {
  54. $timeout(function () { self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) }, 1)
  55. }
  56. }
  57. ////导入文件按钮操作事件
  58. self.btnFileChange = function () {
  59. self.excelData = []; ///定义excel中的数组
  60. self.excelHeadData = [];
  61. var X = XLSX;
  62. var XW = {
  63. msg: 'xlsx',
  64. worker: './js/xlsxworker.js'
  65. };
  66. var global_wb;
  67. var process_wb = (function () {
  68. var OUT = document.getElementById('out');
  69. var to_json = function to_json(workbook) {
  70. var result = {};
  71. workbook.SheetNames.forEach(function (sheetName) {
  72. var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName], { header: 1 });
  73. if (roa.length) result[sheetName] = roa;
  74. });
  75. for (var i in result) {
  76. var sheet = i;
  77. }
  78. //console.log(result[sheet]);
  79. self.excelData = result[sheet]; /////声明excel中的数据变量
  80. //console.log(JSON.stringify(self.excelData));
  81. self.excelHeadData = self.excelData[4]; ////excel的头部数据
  82. self.excelHeadData[0] = self.excelData[3][0];
  83. self.excelHeadData[1] = self.excelData[3][1];
  84. self.excelHeadData[2] = self.excelData[3][2];
  85. self.excelHeadData[3] = self.excelData[3][3];
  86. return JSON.stringify(result[sheet], 2, 2);
  87. };
  88. return function process_wb(wb) {
  89. global_wb = wb;
  90. var output = to_json(wb);
  91. if (OUT.innerText === undefined) OUT.textContent = output;
  92. else OUT.innerText = output;
  93. //console.log(self.excelData);
  94. if (typeof console !== 'undefined') console.log("output", new Date());
  95. };
  96. })();
  97. var setfmt = window.setfmt = function setfmt() { if (global_wb) process_wb(global_wb); };
  98. var do_file = (function () {
  99. var rABS = typeof FileReader !== "undefined" && (FileReader.prototype || {}).readAsBinaryString;
  100. var domrabs = document.getElementsByName("userabs")[0];
  101. if (!rABS) domrabs.disabled = !(domrabs.checked = false);
  102. var use_worker = typeof Worker !== 'undefined';
  103. var domwork = document.getElementsByName("useworker")[0];
  104. if (!use_worker) domwork.disabled = !(domwork.checked = false);
  105. var xw = function xw(data, cb) {
  106. var worker = new Worker(XW.worker);
  107. worker.onmessage = function (e) {
  108. switch (e.data.t) {
  109. case 'ready': break;
  110. case 'e': console.error(e.data.d); break;
  111. case XW.msg: cb(JSON.parse(e.data.d)); break;
  112. }
  113. };
  114. worker.postMessage({ d: data, b: rABS ? 'binary' : 'array' });
  115. };
  116. return function do_file(files) {
  117. //console.log(files)
  118. rABS = domrabs.checked;
  119. use_worker = domwork.checked;
  120. var f = files[0];
  121. $timeout(function () {
  122. self.uploadFile = f.name;
  123. },1)
  124. var reader = new FileReader();
  125. reader.onload = function (e) {
  126. if (typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
  127. var data = e.target.result;
  128. if (!rABS) data = new Uint8Array(data);
  129. if (use_worker) xw(data, process_wb);
  130. else process_wb(X.read(data, { type: rABS ? 'binary' : 'array' }));
  131. };
  132. if (rABS) reader.readAsBinaryString(f);
  133. else reader.readAsArrayBuffer(f);
  134. };
  135. })();
  136. (function () {
  137. var xlfile = document.getElementById('xlfile');
  138. if (!xlfile.addEventListener) return;
  139. function handleFile(e) {
  140. do_file(e.target.files);
  141. }
  142. xlfile.addEventListener('change', handleFile, false);
  143. })();
  144. var _gaq = _gaq || [];
  145. _gaq.push(['_setAccount', 'UA-36810333-1']);
  146. _gaq.push(['_trackPageview']);
  147. (function () {
  148. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  149. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  150. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  151. })();
  152. };
  153. self.btnFileChange();
  154. self.printIn = function () {
  155. if (self.uploadFile == "") {
  156. sp.dialog("请先上传文件");
  157. } else {
  158. self.getImportData = self.excelData;
  159. sp.layer("#importDivPart")
  160. }
  161. }
  162. /////确定导入数据
  163. self.btnTrueImportData = function () {
  164. //$("#btnTrueImportData").attr("disabled", "disabled");
  165. //$("#btnTrueImportData span").text("正在导入中...");
  166. var loc = "";
  167. $("#table_excelHead table tbody tr").each(function () {
  168. var getcode = $("td:eq(0)", this).attr("data-code");
  169. var getcol = $("td:eq(1) select", this).val() == "? undefined:undefined ?" ? "''" : $("td:eq(1) select", this).val();
  170. var getckind = $("td:eq(0)", this).attr("data-ckind");
  171. var loastr = '{"tcode":"' + getcode + '","excelCol":"' + getcol + '","ckind":"' + getckind + '"},';
  172. loc += loastr;
  173. });
  174. loc = "[" + loc.substring(0, loc.length - 1) + "]";
  175. var loc1 = JSON.parse(loc.replace(/\n/g, ""));
  176. var num = 0;
  177. self.excelData1 = []
  178. for (var i = 0; i < self.excelData.length; i++) {
  179. self.excelData1[i] = [];
  180. if (self.excelData[i].length != 0) {
  181. for (var j = 0; j < loc1.length; j++) {
  182. for (var x = 0; x < self.excelHeadData.length; x++) {
  183. if (loc1[j].excelCol == self.excelHeadData[x]) {
  184. if (loc1[j].ckind == "datetime" && i > 0) {
  185. if (loc1[j].tcode == "FFNY" && self.excelData[i][x] != undefined) {
  186. self.excelData1[i].push(self.excelData[i][x] + "01")
  187. } else {
  188. //self.excelData1[i].push(sp.format(self.excelData[i][x]))
  189. self.excelData1[i].push(self.excelData[i][x])
  190. }
  191. } else {
  192. self.excelData1[i].push(self.excelData[i][x])
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. var data = {
  200. tablename: self.tablename,
  201. headarry: loc1,
  202. arr: JSON.stringify(self.excelData1),
  203. startdata:5
  204. }
  205. $http.post(apiurljs.login + "g2app/richang/impGongZiData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  206. .success(function (obj) {
  207. var res = strToJson(s4.decryptData_CBC(obj.data));
  208. sp.layerhide()
  209. if (res.success == true) {
  210. if (res.data > 0) {
  211. sp.dialog("导入成功");
  212. self.getData()
  213. $("#xlfile").val("");
  214. self.uploadFile = "";
  215. $timeout(function () {
  216. sp.dialoghide()
  217. }, 1000)
  218. } else {
  219. sp.dialog("导入失败!")
  220. }
  221. } else {
  222. sp.dialog(res.message);
  223. }
  224. })
  225. .error(function (obj) {
  226. sp.layerhide()
  227. sp.dialog("导入失败!")
  228. })
  229. };
  230. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  231. self.getData = function () {
  232. self.loading = true;
  233. self.list = [];
  234. self.checkedAll = false;
  235. var data = {
  236. tablename: self.tablename,
  237. colums: "*,to_char(FFNY,'yyyy-MM') as FFNY_MM,to_char(CJGZSJ,'yyyy-MM-dd') as CJGZSJ_MM",
  238. order: "ID",
  239. sqlwhere: "",
  240. sqlorwhere: "",
  241. sqlinwhere: "",
  242. sqllikewhere: { FFNY: self.date }
  243. };
  244. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColT", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  245. .success(function (res) {
  246. //var res = strToJson(s4.decryptData_CBC(obj.data));
  247. self.canExportExcel = true;
  248. self.loading = false;
  249. if (res.data == null || res.data == undefined || res.data == "") {
  250. self.noDataTip = 0;
  251. } else {
  252. self.noDataTip = 1;
  253. self.list = res.data;
  254. self.list.forEach(function (item) {
  255. item.checked = false;
  256. self.thead.forEach(function (item1) {
  257. if (item1.ckind == "datetime" && item1.code != "FFNY_MM") {
  258. item[item1.code] = sp.format(item[item1.code]).slice(0, 10)
  259. }
  260. })
  261. })
  262. }
  263. })
  264. }
  265. self.checkAll = function () {
  266. //self.checkedAll = !self.checkedAll;
  267. self.list.forEach(function (item) {
  268. item.checked = self.checkedAll
  269. })
  270. }
  271. self.checkItem = function (obj) {
  272. //obj.checked = !obj.checked;
  273. var n = 0;
  274. self.list.forEach(function (item) {
  275. if (item.checked == true) {
  276. n++
  277. }
  278. })
  279. self.checkedAll = n == self.list.length;
  280. }
  281. self.btnDelete = function () {
  282. var ids = [];
  283. self.list.forEach(function (item) {
  284. if (item.checked == true) {
  285. ids.push(item.ID)
  286. }
  287. })
  288. if (ids.length == 0) {
  289. sp.dialog("请选择要删除的数据!")
  290. return;
  291. }
  292. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  293. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,确定要删除吗</div>";
  294. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='delDataTrue' type='button' value='确 定' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  295. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  296. sp.openCenter(".sp-dialog");
  297. ///取消按钮
  298. $('.sp-closeDialog').click(function (event) {
  299. sp.closeCenter(".sp-dialog");
  300. event.preventDefault();
  301. event.stopPropagation();
  302. });
  303. //post消息的id
  304. $("#delDataTrue").click(function () {
  305. var data = {
  306. tablename: "SX_TFNZZGZB",
  307. sqlwhere: "id IN (" + ids.join(",") + ")"
  308. };
  309. $http.post(apiurljs.login + "g2app/dataabase/deletBywhere", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  310. .success(function (obj) {
  311. var res = strToJson(s4.decryptData_CBC(obj.data));
  312. sp.dialoghide()
  313. if (res.success == true) {
  314. self.getData()
  315. } else {
  316. sp.dialog(res.message)
  317. }
  318. })
  319. });
  320. }
  321. //头部下滚冻结
  322. $(function () {
  323. //页面高度撑满
  324. setTimeout(function () {
  325. if ($(".ibox-content").height() < $(window).height() - 31) {
  326. $(".ibox-content").css("height", $(window).height() - 31)
  327. }
  328. $(".table-body-left").css("max-height", $(".ibox-content").height() - 69)
  329. $(".table-body-right").css("max-height", $(".ibox-content").height() - 54)
  330. }, 1)
  331. })
  332. }])
  333. function formate(d) {
  334. return d > 9 ? d : "0" + d
  335. }
  336. function scrollTableL() {
  337. $(".table-body-right").scrollTop($(".table-body-left").scrollTop())
  338. }
  339. function scrollTableR() {
  340. $(".table-head-right").scrollLeft($(".table-body-right").scrollLeft())
  341. $(".table-body-left").scrollTop($(".table-body-right").scrollTop())
  342. }