taizhang.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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-yzaptz")) || { DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end };
  20. self.getSORTID = function () {
  21. var data = {
  22. userid: self.userId
  23. }
  24. $http.post(apiurljs.login + "g2app/richang/queryLDSortid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  25. .success(function (obj) {
  26. var res = strToJson(s4.decryptData_CBC(obj.data));
  27. self.LDSORTID = res.data;
  28. self.getData()
  29. })
  30. }
  31. self.getData = function () {
  32. self.list = [];
  33. self.loading = false;
  34. var data = {
  35. tablename: "SX_YZAPTZ",
  36. colums: "*,TO_CHAR(YZAPDATE,'yyyy-mm-dd')as YZAPDATE1,TO_CHAR(CTIME,'hh24:mi')as CTIME1",
  37. order: "CTIME",
  38. sqlwhere: " and YZAPDATE BETWEEN '" + self.search.DATE1 + " 00:00:00' AND '" + self.search.DATE2 + " 23:59:59' and USERID='" + self.userId + "'"
  39. }
  40. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColStr", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  41. .success(function (obj) {
  42. var res = strToJson(s4.decryptData_CBC(obj.data));
  43. self.loading = false;
  44. self.addFlag = false;
  45. self.editFlag = false;
  46. self.addList = [];
  47. self.list = res.data;
  48. self.list.forEach(function (item) {
  49. item.CNAME = item.CNAME == "null" ? "" : item.CNAME
  50. item.ATTENDANCESCOPE = item.ATTENDANCESCOPE == "null" ? "" : item.ATTENDANCESCOPE
  51. item.ADDR = item.ADDR == "null" ? "" : item.ADDR
  52. item.TIMEPERIOD1 = item.TIMEPERIOD;
  53. item.CTIME2 = item.CTIME1;
  54. item.CNAME1 = item.CNAME;
  55. item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE;
  56. item.ADDR1 = item.ADDR;
  57. })
  58. console.log(self.list)
  59. })
  60. }
  61. self.getSORTID();
  62. self.openLayer = function () {
  63. sp.layer("#Search")
  64. }
  65. self.doSearch = function () {
  66. sp.layerhide()
  67. if (self.search.DATE1 == "" || self.search.DATE2 == "") {
  68. sp.dialog("时间为可为空!");
  69. return
  70. }
  71. $.cookie("GlWorkPlatform-yzaptz", JSON.stringify(self.search), { path: '/', expires: 1 });
  72. self.getData();
  73. }
  74. self.cancal = function () {
  75. self.search = {
  76. DATE1: sp.getWeekNumber(new Date()).begin,
  77. DATE2: sp.getWeekNumber(new Date()).end
  78. }
  79. $.cookie("GlWorkPlatform-yzaptz", null, { path: '/', expires: 1 });
  80. self.getData();
  81. sp.layerhide()
  82. }
  83. self.refresh = function () {
  84. self.getData();
  85. }
  86. self.openInit = function () {
  87. self.init = {
  88. DATE1: sp.getWeekNumber(new Date()).begin, DATE2: sp.getWeekNumber(new Date()).end
  89. }
  90. sp.layer("#Init")
  91. }
  92. self.doInit = function () {
  93. var data = {
  94. userid: self.userId,
  95. routeinfoid:0,
  96. startdate: self.init.DATE1 + " 00:00:00",
  97. enddate: self.init.DATE2 + " 23:59:59"
  98. }
  99. $http.post(apiurljs.login + "g2app/richang/initYZAPTZList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  100. .success(function (obj) {
  101. var res = strToJson(s4.decryptData_CBC(obj.data));
  102. sp.layerhide();
  103. if (res.success) {
  104. self.getData();
  105. } else {
  106. sp.dialog(res.message)
  107. }
  108. })
  109. }
  110. self.addItem = function () {
  111. self.addFlag = true;
  112. self.addList.push({
  113. LDSORTID: self.LDSORTID,
  114. YZAPDATE: sp.format(sp.getLocalDate()),
  115. CWEEK: weeks[new Date().getDay()],
  116. TIMEPERIOD: "上午",
  117. CTIME: "09:00",
  118. CNAME: "",
  119. ATTENDANCESCOPE: "",
  120. ADDR: ""
  121. })
  122. $timeout(function () {
  123. $(".table-scroll").scrollTop($(".table-scroll").find("table").height())
  124. }, 1)
  125. }
  126. self.delItem = function (item) {
  127. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  128. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  129. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  130. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  131. sp.openCenter(".sp-dialog");
  132. ///取消按钮
  133. $('.sp-closeDialog').click(function (event) {
  134. sp.closeCenter(".sp-dialog");
  135. event.preventDefault();
  136. event.stopPropagation();
  137. });
  138. //post消息的id
  139. $("#delDataTrue").click(function () {
  140. var data = {
  141. tablename: "SX_YZAPTZ",
  142. id: item.ID
  143. };
  144. $http.post(apiurljs.login + "g2app/dataabase/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  145. .success(function (obj) {
  146. var res = strToJson(s4.decryptData_CBC(obj.data));
  147. sp.dialoghide();
  148. if (res.success) {
  149. self.getData();
  150. } else {
  151. sp.dialog("删除失败,请联系管理员!");
  152. }
  153. });
  154. });
  155. }
  156. var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
  157. self.changeCtime = function (obj, n) {
  158. if (n == 0) {
  159. if (obj.CTIME >= "13:00") {
  160. obj.TIMEPERIOD = "下午"
  161. } else {
  162. obj.TIMEPERIOD = "上午"
  163. }
  164. } else {
  165. if (obj.CTIME2 >= "13:00") {
  166. obj.TIMEPERIOD1 = "下午"
  167. } else {
  168. obj.TIMEPERIOD1 = "上午"
  169. }
  170. }
  171. obj.CWEEK = weeks[new Date(obj.YZAPDATE).getDay()]
  172. }
  173. self.btnCancal = function () {
  174. self.addFlag = false;
  175. self.addList = []
  176. self.editFlag = false;
  177. self.list.forEach(function (item) {
  178. item.TIMEPERIOD1 = item.TIMEPERIOD;
  179. item.CTIME2 = item.CTIME1;
  180. item.CNAME1 = item.CNAME;
  181. item.ATTENDANCESCOPE1 = item.ATTENDANCESCOPE;
  182. item.ADDR1 = item.ADDR;
  183. })
  184. }
  185. self.btnSave = function () {
  186. var n1 = true, n2 = true;
  187. if (self.addList.length > 0) {
  188. n1 = false;
  189. var data1 = {
  190. tablename: "SX_YZAPTZ",
  191. data: []
  192. }
  193. self.addList.forEach(function (item) {
  194. data1.data.push({
  195. LDSORTID: item.LDSORTID,
  196. YZAPDATE: item.YZAPDATE,
  197. TIMEPERIOD: item.TIMEPERIOD,
  198. CWEEK: item.CWEEK,
  199. CTIME: item.YZAPDATE + " " + item.CTIME + ":00",
  200. CNAME: item.CNAME,
  201. ATTENDANCESCOPE: item.ATTENDANCESCOPE,
  202. ADDR: item.ADDR,
  203. USERNAME: self.userName,
  204. USERID: self.userId,
  205. SECTCODE: self.userDpCode,
  206. CDATE: sp.getLocalDate()
  207. })
  208. })
  209. $http.post(apiurljs.login + "g2app/dataabase/insertDataList", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
  210. .success(function (obj) {
  211. var res = strToJson(s4.decryptData_CBC(obj.data));
  212. if (res.success == true) {
  213. n1 = true;
  214. if (self.list.length > 0) {
  215. n2 = false;
  216. var data2 = {
  217. entity: "SX_YZAPTZ",
  218. data: [],
  219. setwhere: []
  220. }
  221. self.list.forEach(function (item) {
  222. data2.data.push({
  223. TIMEPERIOD: item.TIMEPERIOD1,
  224. CTIME: item.YZAPDATE1 + " " + item.CTIME2 + ":00",
  225. CNAME: item.CNAME1,
  226. ATTENDANCESCOPE: item.ATTENDANCESCOPE1,
  227. ADDR: item.ADDR1
  228. })
  229. data2.setwhere.push({ ID: item.ID })
  230. })
  231. $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data2)) }, postCfg)
  232. .success(function (obj1) {
  233. var res1 = strToJson(s4.decryptData_CBC(obj1.data));
  234. if (res1.success == true) {
  235. n2 = true;
  236. if (n1 == true && n2 == true) {
  237. self.getData();
  238. sp.dialog("保存成功!");
  239. $timeout(function () {
  240. sp.dialoghide();
  241. }, 1500)
  242. }
  243. } else {
  244. sp.dialog(res1.message)
  245. }
  246. })
  247. } else {
  248. if (n1 == true && n2 == true) {
  249. self.getData();
  250. sp.dialog("保存成功!");
  251. $timeout(function () {
  252. sp.dialoghide();
  253. }, 1500)
  254. }
  255. }
  256. } else {
  257. sp.dialog(res.message)
  258. }
  259. })
  260. } else {
  261. n2 = false;
  262. var data1 = {
  263. entity: "SX_YZAPTZ",
  264. data: [],
  265. setwhere: []
  266. }
  267. self.list.forEach(function (item) {
  268. data1.data.push({
  269. TIMEPERIOD: item.TIMEPERIOD1,
  270. CTIME: item.YZAPDATE1 + " " + item.CTIME2 + ":00",
  271. CNAME: item.CNAME1,
  272. ATTENDANCESCOPE: item.ATTENDANCESCOPE1,
  273. ADDR: item.ADDR1
  274. })
  275. data1.setwhere.push({ ID: item.ID })
  276. })
  277. $http.post(apiurljs.login + "g2app/Data/UpdataByWhereList", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
  278. .success(function (obj) {
  279. var res = strToJson(s4.decryptData_CBC(obj.data));
  280. if (res.success == true) {
  281. n2 = true;
  282. if (n1 == true && n2 == true) {
  283. self.getData();
  284. sp.dialog("保存成功!");
  285. $timeout(function () {
  286. sp.dialoghide();
  287. }, 1500)
  288. }
  289. } else {
  290. sp.dialog(res.message)
  291. }
  292. })
  293. }
  294. }
  295. self.printOut = function () {
  296. if (self.canExportExcel) {
  297. $('#table td').attr('t', 's')
  298. var defaultCellStyle = {
  299. font: {
  300. name: 'Times New Roman',
  301. sz: 12,
  302. color: {
  303. rgb: "000000"
  304. },
  305. bold: false, italic: false,
  306. underline: false
  307. },
  308. alignment: {
  309. vertical: "center",
  310. horizontal: "center", indent: 0, wrapText: true
  311. },
  312. border: {
  313. top: {
  314. style: "thin",
  315. color: {
  316. rgb: "000000"
  317. }
  318. },
  319. right: {
  320. style: "thin",
  321. color: {
  322. rgb: "000000"
  323. }
  324. },
  325. bottom: {
  326. style: "thin",
  327. color: {
  328. rgb: "000000"
  329. }
  330. },
  331. left: {
  332. style: "thin",
  333. color: {
  334. rgb: "000000"
  335. }
  336. }
  337. }
  338. };
  339. var cell = { defaultCellStyle: defaultCellStyle };
  340. var wb = XLSX.utils.table_to_book_addtitle(document.querySelector('#table'), cell, "一周安排台账")
  341. //设置表格的样式
  342. var wbout = XLSX.write(wb, {
  343. bookType: 'xlsx',
  344. bookSST: false,
  345. type: 'binary',
  346. cellStyles: true,
  347. defaultCellStyle: defaultCellStyle,
  348. showGridLines: false
  349. });
  350. var s2ab = function (s) {
  351. var buf = new ArrayBuffer(s.length);
  352. var view = new Uint8Array(buf);
  353. for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  354. return buf;
  355. };
  356. try {
  357. saveAs(new Blob([s2ab(wbout)], { type: 'application/octet-stream' }), '一周安排台账.xlsx')
  358. } catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
  359. return wbout
  360. } else {
  361. sp.dialog('数据还未加载完成,请稍等...')
  362. }
  363. }
  364. //头部下滚冻结
  365. $(function () {
  366. //页面高度撑满
  367. setTimeout(function () {
  368. if ($(".ibox-content").height() < $(window).height() - 31) {
  369. $(".ibox-content").css("height", $(window).height() - 31)
  370. }
  371. }, 1)
  372. })
  373. }])
  374. app.directive("repeatFinish", function () {
  375. return {
  376. link: function (scope) {
  377. if (scope.$last == true) {
  378. scope.$parent.ctl.canExportExcel = true;
  379. setTimeout(function () {
  380. $("#table").rowspan(1)
  381. $("#table").rowspan(0)
  382. }, 10);
  383. }
  384. }
  385. };
  386. });
  387. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  388. return this.each(function () {
  389. var that;
  390. $('tr', this).each(function (row) {
  391. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  392. if (that != null && $(this).html() == $(that).html()) {
  393. var rowspan = $(that).attr("rowSpan");
  394. if (rowspan == undefined) {
  395. $(that).attr("rowSpan", 1);
  396. rowspan = $(that).attr("rowSpan");
  397. }
  398. rowspan = Number(rowspan) + 1;
  399. $(that).attr("rowSpan", rowspan);
  400. $(this).remove();
  401. } else {
  402. that = this;
  403. }
  404. });
  405. });
  406. });
  407. }