zhiban2.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. var data = {
  118. tablename: self.search.type == 1 ? "SX_PRZBB" : "SX_YFZBB",
  119. colums: "*",
  120. order: "ID desc",
  121. sqlwhere: { NF: year, YF: month, STOPMARK: 1 },
  122. sqlorwhere: "",
  123. sqlinwhere: "",
  124. sqllikewhere: self.search.type == 1 ? "" : { SQDWCODE: self.userDpCode }
  125. }
  126. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  127. .success(function (obj) {
  128. var res = strToJson(s4.decryptData_CBC(obj.data));
  129. self.canExportExcel = true;
  130. if (res.data == null || res.data == undefined || res.data == "") {
  131. sp.dialog(self.search.date.split("-")[0] + "年" + self.search.date.split("-")[1] + "月暂无审批通过数据!");
  132. } else {
  133. self.parentID = res.data[0].ID;
  134. if (self.search.type == 1) {
  135. self.ZBREMARK = res.data[0].ZBREMARK;
  136. } else {
  137. self.ZBSJREMARK = res.data[0].ZBSJREMARK;
  138. self.ZBDH = res.data[0].ZBDH;
  139. self.ZBCZ = res.data[0].ZBCZ;
  140. self.YJJJRZBDH = res.data[0].YJJJRZBDH;
  141. self.YJJJRZBCZ = res.data[0].YJJJRZBCZ;
  142. self.ZBDD = res.data[0].ZBDD;
  143. self.TBR = res.data[0].TBR;
  144. self.REMARK = res.data[0].REMARK;
  145. }
  146. if (self.search.type == 1) {
  147. self.list1 = [];
  148. self.list2 = [];
  149. var data = {
  150. tablename: "SX_PRZBB_01",
  151. colums: "*",
  152. order: "ID",
  153. sqlwhere: { PID: self.parentID },
  154. sqlinwhere: "",
  155. sqllikewhere: ""
  156. }
  157. $http.post(apiurljs.login + "/g2app/ZhiBan/queryPRZBList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  158. .success(function (obj) {
  159. var res = strToJson(s4.decryptData_CBC(obj.data));
  160. if (res.data.indexmark.start_index == 0) {
  161. self.table1 = 4; self.table2 = 1
  162. }
  163. if (res.data.indexmark.start_index2 == 0) {
  164. self.table1 = 1; self.table2 = 4
  165. }
  166. if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) {
  167. self.table1 = 4; self.table2 = 0
  168. }
  169. $.each(res.data.data, function (index, item) {
  170. item.RIQI = formate(item.RIQI);
  171. self.XQ.forEach(function (item1) {
  172. if (item.XINGQI == item1.CODE) {
  173. item.XINGQI = item1.CNAME
  174. }
  175. })
  176. self.ZBSJ.forEach(function (item1) {
  177. if (item.ZBSJ == item1.CODE) {
  178. item.ZBSJ = item1.CNAME
  179. }
  180. })
  181. if (res.data.indexmark.start_index == 0 && res.data.indexmark.start_index2 > 0) {
  182. if (index < res.data.indexmark.start_index2) {
  183. self.list1.push(item)
  184. } else {
  185. self.list2.push(item)
  186. }
  187. }
  188. if (res.data.indexmark.start_index2 == 0 && res.data.indexmark.start_index > 0) {
  189. if (index < res.data.indexmark.start_index) {
  190. self.list1.push(item)
  191. } else {
  192. self.list2.push(item)
  193. }
  194. }
  195. if (res.data.indexmark.start_index2 == -1 && res.data.indexmark.end_index2 == -1) {
  196. self.list1.push(item)
  197. }
  198. })
  199. })
  200. } else {
  201. var data1 = {
  202. tablename: "SX_YFZBB_01",
  203. colums: "*",
  204. order: "ID",
  205. sqlwhere: { PID: self.parentID },
  206. sqlinwhere: "",
  207. sqllikewhere: ""
  208. }
  209. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
  210. .success(function (obj1) {
  211. var res1 = strToJson(s4.decryptData_CBC(obj1.data));
  212. self.list1 = res1.data;
  213. self.list1.forEach(function (item) {
  214. item.RIQI = formate(item.RIQI);
  215. self.XQ.forEach(function (item1) {
  216. if (item.XINGQI == item1.CODE) {
  217. item.XINGQI = item1.CNAME
  218. }
  219. })
  220. self.ZBSJ.forEach(function (item1) {
  221. if (item.ZBSJ == item1.CODE) {
  222. item.ZBSJ = item1.CNAME
  223. }
  224. })
  225. })
  226. })
  227. }
  228. }
  229. })
  230. }
  231. self.printOut = function () {
  232. if (self.canExportExcel) {
  233. $('#printOut td').attr('t', 's')
  234. var defaultCellStyle = {
  235. font: {
  236. name: 'Times New Roman',
  237. sz: 12,
  238. color: {
  239. rgb: "000000"
  240. },
  241. bold: false, italic: false,
  242. underline: false
  243. },
  244. alignment: {
  245. vertical: "center",
  246. horizontal: "center", indent: 0, wrapText: true
  247. },
  248. border: {
  249. top: {
  250. style: "thin",
  251. color: {
  252. rgb: "000000"
  253. }
  254. },
  255. right: {
  256. style: "thin",
  257. color: {
  258. rgb: "000000"
  259. }
  260. },
  261. bottom: {
  262. style: "thin",
  263. color: {
  264. rgb: "000000"
  265. }
  266. },
  267. left: {
  268. style: "thin",
  269. color: {
  270. rgb: "000000"
  271. }
  272. }
  273. }
  274. };
  275. var cell = { defaultCellStyle: defaultCellStyle };
  276. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#printOut'), cell, (self.search.type == 1 ? "委机关值班表" : "直属单位值班表"))
  277. //设置表格的样式
  278. var wbout = XLSX.write(wb, {
  279. bookType: 'xlsx',
  280. bookSST: false,
  281. type: 'binary',
  282. cellStyles: true,
  283. defaultCellStyle: defaultCellStyle,
  284. showGridLines: false
  285. });
  286. var s2ab = function (s) {
  287. var buf = new ArrayBuffer(s.length);
  288. var view = new Uint8Array(buf);
  289. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  290. return buf;
  291. };
  292. try {
  293. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), (self.search.type == 1 ? "委机关值班表" : "直属单位值班表") + '.xlsx')
  294. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  295. return wbout
  296. } else {
  297. sp.dialog('数据还未加载完成,请稍等...')
  298. }
  299. }
  300. //委机关查看直属单位
  301. self.getZSDW = function () {
  302. var data = {
  303. nf: self.search.date.split("-")[0],
  304. yfname: parseInt(self.search.date.split("-")[1]),
  305. columns: "*"
  306. }
  307. $http.post(apiurljs.login + "g2app/ZhiBan/queryZSDWList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  308. .success(function (obj) {
  309. var res = strToJson(s4.decryptData_CBC(obj.data));
  310. self.zsdwList = res.data;
  311. self.zsdwList.forEach(function (item) {
  312. item.BSDATE1 = sp.datefmt("yyyy-MM-dd HH:mm", item.BSDATE)
  313. })
  314. })
  315. }
  316. self.goDetail = function (item) {
  317. if (item.STOPMARK !='1') {
  318. return
  319. } else {
  320. sp.openNewWindow("detail.html?id=" + item.ID, item.CNAME + self.search.date.slice(5) + "月值班表")
  321. }
  322. }
  323. //头部下滚冻结
  324. $(function () {
  325. //页面高度撑满
  326. setTimeout(function () {
  327. if ($(".ibox-content").height() < $(window).height() - 31) {
  328. $(".ibox-content").css("height", $(window).height() - 31)
  329. }
  330. }, 1)
  331. })
  332. }])
  333. app.filter('trustHtml', function ($sce) {
  334. return function (input) {
  335. return $sce.trustAsHtml(input.replace(/\n/g, '<br/>').replace(/\s/g, '&nbsp;'));
  336. };
  337. });
  338. app.directive("repeatFinish", function () {
  339. return {
  340. link: function (scope) {
  341. if (scope.$last == true) {
  342. setTimeout(function () {
  343. $(".sp-table").rowspan(1)
  344. $(".sp-table").rowspan(0)
  345. }, 10);
  346. }
  347. }
  348. };
  349. });
  350. function formate(d) {
  351. return d * 1 > 9 ? d * 1 : "0" + d * 1
  352. }
  353. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  354. return this.each(function () {
  355. var that;
  356. $('tr', this).each(function (row) {
  357. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  358. if (that != null && $(this).html() == $(that).html()) {
  359. var rowspan = $(that).attr("rowSpan");
  360. if (rowspan == undefined) {
  361. $(that).attr("rowSpan", 1);
  362. rowspan = $(that).attr("rowSpan");
  363. }
  364. rowspan = Number(rowspan) + 1;
  365. $(that).attr("rowSpan", rowspan);
  366. $(this).remove();
  367. } else {
  368. that = this;
  369. }
  370. });
  371. });
  372. });
  373. }