zhiban.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("listCtrl", ["$scope", "$http", "$timeout", "$sce", function ($scope, $http, $timeout, $sce) {
  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.dateParam = sp.getUrlName("date");
  12. var postCfg = {
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. 'Authorization': "Bearer " + self.get_AccessToken
  16. }
  17. }
  18. self.search = {
  19. type: 1,
  20. dw: "",
  21. date: self.dateParam == "" ? sp.currentYear() + "-" + formate(sp.currentMonth()) : self.dateParam
  22. }
  23. self.showType = 1;
  24. self.getYF = function () {
  25. var data = {
  26. ckey: "CODE_ZBYF",
  27. routeinfoid: self.routeinfoid
  28. }
  29. $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  30. .success(function (obj) {
  31. var res = strToJson(s4.decryptData_CBC(obj.data));
  32. self.YF = res.data.CODE_ZBYF;
  33. self.getXQ()
  34. })
  35. }
  36. self.getXQ = function () {
  37. var data = {
  38. ckey: "CODE_ZBXQ",
  39. routeinfoid: self.routeinfoid
  40. }
  41. $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  42. .success(function (obj) {
  43. var res = strToJson(s4.decryptData_CBC(obj.data));
  44. self.XQ = res.data.CODE_ZBXQ;
  45. self.getType()
  46. })
  47. }
  48. self.getType = function () {
  49. var data = {
  50. userid: self.userId
  51. }
  52. $http.post(apiurljs.login + "g2app/dataabase/queryDPParentName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  53. .success(function (obj) {
  54. var res = strToJson(s4.decryptData_CBC(obj.data));
  55. for (var i in res.data[0]) {
  56. if (res.data[0][i][0].PARENT_DATA.length > 0){
  57. self.search.type = res.data[0][i][0].PARENT_DATA[0].SECTION != "直属单位" ? 1 : 2;
  58. } else {
  59. self.search.type = 1;
  60. }
  61. }
  62. //self.search.type == res.data;
  63. if (self.search.type == 1) {
  64. self.getZBSJ()
  65. } else {
  66. self.getZBSJ1()
  67. }
  68. })
  69. }
  70. //委机关
  71. self.getZBSJ = function () {
  72. var data = {
  73. ckey: "CODE_ZHIBANTIME",
  74. routeinfoid: self.routeinfoid
  75. }
  76. $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  77. .success(function (obj) {
  78. var res = strToJson(s4.decryptData_CBC(obj.data));
  79. self.ZBSJ = res.data.CODE_ZHIBANTIME;
  80. self.getData()
  81. })
  82. }
  83. //直属单位
  84. self.getZBSJ1 = function () {
  85. var data = {
  86. ckey: "CODE_ZHIBANTIMEZSDW",
  87. routeinfoid: self.routeinfoid
  88. }
  89. $http.post(apiurljs.login + "g2app/abase/queryDataCode", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  90. .success(function (obj) {
  91. var res = strToJson(s4.decryptData_CBC(obj.data));
  92. self.ZBSJ = res.data.CODE_ZHIBANTIMEZSDW;
  93. self.getDP()
  94. })
  95. }
  96. self.getDP = function () {
  97. var data = {
  98. userid: self.userId
  99. }
  100. $http.post(apiurljs.login + "g2app/richang/queryDpInfo", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  101. .success(function (obj) {
  102. var res = strToJson(s4.decryptData_CBC(obj.data));
  103. self.userDpName = res.data.length == 0 ? "" : res.data[0].SECTION;
  104. self.userDpCode = res.data.length == 0 ? "" : res.data[0].CODE;
  105. self.getData();
  106. })
  107. }
  108. self.getYF()
  109. self.getData = function () {
  110. var year = self.search.date.split("-")[0], month = "";
  111. self.YF.forEach(function (item) {
  112. if (formate(item.CNAME) == self.search.date.split("-")[1]) {
  113. month = item.CODE;
  114. }
  115. })
  116. self.list = [];
  117. self.list1 = [];
  118. self.list2 = [];
  119. var data = {
  120. tablename: self.search.type == 1 ? "SX_PRZBB" : "SX_YFZBB",
  121. colums: "*",
  122. order: "ID desc",
  123. sqlwhere: { NF: year, YF: month, STOPMARK: 1 },
  124. sqlorwhere: "",
  125. sqlinwhere: "",
  126. sqllikewhere: self.search.type == 1 ? "" : { SQDWCODE: self.userDpCode }
  127. }
  128. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  129. .success(function (obj) {
  130. var res = strToJson(s4.decryptData_CBC(obj.data));
  131. self.canExportExcel = true;
  132. if (res.data == null || res.data == undefined || res.data == "") {
  133. } else {
  134. self.parentID = res.data[0].ID;
  135. if (self.search.type == 1) {
  136. self.ZBREMARK = res.data[0].ZBREMARK;
  137. } else {
  138. self.ZBSJREMARK = res.data[0].ZBSJREMARK;
  139. self.ZBDH = res.data[0].ZBDH;
  140. self.ZBCZ = res.data[0].ZBCZ;
  141. self.YJJJRZBDH = res.data[0].YJJJRZBDH;
  142. self.YJJJRZBCZ = res.data[0].YJJJRZBCZ;
  143. self.ZBDD = res.data[0].ZBDD;
  144. self.TBR = res.data[0].TBR;
  145. self.REMARK = res.data[0].REMARK;
  146. }
  147. if (self.search.type == 1) {
  148. var data = {
  149. tablename: "SX_PRZBB_01",
  150. colums: "*",
  151. order: "ID",
  152. sqlwhere: { PID: self.parentID },
  153. sqlinwhere: "",
  154. sqllikewhere: ""
  155. }
  156. $http.post(apiurljs.login + "/g2app/ZhiBan/queryPRZBList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  157. .success(function (obj) {
  158. var res = strToJson(s4.decryptData_CBC(obj.data));
  159. if (res.data.indexmark.start_index == 0) {
  160. self.table1 = 4; self.table2 = 1
  161. }
  162. if (res.data.indexmark.start_index2 == 0) {
  163. self.table1 = 1; self.table2 = 4
  164. }
  165. if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) {
  166. self.table1 = 1; self.table2 = 0
  167. }
  168. console.log(self.table1)
  169. $.each(res.data.data, function (index, item) {
  170. item.editFlag = false;
  171. item.RIQI = formate(item.RIQI);
  172. self.ZBSJ.forEach(function (item1) {
  173. if (item.ZBSJ == item1.CODE) {
  174. item.ZBSJ = item1.CNAME
  175. }
  176. })
  177. if (res.data.indexmark.start_index == 0 && res.data.indexmark.start_index2 > 0) {
  178. if (index < res.data.indexmark.start_index2) {
  179. self.list1.push(item)
  180. } else {
  181. self.list2.push(item)
  182. }
  183. }
  184. if (res.data.indexmark.start_index2 == 0 && res.data.indexmark.start_index > 0) {
  185. if (index < res.data.indexmark.start_index) {
  186. self.list1.push(item)
  187. } else {
  188. self.list2.push(item)
  189. }
  190. }
  191. if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) {
  192. self.list1.push(item)
  193. }
  194. })
  195. })
  196. } else {
  197. var data1 = {
  198. tablename: "SX_YFZBB_01",
  199. colums: "*",
  200. order: "ID",
  201. sqlwhere: { PID: self.parentID },
  202. sqlinwhere: "",
  203. sqllikewhere: ""
  204. }
  205. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
  206. .success(function (obj1) {
  207. var res1 = strToJson(s4.decryptData_CBC(obj1.data));
  208. self.list1 = res1.data;
  209. self.list1.forEach(function (item) {
  210. item.RIQI = formate(item.RIQI);
  211. self.XQ.forEach(function (item1) {
  212. if (item.XINGQI == item1.CODE) {
  213. item.XINGQI = item1.CNAME
  214. }
  215. })
  216. self.ZBSJ.forEach(function (item1) {
  217. if (item.ZBSJ == item1.CODE) {
  218. item.ZBSJ = item1.CNAME
  219. }
  220. })
  221. })
  222. })
  223. }
  224. }
  225. })
  226. }
  227. self.printOut = function () {
  228. if (self.canExportExcel) {
  229. $('#printOut td').attr('t', 's')
  230. var defaultCellStyle = {
  231. font: {
  232. name: 'Times New Roman',
  233. sz: 12,
  234. color: {
  235. rgb: "000000"
  236. },
  237. bold: false, italic: false,
  238. underline: false
  239. },
  240. alignment: {
  241. vertical: "center",
  242. horizontal: "center", indent: 0, wrapText: true
  243. },
  244. border: {
  245. top: {
  246. style: "thin",
  247. color: {
  248. rgb: "000000"
  249. }
  250. },
  251. right: {
  252. style: "thin",
  253. color: {
  254. rgb: "000000"
  255. }
  256. },
  257. bottom: {
  258. style: "thin",
  259. color: {
  260. rgb: "000000"
  261. }
  262. },
  263. left: {
  264. style: "thin",
  265. color: {
  266. rgb: "000000"
  267. }
  268. }
  269. }
  270. };
  271. var cell = { defaultCellStyle: defaultCellStyle };
  272. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, (self.search.type == 1 ? "委机关值班表" : "直属单位值班表"))
  273. //设置表格的样式
  274. var wbout = XLSX.write(wb, {
  275. bookType: 'xlsx',
  276. bookSST: false,
  277. type: 'binary',
  278. cellStyles: true,
  279. defaultCellStyle: defaultCellStyle,
  280. showGridLines: false
  281. });
  282. var s2ab = function (s) {
  283. var buf = new ArrayBuffer(s.length);
  284. var view = new Uint8Array(buf);
  285. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  286. return buf;
  287. };
  288. try {
  289. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), (self.search.type == 1 ? "委机关值班表" : "直属单位值班表") + '.xlsx')
  290. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  291. return wbout
  292. } else {
  293. sp.dialog('数据还未加载完成,请稍等...')
  294. }
  295. }
  296. //委机关查看直属单位
  297. self.getZSDW = function () {
  298. var data = {
  299. nf: self.search.date.split("-")[0],
  300. yfname: parseInt(self.search.date.split("-")[1]),
  301. columns: "*"
  302. }
  303. $http.post(apiurljs.login + "g2app/ZhiBan/queryZSDWList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  304. .success(function (obj) {
  305. var res = strToJson(s4.decryptData_CBC(obj.data));
  306. self.zsdwList = res.data;
  307. self.zsdwList.forEach(function (item) {
  308. item.BSDATE1 = sp.datefmt("yyyy-MM-dd", item.BSDATE)
  309. })
  310. })
  311. }
  312. self.goDetail = function (item) {
  313. if (item.STOPMARK == '1' || item.WNCKBS == '1') {
  314. sp.openNewWindow("detail.html?id=" + item.ID + "&bssj=" + new Date(item.BSDATE1).getTime(), item.CNAME + self.search.date.slice(5) + "月值班表")
  315. } else {
  316. }
  317. }
  318. //头部下滚冻结
  319. $(function () {
  320. //页面高度撑满
  321. setTimeout(function () {
  322. if ($(".ibox-content").height() < $(window).height() - 31) {
  323. $(".ibox-content").css("height", $(window).height() - 31)
  324. }
  325. }, 1)
  326. })
  327. }])
  328. app.filter('trustHtml', function ($sce) {
  329. return function (input) {
  330. return $sce.trustAsHtml(input.replace(/\n/g, '<br/>').replace(/\s/g, '&nbsp;'));
  331. };
  332. });
  333. app.directive("repeatFinish", function () {
  334. return {
  335. link: function (scope) {
  336. if (scope.$last == true) {
  337. setTimeout(function () {
  338. $(".sp-table").rowspan(1)
  339. $(".sp-table").rowspan(0)
  340. }, 10);
  341. }
  342. }
  343. };
  344. });
  345. function formate(d) {
  346. return d * 1 > 9 ? d * 1 : "0" + d * 1
  347. }
  348. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  349. return this.each(function () {
  350. var that;
  351. $('tr', this).each(function (row) {
  352. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  353. if (that != null && $(this).html() == $(that).html()) {
  354. var rowspan = $(that).attr("rowSpan");
  355. if (rowspan == undefined) {
  356. $(that).attr("rowSpan", 1);
  357. rowspan = $(that).attr("rowSpan");
  358. }
  359. rowspan = Number(rowspan) + 1;
  360. $(that).attr("rowSpan", rowspan);
  361. $(this).remove();
  362. } else {
  363. that = this;
  364. }
  365. });
  366. });
  367. });
  368. }