total.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("totalCtrl", ["$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.dateParam = sp.getUrlName("date");
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. self.loading = false;
  20. self.search = self.dateParam == "" ? { DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end } : { DATE1: self.dateParam, DATE2: self.dateParam }
  21. self.getData = function () {
  22. self.list = [];
  23. self.loading = false;
  24. var data = {
  25. tablename: "SX_YZAPTZ",
  26. colums: "*,TO_CHAR(YZAPDATE,'MM-dd')as YZAPDATE1",
  27. order: "YZAPDATE ASC,CTIME ASC,LDSORTID ASC,CNAME ASC",
  28. //sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59' and USERID='" + self.userId + "'"
  29. sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59'"
  30. }
  31. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColStr", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  32. .success(function (obj) {
  33. var res = strToJson(s4.decryptData_CBC(obj.data));
  34. self.loading = false;
  35. self.addFlag = false;
  36. self.editFlag = false;
  37. self.addList = [];
  38. self.list = res.data;
  39. self.list.forEach(function (item) {
  40. item.CTIME1 = item.CTIME.slice(11, 16);
  41. item.CNAME = item.CNAME == "null" ? "" : item.CNAME
  42. item.ATTENDANCESCOPE = item.ATTENDANCESCOPE == "null" ? "" : item.ATTENDANCESCOPE
  43. item.ADDR = item.ADDR == "null" ? "" : item.ADDR
  44. item.TIMEPERIOD1 = item.TIMEPERIOD;
  45. item.CTIME2 = item.CTIME1;
  46. item.CNAME1 = item.CNAME;
  47. item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE;
  48. item.ADDR1 = item.ADDR;
  49. })
  50. })
  51. }
  52. self.getData();
  53. self.openLayer = function () {
  54. sp.layer("#Search")
  55. }
  56. self.doSearch = function () {
  57. sp.layerhide()
  58. if (self.search.DATE1 == "" || self.search.DATE2 == "") {
  59. sp.dialog("时间为可为空!");
  60. return
  61. }
  62. $.cookie("GlWorkPlatform-yzaptotal", JSON.stringify(self.search), { path: '/', expires: 1 });
  63. self.getData();
  64. }
  65. self.cancal = function () {
  66. self.search = {
  67. DATE1: sp.getWeekNumber(new Date()).begin,
  68. DATE2: sp.getWeekNumber(new Date()).end
  69. }
  70. $.cookie("GlWorkPlatform-yzaptotal", null, { path: '/', expires: 1 });
  71. self.getData();
  72. sp.layerhide()
  73. }
  74. self.refresh = function () {
  75. self.getData();
  76. }
  77. self.printOut = function () {
  78. if (self.canExportExcel) {
  79. $('#table td').attr('t', 's')
  80. var defaultCellStyle = {
  81. font: {
  82. name: 'Times New Roman',
  83. sz: 12,
  84. color: {
  85. rgb: "000000"
  86. },
  87. bold: false, italic: false,
  88. underline: false
  89. },
  90. alignment: {
  91. vertical: "center",
  92. horizontal: "center", indent: 0, wrapText: true
  93. },
  94. border: {
  95. top: {
  96. style: "thin",
  97. color: {
  98. rgb: "000000"
  99. }
  100. },
  101. right: {
  102. style: "thin",
  103. color: {
  104. rgb: "000000"
  105. }
  106. },
  107. bottom: {
  108. style: "thin",
  109. color: {
  110. rgb: "000000"
  111. }
  112. },
  113. left: {
  114. style: "thin",
  115. color: {
  116. rgb: "000000"
  117. }
  118. }
  119. }
  120. };
  121. var cell = { defaultCellStyle: defaultCellStyle };
  122. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#table'), cell, "一周安排台账")
  123. //设置表格的样式
  124. var wbout = XLSX.write(wb, {
  125. bookType: 'xlsx',
  126. bookSST: false,
  127. type: 'binary',
  128. cellStyles: true,
  129. defaultCellStyle: defaultCellStyle,
  130. showGridLines: false
  131. });
  132. var s2ab = function (s) {
  133. var buf = new ArrayBuffer(s.length);
  134. var view = new Uint8Array(buf);
  135. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  136. return buf;
  137. };
  138. try {
  139. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '一周安排台账.xlsx')
  140. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  141. return wbout
  142. } else {
  143. sp.dialog('数据还未加载完成,请稍等...')
  144. }
  145. }
  146. //头部下滚冻结
  147. $(function () {
  148. //页面高度撑满
  149. setTimeout(function () {
  150. if ($(".ibox-content").height() < $(window).height() - 31) {
  151. $(".ibox-content").css("height", $(window).height() - 31)
  152. }
  153. }, 1)
  154. })
  155. }])
  156. app.directive("repeatFinish", function () {
  157. return {
  158. link: function (scope) {
  159. if (scope.$last == true) {
  160. scope.$parent.ctl.canExportExcel = true;
  161. setTimeout(function () {
  162. $("#table").rowspan(7)
  163. $("#table").rowspan(6)
  164. $("#table").rowspan(5)
  165. $("#table").rowspan(3)
  166. $("#table").rowspan(2)
  167. $("#table").rowspan(1)
  168. $("#table").rowspan(0)
  169. }, 10);
  170. }
  171. }
  172. };
  173. });
  174. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  175. return this.each(function () {
  176. var that;
  177. $('tr', this).each(function (row) {
  178. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  179. if (that != null && $(this).html() == $(that).html()) {
  180. var rowspan = $(that).attr("rowSpan");
  181. if (rowspan == undefined) {
  182. $(that).attr("rowSpan", 1);
  183. rowspan = $(that).attr("rowSpan");
  184. }
  185. rowspan = Number(rowspan) + 1;
  186. $(that).attr("rowSpan", rowspan);
  187. $(this).remove();
  188. } else {
  189. that = this;
  190. }
  191. });
  192. });
  193. });
  194. }