list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 })
  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 (item1.ckind == "datetime") {
  94. item[item1.code] = item[item1.code] ? sp.minsToDate("yyyy-MM", item[item1.code]) : "";
  95. }
  96. if (item.NAMETYPE == "合计") {
  97. item.XM = "合计";
  98. }
  99. })
  100. })
  101. }
  102. })
  103. } else {
  104. var data = {
  105. tablename: self.tablename,
  106. colums: "*",
  107. order: "ID",
  108. sqlwhere: { XM: self.userName, SFZHM: self.CARDID },
  109. sqlorwhere: "",
  110. sqlinwhere: "",
  111. sqllikewhere: { FFNY: self.date }
  112. };
  113. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  114. .success(function (obj) {
  115. var res = strToJson(s4.decryptData_CBC(obj.data));
  116. self.canExportExcel = true;
  117. if (res.data == null || res.data == undefined || res.data == "") {
  118. self.noDataTip = 0;
  119. } else {
  120. self.noDataTip = 1;
  121. self.list = res.data;
  122. self.list.forEach(function (item) {
  123. self.thead.forEach(function (item1) {
  124. if (item1.ckind == "datetime") {
  125. item[item1.code] = sp.format(item[item1.code]).slice(0, 10)
  126. }
  127. })
  128. })
  129. }
  130. })
  131. }
  132. }
  133. self.YINHANG = function () {
  134. self.yhList = [];
  135. var data = {
  136. cname: "SX_TFWZZGZB",
  137. ffny: self.date,
  138. xm: self.userName
  139. }
  140. $http.post(apiurljs.login + "g2app/richang/queryTFWDataToMan", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  141. .success(function (obj) {
  142. var res = strToJson(s4.decryptData_CBC(obj.data))
  143. self.yhList = res.data;
  144. sp.layer("#YINHANG")
  145. })
  146. }
  147. self.downloadYH = function () {
  148. var title = "统发外个人工资银行表格"
  149. if (self.canExportExcel) {
  150. $('#yh td').attr('t', 's')
  151. var defaultCellStyle = {
  152. font: {
  153. name: 'Times New Roman',
  154. sz: 12,
  155. color: {
  156. rgb: "000000"
  157. },
  158. bold: false, italic: false,
  159. underline: false
  160. },
  161. alignment: {
  162. vertical: "center",
  163. horizontal: "center", indent: 0, wrapText: true
  164. },
  165. border: {
  166. top: {
  167. style: "thin",
  168. color: {
  169. rgb: "000000"
  170. }
  171. },
  172. right: {
  173. style: "thin",
  174. color: {
  175. rgb: "000000"
  176. }
  177. },
  178. bottom: {
  179. style: "thin",
  180. color: {
  181. rgb: "000000"
  182. }
  183. },
  184. left: {
  185. style: "thin",
  186. color: {
  187. rgb: "000000"
  188. }
  189. }
  190. }
  191. };
  192. var cell = { defaultCellStyle: defaultCellStyle };
  193. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#yh'), cell, title)
  194. //设置表格的样式
  195. var wbout = XLSX.write(wb, {
  196. bookType: 'xlsx',
  197. bookSST: false,
  198. type: 'binary',
  199. cellStyles: true,
  200. defaultCellStyle: defaultCellStyle,
  201. showGridLines: false
  202. });
  203. var s2ab = function (s) {
  204. var buf = new ArrayBuffer(s.length);
  205. var view = new Uint8Array(buf);
  206. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  207. return buf;
  208. };
  209. try {
  210. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '统发外个人工资银行表格.xlsx')
  211. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  212. return wbout
  213. } else {
  214. sp.dialog('数据还未加载完成,请稍等...')
  215. }
  216. }
  217. self.printOut = function () {
  218. var title = self.date.split("-")[0] + "年" + self.date.split("-")[1] + "月" + (self.tablename == "SX_TFNZZGZB" ? "统发内工资单" : "统发外工资单");
  219. if (self.canExportExcel) {
  220. $('#printOut td').attr('t', 's')
  221. var defaultCellStyle = {
  222. font: {
  223. name: 'Times New Roman',
  224. sz: 12,
  225. color: {
  226. rgb: "000000"
  227. },
  228. bold: false, italic: false,
  229. underline: false
  230. },
  231. alignment: {
  232. vertical: "center",
  233. horizontal: "center", indent: 0, wrapText: true
  234. },
  235. border: {
  236. top: {
  237. style: "thin",
  238. color: {
  239. rgb: "000000"
  240. }
  241. },
  242. right: {
  243. style: "thin",
  244. color: {
  245. rgb: "000000"
  246. }
  247. },
  248. bottom: {
  249. style: "thin",
  250. color: {
  251. rgb: "000000"
  252. }
  253. },
  254. left: {
  255. style: "thin",
  256. color: {
  257. rgb: "000000"
  258. }
  259. }
  260. }
  261. };
  262. var cell = { defaultCellStyle: defaultCellStyle };
  263. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, title)
  264. //设置表格的样式
  265. var wbout = XLSX.write(wb, {
  266. bookType: 'xlsx',
  267. bookSST: false,
  268. type: 'binary',
  269. cellStyles: true,
  270. defaultCellStyle: defaultCellStyle,
  271. showGridLines: false
  272. });
  273. var s2ab = function (s) {
  274. var buf = new ArrayBuffer(s.length);
  275. var view = new Uint8Array(buf);
  276. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  277. return buf;
  278. };
  279. try {
  280. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), title + '.xlsx')
  281. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  282. return wbout
  283. } else {
  284. sp.dialog('数据还未加载完成,请稍等...')
  285. }
  286. }
  287. }])
  288. function formate(d){
  289. return d > 9 ? d : "0" + d
  290. }
  291. function goUrl() {
  292. window.top.sp.addTabNav('asetNewPersonalData', '个人资料', 'tpk/_asetnew/personalData_phone.html')
  293. sp.dialoghide()
  294. }