list2.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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_TFWZZGZB"
  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" && item.code != "CJGZSJ") {
  34. self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind })
  35. }
  36. })
  37. self.thead_left = self.thead.slice(0, 4)
  38. self.thead_right = self.thead.slice(4)
  39. self.date = sp.currentYear() + "-" + formate(sp.currentMonth())
  40. self.uploadFile = "";
  41. self.getData()
  42. })
  43. }
  44. self.getHead()
  45. self.changeDate = function () {
  46. if (self.date > sp.currentYear() + "-" + formate(sp.currentMonth())) {
  47. $timeout(function () { self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) }, 1)
  48. }
  49. }
  50. self.changeTB = function (tablename) {
  51. if (self.tablename == tablename) {
  52. return;
  53. } else {
  54. self.tablename = tablename;
  55. self.getHead()
  56. }
  57. }
  58. self.setPrintIn = function () {
  59. self.inport = { tablename: "SX_TFWZZGZB", thead: "" }
  60. self.getInportTable()
  61. sp.layer("#importDivPart")
  62. }
  63. self.getInportTable = function () {
  64. var data = {
  65. tablename: self.inport.tablename,
  66. order: "sortid"
  67. }
  68. $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  69. .success(function (obj) {
  70. var res = strToJson(s4.decryptData_CBC(obj.data))
  71. self.inport.thead = [];
  72. $.each(res.data, function (index, item) {
  73. if (item.code != "ID" && item.code != "ROUTEINFOID" &&
  74. item.code != "SORTID" && item.code != "APPCODE" &&
  75. item.code != "CTIME") {
  76. self.inport.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind })
  77. }
  78. })
  79. console.log(self.inport.thead)
  80. })
  81. }
  82. ////导入文件按钮操作事件
  83. self.btnFileChange = function () {
  84. self.excelData = []; ///定义excel中的数组
  85. self.excelHeadData = [];
  86. var X = XLSX;
  87. var XW = {
  88. msg: 'xlsx',
  89. worker: './js/xlsxworker.js'
  90. };
  91. var global_wb;
  92. var process_wb = (function () {
  93. var OUT = document.getElementById('out');
  94. var to_json = function to_json(workbook) {
  95. var result = {};
  96. workbook.SheetNames.forEach(function (sheetName) {
  97. var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName], { header: 1 });
  98. if (roa.length) result[sheetName] = roa;
  99. });
  100. for (var i in result) {
  101. var sheet = i;
  102. }
  103. //console.log(result[sheet]);
  104. self.excelData = result[sheet]; /////声明excel中的数据变量
  105. //console.log(JSON.stringify(self.excelData));
  106. self.excelHeadData = self.excelData[0]; ////excel的头部数据
  107. //console.log(self.excelHeadData);
  108. return JSON.stringify(result[sheet], 2, 2);
  109. };
  110. return function process_wb(wb) {
  111. global_wb = wb;
  112. var output = to_json(wb);
  113. if (OUT.innerText === undefined) OUT.textContent = output;
  114. else OUT.innerText = output;
  115. //console.log(self.excelData);
  116. if (typeof console !== 'undefined') console.log("output", new Date());
  117. };
  118. })();
  119. var setfmt = window.setfmt = function setfmt() { if (global_wb) process_wb(global_wb); };
  120. var do_file = (function () {
  121. var rABS = typeof FileReader !== "undefined" && (FileReader.prototype || {}).readAsBinaryString;
  122. var domrabs = document.getElementsByName("userabs")[0];
  123. if (!rABS) domrabs.disabled = !(domrabs.checked = false);
  124. var use_worker = typeof Worker !== 'undefined';
  125. var domwork = document.getElementsByName("useworker")[0];
  126. if (!use_worker) domwork.disabled = !(domwork.checked = false);
  127. var xw = function xw(data, cb) {
  128. var worker = new Worker(XW.worker);
  129. worker.onmessage = function (e) {
  130. switch (e.data.t) {
  131. case 'ready': break;
  132. case 'e': console.error(e.data.d); break;
  133. case XW.msg: cb(JSON.parse(e.data.d)); break;
  134. }
  135. };
  136. worker.postMessage({ d: data, b: rABS ? 'binary' : 'array' });
  137. };
  138. return function do_file(files) {
  139. rABS = domrabs.checked;
  140. use_worker = domwork.checked;
  141. var f = files[0];
  142. $timeout(function () {
  143. self.uploadFile = f.name;
  144. },1)
  145. var reader = new FileReader();
  146. reader.onload = function (e) {
  147. if (typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
  148. var data = e.target.result;
  149. if (!rABS) data = new Uint8Array(data);
  150. if (use_worker) xw(data, process_wb);
  151. else process_wb(X.read(data, { type: rABS ? 'binary' : 'array' }));
  152. };
  153. if (rABS) reader.readAsBinaryString(f);
  154. else reader.readAsArrayBuffer(f);
  155. };
  156. })();
  157. (function () {
  158. var xlfile = document.getElementById('xlfile');
  159. if (!xlfile.addEventListener) return;
  160. function handleFile(e) {
  161. do_file(e.target.files);
  162. }
  163. xlfile.addEventListener('change', handleFile, false);
  164. })();
  165. var _gaq = _gaq || [];
  166. _gaq.push(['_setAccount', 'UA-36810333-1']);
  167. _gaq.push(['_trackPageview']);
  168. (function () {
  169. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  170. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  171. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  172. })();
  173. };
  174. self.btnFileChange();
  175. self.printIn = function () {
  176. if (self.uploadFile == "") {
  177. sp.dialog("请先上传文件");
  178. } else {
  179. self.getImportData = self.excelData;
  180. sp.layer("#importDivPart")
  181. }
  182. }
  183. /////确定导入数据
  184. self.btnTrueImportData = function () {
  185. //$("#btnTrueImportData").attr("disabled", "disabled");
  186. //$("#btnTrueImportData span").text("正在导入中...");
  187. var loc = "";
  188. $("#table_excelHead table tbody tr").each(function () {
  189. var getcode = $("td:eq(0)", this).attr("data-code");
  190. var getcol = $("td:eq(1) select", this).val() == "? undefined:undefined ?" ? "''" : $("td:eq(1) select", this).val();
  191. var getckind = $("td:eq(0)", this).attr("data-ckind");
  192. var loastr = '{"tcode":"' + getcode + '","excelCol":"' + getcol + '","ckind":"' + getckind + '"},';
  193. loc += loastr;
  194. });
  195. loc = "[" + loc.substring(0, loc.length - 1) + "]";
  196. var loc1 = JSON.parse(loc.replace(/\n/g, ""));
  197. var num = 0;
  198. self.excelData1 = []
  199. for (var i = 0; i < self.excelData.length; i++) {
  200. self.excelData1[i] = [];
  201. if (self.excelData[i].length != 0) {
  202. for (var j = 0; j < loc1.length; j++) {
  203. for (var x = 0; x < self.excelHeadData.length; x++) {
  204. if (loc1[j].excelCol == self.excelHeadData[x]) {
  205. if (loc1[j].ckind == "datetime" && i > 0) {
  206. if (loc1[j].tcode == "FFNY" && self.excelData[i][x] != undefined) {
  207. self.excelData1[i].push(self.excelData[i][x] + "01")
  208. } else {
  209. //self.excelData1[i].push(sp.format(self.excelData[i][x]))
  210. self.excelData1[i].push(self.excelData[i][x])
  211. }
  212. } else {
  213. self.excelData1[i].push(self.excelData[i][x])
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. var data = {
  221. tablename: self.inport.tablename,
  222. headarry: loc1,
  223. arr: JSON.stringify(self.excelData1),
  224. startdata:1
  225. }
  226. console.log(data)
  227. $http.post(apiurljs.login + "g2app/richang/impGongZiData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  228. .success(function (obj) {
  229. var res = strToJson(s4.decryptData_CBC(obj.data));
  230. sp.layerhide()
  231. if (res.success == true) {
  232. sp.dialog("导入成功");
  233. self.getData()
  234. $("#xlfile").val("");
  235. self.uploadFile = "";
  236. $timeout(function () {
  237. sp.dialoghide()
  238. }, 1000)
  239. } else {
  240. sp.dialog(res.message);
  241. }
  242. });
  243. };
  244. self.printOut = function () {
  245. var title = self.date.split("-")[0] + "年" + self.date.split("-")[1] + "月" + (self.tablename == "SX_TFWZZGZB" ? "统发外在职工资单" : self.tablename == "SX_TFWTXGZB" ? "统发外退休工资单" : "统发外离休工资单")
  246. if (self.canExportExcel) {
  247. $('#printOut td').attr('t', 's')
  248. var defaultCellStyle = {
  249. font: {
  250. name: 'Times New Roman',
  251. sz: 12,
  252. color: {
  253. rgb: "000000"
  254. },
  255. bold: false, italic: false,
  256. underline: false
  257. },
  258. alignment: {
  259. vertical: "center",
  260. horizontal: "center", indent: 0, wrapText: true
  261. },
  262. border: {
  263. top: {
  264. style: "thin",
  265. color: {
  266. rgb: "000000"
  267. }
  268. },
  269. right: {
  270. style: "thin",
  271. color: {
  272. rgb: "000000"
  273. }
  274. },
  275. bottom: {
  276. style: "thin",
  277. color: {
  278. rgb: "000000"
  279. }
  280. },
  281. left: {
  282. style: "thin",
  283. color: {
  284. rgb: "000000"
  285. }
  286. }
  287. }
  288. };
  289. var cell = { defaultCellStyle: defaultCellStyle };
  290. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, title)
  291. //设置表格的样式
  292. var wbout = XLSX.write(wb, {
  293. bookType: 'xlsx',
  294. bookSST: false,
  295. type: 'binary',
  296. cellStyles: true,
  297. defaultCellStyle: defaultCellStyle,
  298. showGridLines: false
  299. });
  300. var s2ab = function (s) {
  301. var buf = new ArrayBuffer(s.length);
  302. var view = new Uint8Array(buf);
  303. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  304. return buf;
  305. };
  306. try {
  307. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), title + '.xlsx')
  308. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  309. return wbout
  310. } else {
  311. sp.dialog('数据还未加载完成,请稍等...')
  312. }
  313. }
  314. self.YINHANG = function () {
  315. self.yhList = [];
  316. var data = {
  317. cname: "SX_TFWZZGZB",
  318. ffny: self.date
  319. }
  320. $http.post(apiurljs.login + "g2app/richang/queryDataToBank", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  321. .success(function (obj) {
  322. var res = strToJson(s4.decryptData_CBC(obj.data))
  323. self.yhList = res.data;
  324. sp.layer("#YINHANG")
  325. })
  326. }
  327. self.downloadYH = function () {
  328. var title = "统发外在职工资银行表格"
  329. if (self.canExportExcel) {
  330. $('#yh td').attr('t', 's')
  331. var defaultCellStyle = {
  332. font: {
  333. name: 'Times New Roman',
  334. sz: 12,
  335. color: {
  336. rgb: "000000"
  337. },
  338. bold: false, italic: false,
  339. underline: false
  340. },
  341. alignment: {
  342. vertical: "center",
  343. horizontal: "center", indent: 0, wrapText: true
  344. },
  345. border: {
  346. top: {
  347. style: "thin",
  348. color: {
  349. rgb: "000000"
  350. }
  351. },
  352. right: {
  353. style: "thin",
  354. color: {
  355. rgb: "000000"
  356. }
  357. },
  358. bottom: {
  359. style: "thin",
  360. color: {
  361. rgb: "000000"
  362. }
  363. },
  364. left: {
  365. style: "thin",
  366. color: {
  367. rgb: "000000"
  368. }
  369. }
  370. }
  371. };
  372. var cell = { defaultCellStyle: defaultCellStyle };
  373. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#yh'), cell, title)
  374. //设置表格的样式
  375. var wbout = XLSX.write(wb, {
  376. bookType: 'xlsx',
  377. bookSST: false,
  378. type: 'binary',
  379. cellStyles: true,
  380. defaultCellStyle: defaultCellStyle,
  381. showGridLines: false
  382. });
  383. var s2ab = function (s) {
  384. var buf = new ArrayBuffer(s.length);
  385. var view = new Uint8Array(buf);
  386. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  387. return buf;
  388. };
  389. try {
  390. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '统发外在职工资银行表格.xlsx')
  391. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  392. return wbout
  393. } else {
  394. sp.dialog('数据还未加载完成,请稍等...')
  395. }
  396. }
  397. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  398. self.getData = function () {
  399. self.list = [];
  400. self.checkedAll = false;
  401. self.loading = true;
  402. if (self.tablename == "SX_TFWZZGZB") {
  403. var data = {
  404. ffny: self.date,
  405. sfzhm: "",
  406. xm: ""
  407. }
  408. $http.post(apiurljs.login + "g2app/richang/querytfwzzgzbDataT", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  409. .success(function (obj) {
  410. //var res = strToJson(s4.decryptData_CBC(obj.data));
  411. var res = obj.data;
  412. self.canExportExcel = true;
  413. self.loading = false;
  414. //if (res.data == null || res.data == undefined || res.data == "") {
  415. if (res== null || res== undefined || res.length==0) {
  416. self.noDataTip = 0;
  417. } else {
  418. self.noDataTip = 1;
  419. //res.data.forEach(function (item) {
  420. res.forEach(function (item) {
  421. item.DATA.forEach(function (item1) {
  422. self.list.push(item1)
  423. })
  424. });
  425. self.list.forEach(function (item) {
  426. item.checked = false;
  427. self.thead.forEach(function (item1) {
  428. if (item1.ckind == "datetime") {
  429. item[item1.code] = item[item1.code] ? sp.minsToDate("yyyy-MM", item[item1.code]) : "";
  430. }
  431. if (item.NAMETYPE == "合计") {
  432. item.XM = "合计";
  433. }
  434. })
  435. })
  436. }
  437. })
  438. } else {
  439. self.list = [];
  440. var data = {
  441. tablename: self.tablename,
  442. colums: "*",
  443. order: "ID",
  444. sqlwhere: "",
  445. sqlorwhere: "",
  446. sqlinwhere: "",
  447. sqllikewhere: { FFNY: self.date }
  448. };
  449. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  450. .success(function (obj) {
  451. var res = strToJson(s4.decryptData_CBC(obj.data));
  452. self.canExportExcel = true;
  453. self.loading = false;
  454. if (res.data == null || res.data == undefined || res.data == "") {
  455. self.noDataTip = 0;
  456. } else {
  457. self.noDataTip = 1;
  458. self.list = res.data;
  459. self.list.forEach(function (item) {
  460. item.checked = false;
  461. self.thead.forEach(function (item1) {
  462. if (item1.ckind == "datetime") {
  463. item[item1.code] = sp.format(item[item1.code]).slice(0, 10)
  464. }
  465. })
  466. })
  467. }
  468. })
  469. }
  470. }
  471. self.checkAll = function () {
  472. //self.checkedAll = !self.checkedAll;
  473. self.list.forEach(function (item) {
  474. item.checked = self.checkedAll
  475. })
  476. }
  477. self.checkItem = function (obj) {
  478. //obj.checked = !obj.checked;
  479. var n = 0;
  480. self.list.forEach(function (item) {
  481. if (item.checked == true) {
  482. n++
  483. }
  484. })
  485. self.checkedAll = n == self.list.length;
  486. }
  487. self.btnDelete = function () {
  488. var ids = [];
  489. self.list.forEach(function (item) {
  490. if (item.checked == true) {
  491. ids.push(item.ID)
  492. }
  493. })
  494. if (ids.length == 0) {
  495. sp.dialog("请选择要删除的数据!")
  496. return;
  497. }
  498. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  499. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,确定要删除吗</div>";
  500. 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>";
  501. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  502. sp.openCenter(".sp-dialog");
  503. ///取消按钮
  504. $('.sp-closeDialog').click(function (event) {
  505. sp.closeCenter(".sp-dialog");
  506. event.preventDefault();
  507. event.stopPropagation();
  508. });
  509. //post消息的id
  510. $("#delDataTrue").click(function () {
  511. var data = {
  512. tablename: self.tablename,
  513. sqlwhere: "id IN (" + ids.join(",") + ")"
  514. };
  515. $http.post(apiurljs.login + "g2app/dataabase/deletBywhere", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  516. .success(function (obj) {
  517. var res = strToJson(s4.decryptData_CBC(obj.data));
  518. sp.dialoghide()
  519. if (res.success == true) {
  520. self.getData()
  521. } else {
  522. sp.dialog(res.message)
  523. }
  524. })
  525. });
  526. }
  527. //头部下滚冻结
  528. $(function () {
  529. //页面高度撑满
  530. setTimeout(function () {
  531. if ($(".ibox-content").height() < $(window).height() - 31) {
  532. $(".ibox-content").css("height", $(window).height() - 31)
  533. }
  534. $(".table-body-left").css("max-height", $(".ibox-content").height() - 69)
  535. $(".table-body-right").css("max-height", $(".ibox-content").height() - 54)
  536. }, 1)
  537. })
  538. }])
  539. function formate(d) {
  540. return d > 9 ? d : "0" + d
  541. }
  542. function scrollTableL() {
  543. $(".table-body-right").scrollTop($(".table-body-left").scrollTop())
  544. }
  545. function scrollTableR() {
  546. $(".table-head-right").scrollLeft($(".table-body-right").scrollLeft())
  547. $(".table-body-left").scrollTop($(".table-body-right").scrollTop())
  548. }