list.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.pageform = sp.getUrlName("pageform");
  13. self.tablename = "SX_TFNZZGZB"
  14. var postCfg = {
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. 'Authorization': "Bearer " + self.get_AccessToken
  18. }
  19. }
  20. self.getCARDID = function () {
  21. var postData = { "userid": self.userId };
  22. $http.post(apiurljs.login + "g2work/user/queryUserinfoAddress", JSON.stringify(postData), postCfg)
  23. .success(function (obj) {
  24. var res = strToJson(s4.decryptData_CBC(obj.data));
  25. if (res.success) {
  26. self.CARDID = res.data.CARDID///身份证号码
  27. if (self.CARDID == "" || self.CARDID == null || self.CARDID == undefined) {
  28. sp.dialog("请先去<strong>个人资料-通讯录信息</strong>中补全身份证号信息!<strong class='sp-color-red'><a onclick='goUrl()'>现在就去</a></strong>")
  29. } else {
  30. self.getHead()
  31. }
  32. }
  33. })
  34. };
  35. self.getHead = function () {
  36. var data = {
  37. tablename: self.tablename,
  38. order: "sortid"
  39. }
  40. $http.post(apiurljs.login + "g2app/richang/queryColumnsData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  41. .success(function (obj) {
  42. var res = strToJson(s4.decryptData_CBC(obj.data))
  43. self.thead = [];
  44. $.each(res.data, function (index, item) {
  45. if (item.code != "ID" && item.code != "ROUTEINFOID" &&
  46. item.code != "SORTID" && item.code != "APPCODE" &&
  47. item.code != "CTIME" && item.code != "RYSF" && item.code != "RYFL" && item.code != "SFZHM" && item.code != "CJGZSJ" && item.code != "ZW") {
  48. self.thead.push({ code: item.code, cname: item.cname, ckind: item.ckind, show: false })
  49. }
  50. })
  51. self.date = sp.currentYear() + "-" + formate(sp.currentMonth())
  52. self.getData()
  53. })
  54. }
  55. self.getCARDID();
  56. self.changeDate = function () {
  57. if (self.date > sp.currentYear() + "-" + formate(sp.currentMonth())) {
  58. $timeout(function () { self.date = sp.currentYear() + "-" + formate(sp.currentMonth()) },1)
  59. }
  60. }
  61. self.changeTB = function (tablename) {
  62. if (self.tablename == tablename) {
  63. return;
  64. } else {
  65. self.tablename = tablename;
  66. self.getHead()
  67. }
  68. }
  69. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  70. self.getData = function () {
  71. self.list = [];
  72. if (self.tablename == "SX_TFWZZGZB") {
  73. var data = {
  74. ffny: self.date,
  75. sfzhm: self.CARDID,
  76. xm: self.userName
  77. }
  78. $http.post(apiurljs.login + "g2app/richang/querytfwzzgzbData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  79. .success(function (obj) {
  80. var res = strToJson(s4.decryptData_CBC(obj.data));
  81. self.canExportExcel = true;
  82. if (res.data == null || res.data == undefined || res.data == "") {
  83. self.noDataTip = 0;
  84. } else {
  85. self.noDataTip = 1;
  86. res.data.forEach(function (item) {
  87. item.DATA.forEach(function (item1) {
  88. self.list.push(item1)
  89. })
  90. });
  91. self.list.forEach(function (item) {
  92. self.thead.forEach(function (item1) {
  93. if (item[item1.code] != "" && item[item1.code] != null && item[item1.code] != undefined) {
  94. item1.show = true;
  95. }
  96. if (item1.ckind == "datetime") {
  97. item[item1.code] = item[item1.code] ? sp.minsToDate("yyyy-MM", item[item1.code]) : "";
  98. }
  99. if (item.NAMETYPE == "合计") {
  100. item.XM = "合计";
  101. //if (item[item1.code] == "" || item[item1.code] == null || item[item1.code] == undefined) {
  102. // item1.show = false;
  103. //}
  104. }
  105. })
  106. })
  107. }
  108. })
  109. } else {
  110. var data = {
  111. tablename: self.tablename,
  112. colums: "*",
  113. order: "ID",
  114. sqlwhere: { XM: self.userName, SFZHM: self.CARDID },
  115. sqlorwhere: "",
  116. sqlinwhere: "",
  117. sqllikewhere: { FFNY: self.date }
  118. };
  119. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  120. .success(function (obj) {
  121. var res = strToJson(s4.decryptData_CBC(obj.data));
  122. self.canExportExcel = true;
  123. if (res.data == null || res.data == undefined || res.data == "") {
  124. self.noDataTip = 0;
  125. } else {
  126. self.noDataTip = 1;
  127. self.list = res.data;
  128. self.list.forEach(function (item) {
  129. self.thead.forEach(function (item1) {
  130. if (item1.ckind == "datetime") {
  131. item[item1.code] = sp.format(item[item1.code]).slice(0, 10)
  132. }
  133. if (item[item1.code] != 0 && item[item1.code] != "" && item[item1.code] != null && item[item1.code] != undefined) {
  134. item1.show = true;
  135. }
  136. //if ((item1.ckind == "decimal" && item[item1.code] == 0) || item[item1.code] == "" || item[item1.code] == null | item[item1.code] == undefined) {
  137. // item1.show = false;
  138. //}
  139. })
  140. })
  141. }
  142. })
  143. }
  144. }
  145. self.YINHANG = function () {
  146. self.yhList = [];
  147. var data = {
  148. cname: "SX_TFWZZGZB",
  149. ffny: self.date,
  150. xm: self.userName
  151. }
  152. $http.post(apiurljs.login + "g2app/richang/queryTFWDataToMan", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  153. .success(function (obj) {
  154. var res = strToJson(s4.decryptData_CBC(obj.data))
  155. self.yhList = res.data;
  156. sp.layer("#YINHANG")
  157. })
  158. }
  159. self.downloadYH = function () {
  160. var title = "统发外个人工资银行表格"
  161. if (self.canExportExcel) {
  162. $('#yh td').attr('t', 's')
  163. var defaultCellStyle = {
  164. font: {
  165. name: 'Times New Roman',
  166. sz: 12,
  167. color: {
  168. rgb: "000000"
  169. },
  170. bold: false, italic: false,
  171. underline: false
  172. },
  173. alignment: {
  174. vertical: "center",
  175. horizontal: "center", indent: 0, wrapText: true
  176. },
  177. border: {
  178. top: {
  179. style: "thin",
  180. color: {
  181. rgb: "000000"
  182. }
  183. },
  184. right: {
  185. style: "thin",
  186. color: {
  187. rgb: "000000"
  188. }
  189. },
  190. bottom: {
  191. style: "thin",
  192. color: {
  193. rgb: "000000"
  194. }
  195. },
  196. left: {
  197. style: "thin",
  198. color: {
  199. rgb: "000000"
  200. }
  201. }
  202. }
  203. };
  204. var cell = { defaultCellStyle: defaultCellStyle };
  205. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#yh'), cell, title)
  206. //设置表格的样式
  207. var wbout = XLSX.write(wb, {
  208. bookType: 'xlsx',
  209. bookSST: false,
  210. type: 'binary',
  211. cellStyles: true,
  212. defaultCellStyle: defaultCellStyle,
  213. showGridLines: false
  214. });
  215. var s2ab = function (s) {
  216. var buf = new ArrayBuffer(s.length);
  217. var view = new Uint8Array(buf);
  218. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  219. return buf;
  220. };
  221. try {
  222. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '统发外个人工资银行表格.xlsx')
  223. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  224. return wbout
  225. } else {
  226. sp.dialog('数据还未加载完成,请稍等...')
  227. }
  228. }
  229. self.printOut = function () {
  230. var title = self.date.split("-")[0] + "年" + self.date.split("-")[1] + "月" + (self.tablename == "SX_TFNZZGZB" ? "统发内工资单" : "统发外工资单");
  231. if (self.canExportExcel) {
  232. $('#printOut td').attr('t', 's')
  233. var defaultCellStyle = {
  234. font: {
  235. name: 'Times New Roman',
  236. sz: 12,
  237. color: {
  238. rgb: "000000"
  239. },
  240. bold: false, italic: false,
  241. underline: false
  242. },
  243. alignment: {
  244. vertical: "center",
  245. horizontal: "center", indent: 0, wrapText: true
  246. },
  247. border: {
  248. top: {
  249. style: "thin",
  250. color: {
  251. rgb: "000000"
  252. }
  253. },
  254. right: {
  255. style: "thin",
  256. color: {
  257. rgb: "000000"
  258. }
  259. },
  260. bottom: {
  261. style: "thin",
  262. color: {
  263. rgb: "000000"
  264. }
  265. },
  266. left: {
  267. style: "thin",
  268. color: {
  269. rgb: "000000"
  270. }
  271. }
  272. }
  273. };
  274. var cell = { defaultCellStyle: defaultCellStyle };
  275. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, title)
  276. //设置表格的样式
  277. var wbout = XLSX.write(wb, {
  278. bookType: 'xlsx',
  279. bookSST: false,
  280. type: 'binary',
  281. cellStyles: true,
  282. defaultCellStyle: defaultCellStyle,
  283. showGridLines: false
  284. });
  285. var s2ab = function (s) {
  286. var buf = new ArrayBuffer(s.length);
  287. var view = new Uint8Array(buf);
  288. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  289. return buf;
  290. };
  291. try {
  292. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), title + '.xlsx')
  293. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  294. return wbout
  295. } else {
  296. sp.dialog('数据还未加载完成,请稍等...')
  297. }
  298. }
  299. }])
  300. function formate(d){
  301. return d > 9 ? d : "0" + d
  302. }
  303. function goUrl() {
  304. window.top.sp.addTabNav('asetNewPersonalData', '个人资料', 'tpk/_asetnew/personalData_phone.html')
  305. sp.dialoghide()
  306. }