search.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.get_type = parseInt(sp.getUrlName("type"));
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. self.search = {
  20. TYPE: 1,
  21. KSSJ: sp.monthfirst(sp.getLocalDate()),
  22. JSSJ: sp.formatMonthLast(sp.getLocalDate())
  23. }
  24. self.changeType = function () {
  25. switch (self.search.TYPE) {
  26. case "1": self.search.KSSJ = sp.monthfirst(sp.getLocalDate()); self.search.JSSJ = sp.formatMonthLast(sp.getLocalDate()); break;
  27. case "2": self.search.KSSJ = sp.quarter(sp.getLocalDate(), 1); self.search.JSSJ = sp.quarter(sp.getLocalDate(), 2); break;
  28. case "3": self.search.KSSJ = sp.currentYear() + "-01-01"; self.search.JSSJ = sp.currentYear() + "-12-31"; break;
  29. case "4": self.search.KSSJ = sp.format(sp.getLocalDate()); self.search.JSSJ = sp.format(sp.getLocalDate()); break;
  30. }
  31. }
  32. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  33. self.getData = function () {
  34. self.list = []
  35. var data = {
  36. flowtype: "C03",
  37. tablename: "",
  38. begindate: self.search.KSSJ + " 00:00:00",
  39. enddate: self.search.JSSJ + " 23:59:59"
  40. }
  41. $http.post(apiurljs.login + "g2app/richang/XinFangStatistics", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  42. .success(function (obj) {
  43. var res = strToJson(s4.decryptData_CBC(obj.data));
  44. self.canExportExcel = true;
  45. if (res.data == null || res.data == undefined || res.data == "") {
  46. self.noDataTip = 0;
  47. } else {
  48. self.noDataTip = 1;
  49. self.list = res.data;
  50. }
  51. })
  52. }
  53. self.getData();
  54. self.printOut = function () {
  55. if (self.canExportExcel) {
  56. $('#printOut td').attr('t', 's')
  57. var defaultCellStyle = {
  58. font: {
  59. name: 'Times New Roman',
  60. sz: 12,
  61. color: {
  62. rgb: "000000"
  63. },
  64. bold: false, italic: false,
  65. underline: false
  66. },
  67. alignment: {
  68. vertical: "center",
  69. horizontal: "center", indent: 0, wrapText: true
  70. },
  71. border: {
  72. top: {
  73. style: "thin",
  74. color: {
  75. rgb: "000000"
  76. }
  77. },
  78. right: {
  79. style: "thin",
  80. color: {
  81. rgb: "000000"
  82. }
  83. },
  84. bottom: {
  85. style: "thin",
  86. color: {
  87. rgb: "000000"
  88. }
  89. },
  90. left: {
  91. style: "thin",
  92. color: {
  93. rgb: "000000"
  94. }
  95. }
  96. }
  97. };
  98. var cell = { defaultCellStyle: defaultCellStyle };
  99. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, "日常管理统计")
  100. //设置表格的样式
  101. var wbout = XLSX.write(wb, {
  102. bookType: 'xlsx',
  103. bookSST: false,
  104. type: 'binary',
  105. cellStyles: true,
  106. defaultCellStyle: defaultCellStyle,
  107. showGridLines: false
  108. });
  109. var s2ab = function (s) {
  110. var buf = new ArrayBuffer(s.length);
  111. var view = new Uint8Array(buf);
  112. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  113. return buf;
  114. };
  115. try {
  116. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '日常管理统计.xlsx')
  117. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  118. return wbout
  119. } else {
  120. sp.dialog('数据还未加载完成,请稍等...')
  121. }
  122. }
  123. //头部下滚冻结
  124. $(function () {
  125. //页面高度撑满
  126. setTimeout(function () {
  127. if ($(".ibox-content").height() < $(window).height() - 31) {
  128. $(".ibox-content").css("height", $(window).height() - 31)
  129. }
  130. $(".sp-table").parent().css("height", $(".ibox-content").height() - 50)
  131. }, 1)
  132. })
  133. }])