taizhang.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("taizhangCtrl", ["$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. var postCfg = {
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. 'Authorization': "Bearer " + self.get_AccessToken
  16. }
  17. }
  18. self.loading = false;
  19. self.search = JSON.parse($.cookie("GlWorkPlatform-ldyzaptz")) || { DATE1: sp.dateCount(0) };
  20. self.currentWeek = sp.getWeekNumber(new Date()).dateString.split(",").map(function (item) {
  21. return item.replace(".", "-")
  22. })
  23. self.day = self.search.DATE1.slice(5);
  24. self.changeDay = function (item) {
  25. self.day = item;
  26. self.search.DATE1 = sp.currentYear() + "-" + self.day;
  27. self.getData();
  28. }
  29. self.getData = function () {
  30. self.list = [];
  31. self.loading = false;
  32. var data = {
  33. tablename: "SX_YZAPTZ",
  34. colums: "*,TO_CHAR(YZAPDATE,'yyyy-mm-dd')as YZAPDATE1,TO_CHAR(CTIME,'hh24:mi')as CTIME1",
  35. order: "LDSORTID asc",
  36. sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE1 + " 23:59:59'"
  37. }
  38. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColStr", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  39. .success(function (obj) {
  40. var res = strToJson(s4.decryptData_CBC(obj.data));
  41. self.loading = false;
  42. self.list = res.data;
  43. self.list.forEach(function (item) {
  44. item.CNAME = item.CNAME == "null" ? "" : item.CNAME
  45. item.ATTENDANCESCOPE = item.ATTENDANCESCOPE == "null" ? "" : item.ATTENDANCESCOPE
  46. item.ADDR = item.ADDR == "null" ? "" : item.ADDR
  47. })
  48. })
  49. }
  50. self.getData();
  51. self.openLayer = function () {
  52. sp.layer("#Search")
  53. }
  54. self.doSearch = function () {
  55. sp.layerhide()
  56. if (self.search.DATE1 == "") {
  57. sp.dialog("时间为可为空!");
  58. return
  59. }
  60. self.day = self.search.DATE1.slice(5);
  61. $.cookie("GlWorkPlatform-ldyzaptz", JSON.stringify(self.search), { path: '/', expires: 1 });
  62. self.getData();
  63. }
  64. self.cancal = function () {
  65. self.search = {
  66. DATE1: sp.dateCount(0)
  67. }
  68. self.day = self.search.DATE1.slice(5);
  69. $.cookie("GlWorkPlatform-ldyzaptz", null, { path: '/', expires: 1 });
  70. self.getData();
  71. sp.layerhide()
  72. }
  73. self.refresh = function () {
  74. self.getData();
  75. }
  76. var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
  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(1)
  163. $("#table").rowspan(0)
  164. }, 10);
  165. }
  166. }
  167. };
  168. });
  169. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  170. return this.each(function () {
  171. var that;
  172. $('tr', this).each(function (row) {
  173. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  174. if (that != null && $(this).html() == $(that).html()) {
  175. var rowspan = $(that).attr("rowSpan");
  176. if (rowspan == undefined) {
  177. $(that).attr("rowSpan", 1);
  178. rowspan = $(that).attr("rowSpan");
  179. }
  180. rowspan = Number(rowspan) + 1;
  181. $(that).attr("rowSpan", rowspan);
  182. $(this).remove();
  183. } else {
  184. that = this;
  185. }
  186. });
  187. });
  188. });
  189. }