list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 = sp.getUrlName("type");
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. self.type = self.get_type != "" ? self.get_type : "1";
  20. self.loading = false;
  21. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  22. self.pageno = 1;
  23. self.total_count = 0;
  24. self.itemsPerPage = 10;
  25. self.pageOptions = [10, 20, 30, 40];
  26. self.Status = "";
  27. self.getData = function (pageno) {
  28. self.list = [];
  29. self.loading = false;
  30. self.pageno = pageno;
  31. $scope.__default__currentPage = self.pageno; //设置页面样式在第几页
  32. var data = {
  33. tablename: "SX_HYSGLB",
  34. pagesize: self.itemsPerPage,
  35. pageno: self.pageno,
  36. colums: "*",
  37. order: "SORTID",
  38. sqlwhere: { ZT: self.Status },
  39. sqlorwhere: "",
  40. sqlinwhere: "",
  41. sqllikewhere: ""
  42. };
  43. $http.post(apiurljs.login + "g2app/dataabase/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  44. .success(function (obj) {
  45. var res = strToJson(s4.decryptData_CBC(obj.data));
  46. self.loading = false;
  47. if (res.data == null || res.data == undefined || res.data == "") {
  48. self.noDataTip = 0;
  49. } else {
  50. self.noDataTip = 1;
  51. self.list = res.data;
  52. self.total_count = res.totalCount;
  53. }
  54. })
  55. }
  56. self.load = function () {
  57. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  58. self.getData(self.pageno);
  59. } else {
  60. $timeout(function () {
  61. self.getData(self.get_lastReturnPageno);
  62. }, 1)
  63. }
  64. }
  65. self.wuye = false;
  66. self.getROLE = function () {
  67. var data = {
  68. userid: self.userId
  69. };
  70. $http.post(apiurljs.login + "g2work/datazu/queryDataUserAuth", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  71. .success(function (obj) {
  72. var res = strToJson(s4.decryptData_CBC(obj.data));
  73. res.data[0].auths.forEach(function (item) {
  74. if (item.ZID == "AA36" && item.AUTH == "1") {
  75. self.wuye = true;
  76. self.load()
  77. }
  78. })
  79. });
  80. }
  81. self.getROLE()
  82. self.refresh = function () {
  83. self.getData(self.pageno);
  84. }
  85. self.changeType = function (str) {
  86. if (self.type == str) {
  87. return;
  88. } else {
  89. self.type = str;
  90. self.getData(1)
  91. }
  92. }
  93. self.btnEdit = function (id) {
  94. window.location.href = "huiyi/formedit.html?id=" + id + "&lastReturnPageno=" + self.pageno;
  95. }
  96. self.btnDel = function (id) {
  97. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  98. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  99. 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>";
  100. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  101. sp.openCenter(".sp-dialog");
  102. ///取消按钮
  103. $('.sp-closeDialog').click(function (event) {
  104. sp.closeCenter(".sp-dialog");
  105. event.preventDefault();
  106. event.stopPropagation();
  107. });
  108. //post消息的id
  109. $("#delDataTrue").click(function () {
  110. var data = {
  111. tablename: "SX_HYSGLB",
  112. id: id
  113. };
  114. $http.post(apiurljs.login + "g2app/dataabase/delDataById", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  115. .success(function (obj) {
  116. var res = strToJson(s4.decryptData_CBC(obj.data));
  117. sp.dialoghide();
  118. if (res.success) {
  119. self.getData(self.pageno);
  120. } else {
  121. sp.dialog("删除失败,请联系管理员!");
  122. }
  123. });
  124. });
  125. }
  126. //生成当天起,一共7天数据
  127. self.searchDay = sp.format(sp.getLocalDate())
  128. //自动生成列数据
  129. self.getRoom = function () {
  130. self.week = []
  131. sp.getWeekNumber(new Date(self.searchDay)).dateString.split(",").forEach(function (item) {
  132. self.week.push({ date: item, time: "08:00" }, { date: item, time: "09:00" }, { date: item, time: "10:00" }, { date: item, time: "11:00" }, { date: item, time: "12:00" }, { date: item, time: "13:00" }, { date: item, time: "14:00" }, { date: item, time: "15:00" }, { date: item, time: "16:00" }, { date: item, time: "17:00" }, { date: item, time: "18:00" })
  133. })
  134. var data = {
  135. tablename: "SX_HYSGLB",
  136. colums: "*",
  137. order: "ID",
  138. sqlwhere: { ZT: "正常" },
  139. sqlorwhere: "",
  140. sqlinwhere: "",
  141. sqllikewhere: ""
  142. };
  143. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  144. .success(function (obj) {
  145. var res = strToJson(s4.decryptData_CBC(obj.data));
  146. self.huiyiRoom = [];
  147. res.data.forEach(function (item) {
  148. self.huiyiRoom.push({ name: item.HYSMC, fjh: item.WZ })
  149. })
  150. self.getApplication()
  151. })
  152. }
  153. self.getRoom()
  154. //使用情况数据,status:1为已结束,2为进行中,3为已预订,4为已取消
  155. self.getApplication = function () {
  156. self.application = [];
  157. var data = {
  158. userid: self.userId,
  159. sdate: sp.dateCount(0) + " 08:00:00",
  160. edate: sp.dateCount(6) + " 23:00:00"
  161. }
  162. $http.post(apiurljs.login + "g2app/huiwu/queryDataHuiwuStatus", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  163. .success(function (obj) {
  164. var res = strToJson(s4.decryptData_CBC(obj.data));
  165. res.data.forEach(function (item) {
  166. self.application.push({
  167. date: sp.datefmt("M-dd", item.KSSJ).replace("-", "."),
  168. start: sp.datefmt("HH:mm", item.KSSJ),
  169. end: sp.datefmt("HH:mm", item.JSSJ),
  170. fjh: item.HYS,
  171. dpname: item.CBBM,
  172. username: item.SQR,
  173. status: getStatus(sp.datefmt("MM-dd HH-mm", item.KSSJ), sp.datefmt("MM-dd HH-mm", item.JSSJ)),
  174. title: item.HYMC
  175. })
  176. })
  177. self.application.forEach(function (item, index) {
  178. item.msg = item.start + "—" + item.end + " " + " " + item.dpname + " " + item.username;
  179. item.show = true;
  180. item.showRoom = false;
  181. item.showDate = false;
  182. item.style = {
  183. "background-color": "",
  184. "text-align": "center",
  185. "color": "white",
  186. "font-size": "14px",
  187. "font-weight": 600,
  188. "padding": 0,
  189. "position": "absolute",
  190. "left": 0,
  191. "top": 0,
  192. "width": 200,
  193. "height": 0,
  194. }
  195. item.style["background-color"] = getColor(item.status);
  196. self.huiyiRoom.forEach(function (item1, index1) {
  197. if (item.fjh == item1.name) {
  198. item.style.left = index1 * 200 + 200;
  199. item.showRoom = true;
  200. }
  201. })
  202. self.week.forEach(function (item1, index1) {
  203. var n1 = 0, n2 = 0, n3 = 0, n4 = 0;
  204. if ((item.date.split(".")[0] < 10 ? "0" + item.date : item.date) == item1.date) {
  205. if (item.start.slice(0, 2) == item1.time.slice(0, 2)) {
  206. n1 = index1 * 50;
  207. n2 = 50 - item.start.slice(3) * 1 / 60 * 50;
  208. item.style.top = n1 + n2;
  209. }
  210. item.style.height = (item.end.slice(0, 2) * 1 - item.start.slice(0, 2) * 1) * 50 + (item.end.slice(3) * 1 - item.start.slice(3) * 1) / 60 * 50;
  211. item.showDate = true;
  212. }
  213. })
  214. item.style.padding = (item.style.height - 36) / 2 + "px 0";
  215. item.show = item.showRoom == true && item.showDate == true
  216. })
  217. console.log(res.data)
  218. console.log(self.application)
  219. console.log(self.huiyiRoom)
  220. })
  221. }
  222. //头部下滚冻结
  223. $(function () {
  224. //页面高度撑满
  225. setTimeout(function () {
  226. if ($(".ibox-content").height() < $(window).height() - 31) {
  227. $(".ibox-content").css("height", $(window).height() - 31)
  228. }
  229. }, 1)
  230. $(".huiyi-table").parent().css("max-height", $(window).height() - 130)
  231. })
  232. }])
  233. app.directive("repeatFinish", function () {
  234. return {
  235. link: function (scope) {
  236. if (scope.$last == true) {
  237. setTimeout(function () {
  238. $(".sp-table").rowspan(0)
  239. }, 10);
  240. }
  241. }
  242. };
  243. });
  244. function getStatus(time1,time2) {
  245. var ctime = sp.datefmt("MM-dd HH:mm", sp.getLocalDate());
  246. if (ctime <= time1) {
  247. return 3
  248. } else if (ctime >= time1 && ctime <= time2) {
  249. return 2
  250. } else if (ctime >= time2) {
  251. return 1
  252. }
  253. }
  254. function getColor(n) {
  255. var color = "";
  256. switch (n) {
  257. case 1: color = "#CCCCCC"; break;
  258. case 2: color = "#00CC66"; break;
  259. case 3: color = "#0099FF"; break;
  260. case 4: color = "#CC0000"; break;
  261. }
  262. return color;
  263. }
  264. jQuery.fn.rowspan = function (colIdx) { //封装的一个JQuery小插件
  265. return this.each(function () {
  266. var that, rowspan;
  267. $('tr', this).each(function (row) {
  268. $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
  269. if (that != null && $(this).html() == $(that).html()) {
  270. rowspan = $(that).attr("rowSpan");
  271. if (rowspan == undefined) {
  272. $(that).attr("rowSpan", 1);
  273. rowspan = $(that).attr("rowSpan");
  274. }
  275. rowspan = Number(rowspan) + 1;
  276. $(that).attr("rowSpan", rowspan);
  277. $(this).remove();
  278. } else {
  279. that = this;
  280. }
  281. });
  282. });
  283. });
  284. }