map-index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. (function ($app) {
  2. $app.module('ylmis').controller('mapIndexCtrl', function ($scope, $http, $filter, $modal, $ocLazyLoad, $alert, $loading, $state, excelPopup, $bsRouterState, popupReport, $timeout) {
  3. $scope.buildingXYAxisList = [];
  4. $scope.searchInput = "";
  5. $scope.nowPositionStyle = { "left": "0", "top": "0", "width": "0", "height": "0" };
  6. $scope.coordinateStyle = { "left": "0", "top": "0" };
  7. $scope.modalStyle = { "left": "0", "top": "0" };
  8. $scope.isShowMark = false;
  9. $scope.isShowNowModal = false;
  10. $scope.showModalType = 1;
  11. $scope.nowBuilding = {};
  12. $scope.allFloorList = [];
  13. $scope.allRoomList = [];
  14. $scope.floorList = [];
  15. $scope.roomList = [];
  16. $scope.roomModel = [];
  17. $scope.searchList = [];
  18. $scope.isShowSearchList = false;
  19. $("#mapimg").css("height", $(window).height());
  20. $("#searchInput").focus(function () {
  21. });
  22. $scope.mapImgClick = function (e) {
  23. console.log(e.offsetX, e.offsetY);
  24. $scope.isShowMark = false;
  25. $scope.isShowNowModal = false;
  26. var img = $("#mapimg")[0];
  27. var buildingList = $scope.buildingXYAxisList.filter(x => e.offsetX >= x.MinXAxis * img.width && e.offsetX <= x.MaxXAxis * img.width && e.offsetY >= x.MinYAxis * img.height && e.offsetY <= x.MaxYAxis * img.height);
  28. if (buildingList.length > 0) {
  29. $scope.goBuilding(buildingList[0]);
  30. }
  31. };
  32. $scope.searchBuilding = function () {
  33. $scope.isShowMark = false;
  34. $scope.isShowNowModal = false;
  35. if ($scope.searchInput) {
  36. /*var buildingList = $scope.buildingXYAxisList.filter(x => x.BuildingName.indexOf($scope.searchInput) >= 0);
  37. if (buildingList.length > 0) {
  38. $scope.goBuilding(buildingList[0]);
  39. return;
  40. }*/
  41. var searchRoomList = $scope.allRoomList.filter(x => x.DepartmentOrServiceName.indexOf($scope.searchInput) >= 0);
  42. /*if (searchRoomList.length > 0) {
  43. var searchRoom = searchRoomList[0];
  44. buildingList = $scope.buildingXYAxisList.filter(x => x.BuildingId == searchRoom.BuildingId);
  45. if (buildingList.length > 0) {
  46. $scope.goBuilding(buildingList[0]);
  47. var searchFloor = $scope.floorList.filter(x => x.BuildingFloorId == searchRoom.BuildingFloorId);
  48. $timeout(function () {
  49. $scope.floorClick(searchFloor[0]);
  50. }, 500);
  51. }
  52. }*/
  53. $scope.searchList = [];
  54. searchRoomList.forEach(r => {
  55. var building = $scope.buildingXYAxisList.filter(e => e.BuildingId == r.BuildingId);
  56. if (building.length > 0)
  57. $scope.searchList.push({ BuildingFloorId: r.BuildingFloorId, BuildingId: r.BuildingId, RoomName: r.RoomName, DepartmentOrServiceName: r.DepartmentOrServiceName, FloorName: r.FloorName, BuildingName: building.length > 0 ? building[0].BuildingName : "" });
  58. });
  59. $scope.isShowSearchList = $scope.searchList.length > 0;
  60. }
  61. };
  62. $scope.clickSearchRoom = function (room) {
  63. $scope.isShowSearchList = false;
  64. var buildingList = $scope.buildingXYAxisList.filter(x => x.BuildingId == room.BuildingId);
  65. if (buildingList.length > 0) {
  66. $scope.goBuilding(buildingList[0]);
  67. var searchFloor = $scope.floorList.filter(x => x.BuildingFloorId == room.BuildingFloorId);
  68. $timeout(function () {
  69. $scope.floorClick(searchFloor[0]);
  70. }, 500);
  71. }
  72. };
  73. $scope.goBuilding = function (building) {
  74. $scope.nowBuilding = building;
  75. $scope.floorList = $scope.allFloorList.filter(e => e.BuildingId == $scope.nowBuilding.BuildingId);
  76. $scope.roomList = $scope.allRoomList.filter(e => e.BuildingId == $scope.nowBuilding.BuildingId);
  77. var img = $("#mapimg")[0];
  78. $scope.nowPositionStyle.left = (img.offsetLeft + building.MinXAxis * img.width) + "px";
  79. $scope.nowPositionStyle.top = (img.offsetTop + building.MinYAxis * img.height) + "px";
  80. $scope.nowPositionStyle.width = (building.MaxXAxis * img.width - building.MinXAxis * img.width) + "px";
  81. $scope.nowPositionStyle.height = (building.MaxYAxis * img.height - building.MinYAxis * img.height) + "px";
  82. $scope.coordinateStyle.left = (img.offsetLeft + building.XCenter * img.width - 22) + "px";
  83. $scope.coordinateStyle.top = (img.offsetTop + building.YCenter * img.height - 73) + "px";
  84. $scope.isShowMark = true;
  85. $scope.showModalType = 1;
  86. $timeout(function () {
  87. $scope.modalStyle.left = (img.offsetLeft + building.MaxXAxis * img.width) + "px";
  88. $scope.modalStyle.top = (img.offsetTop + building.MinYAxis * img.height) > 400 ? (img.offsetTop + building.MinYAxis * img.height - 420) : 20 + "px";
  89. $scope.isShowNowModal = true;
  90. }, 300);
  91. $timeout(function () {
  92. $scope.floorClick($scope.floorList[0]);
  93. }, 500);
  94. }
  95. $scope.floorClick = function (clickData) {
  96. var top = 10;
  97. var totalRoom = 0;
  98. var index = $.map($filter('filter')($scope.floorList, {}), function (x) { return x.BuildingFloorId; }).indexOf(clickData.BuildingFloorId);
  99. $scope.floorList.forEach((f, i) => {
  100. f.checked = clickData.Name == f.Name;
  101. if (i < index) {
  102. totalRoom += $scope.roomList.filter(e => e.FloorName == f.Name).length;
  103. }
  104. });
  105. $("#card-content").scrollTop(index == 0 ? 0 : (top + index * 20 + totalRoom * 40));
  106. };
  107. // 定义滚动事件的处理函数
  108. var scrollHandler = function () {
  109. var scrollTop = $("#card-content").scrollTop();
  110. var top = 10;
  111. var totalRoom = 0;
  112. $scope.floorList.forEach((f, i) => {
  113. $scope.roomList.filter(e => e.BuildingFloorId == f.BuildingFloorId).forEach((r, k) => {
  114. r.scrollTop = (i == 0 && k == 0) ? top : (top + i * 20 + totalRoom * 40);
  115. totalRoom += 1;
  116. });
  117. });
  118. var scrollRoom = $scope.roomList.filter(e => e.scrollTop >= scrollTop);
  119. if (scrollRoom.length > 0) {
  120. $scope.floorList.forEach((f, i) => {
  121. f.checked = scrollRoom[0].BuildingFloorId == f.BuildingFloorId;
  122. });
  123. }
  124. $scope.$apply();
  125. };
  126. angular.element($("#card-content")).on('scroll', scrollHandler);
  127. $scope.showModal = function () {
  128. $scope.isShowNowModal = true;
  129. $scope.showModalType = 1;
  130. };
  131. $scope.showRoom = function (room) {
  132. $scope.roomModel = room;
  133. $scope.showModalType = 2;
  134. };
  135. $scope.coloseRoom = function () {
  136. $scope.showModalType = 1;
  137. };
  138. $scope.isHightlight = function (room) {
  139. return $scope.searchInput != '' && ((room.RoomName != null && room.RoomName != '' && room.RoomName.indexOf($scope.searchInput) >= 0) || (room.DepartmentOrServiceName != null && room.DepartmentOrServiceName != '' && room.DepartmentOrServiceName.indexOf($scope.searchInput) >= 0));
  140. };
  141. $(document).on('touchstart', function (e) {
  142. // touch start event handler code here
  143. });
  144. $(document).on('touchmove', function (e) {
  145. // touch move event handler code here
  146. });
  147. $(document).on('touchend', function (e) {
  148. // touch end event handler code here
  149. });
  150. $scope.backMap = function () {
  151. $state.go("map");
  152. };
  153. //加载列表数据
  154. $scope.getBuildingXYAxisList = function () {
  155. $http
  156. ({
  157. method: 'get', url: '../../api/build/building/GetBuildingXyAxisGroupList', params: {}
  158. }).then(function (result) {
  159. $scope.buildingXYAxisList = result.data.Data;
  160. }, function (resp) {
  161. });
  162. };
  163. $scope.getFloorList = function () {
  164. $http({
  165. method: "get",
  166. url: "../../api/build/building/GetFloorList",
  167. params: {
  168. }
  169. }).then(function (result) {
  170. $scope.allFloorList = result.data.Data;
  171. }, function (resp) {
  172. });
  173. };
  174. $scope.getRoomDepOrServiceList = function () {
  175. $http({
  176. method: "get",
  177. url: "../../api/build/room/GetRoomDepOrServiceList",
  178. params: {
  179. }
  180. }).then(function (result) {
  181. $scope.allRoomList = result.data.Data;
  182. }, function (resp) {
  183. });
  184. };
  185. $scope.getBuildingXYAxisList();
  186. $scope.getFloorList();
  187. $scope.getRoomDepOrServiceList();
  188. //全屏自适应
  189. /*$(document).on('keydown', function (e) {
  190. var e = event || window.event || arguments.callee.caller.arguments[0];
  191. if (e && e.keyCode == 122) {//捕捉F11键盘动作
  192. e.preventDefault(); //阻止F11默认动作
  193. var el = document.documentElement;
  194. var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;//定义不同浏览器的全屏API      //执行全屏
  195. if (typeof rfs != "undefined" && rfs) {
  196. rfs.call(el);
  197. } else if (typeof window.ActiveXObject != "undefined") {
  198. var wscript = new ActiveXObject("WScript.Shell");
  199. if (wscript != null) {
  200. wscript.SendKeys("{F11}");
  201. }
  202. }
  203. }
  204. });
  205. //监听不同浏览器的全屏事件,并件执行相应的代码
  206. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange msfullscreenchange', function (e) {
  207. if (document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement) {
  208. // 当前处于全屏状态
  209. console.log("已经进入全屏");
  210. $scope.isShowMark = false;
  211. $scope.isShowNowModal = false;
  212. $scope.isShowSearchList = false;
  213. $("#mapimg").css("height", $(window).height());
  214. } else {
  215. // 不在全屏状态
  216. console.log("已经退出全屏");
  217. $scope.isShowMark = false;
  218. $scope.isShowNowModal = false;
  219. $scope.isShowSearchList = false;
  220. $("#mapimg").css("height", $(window).height());
  221. }
  222. $scope.$apply();
  223. });*/
  224. });
  225. })(angular);