map-index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $("#mapimg").css("height", $(window).height());
  18. $("#searchInput").focus(function () {
  19. });
  20. $scope.mapImgClick = function (e) {
  21. console.log(e.offsetX, e.offsetY);
  22. $scope.isShowMark = false;
  23. $scope.isShowNowModal = false;
  24. var img = $("#mapimg")[0];
  25. 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);
  26. if (buildingList.length > 0) {
  27. $scope.goBuilding(buildingList[0]);
  28. }
  29. };
  30. $scope.searchBuilding = function () {
  31. $scope.isShowMark = false;
  32. $scope.isShowNowModal = false;
  33. if ($scope.searchInput) {
  34. var buildingList = $scope.buildingXYAxisList.filter(x => x.BuildingName.indexOf($scope.searchInput) >= 0);
  35. if (buildingList.length > 0) {
  36. $scope.goBuilding(buildingList[0]);
  37. return;
  38. }
  39. var searchRoomList = $scope.allRoomList.filter(x => x.DepartmentOrServiceName.indexOf($scope.searchInput) >= 0);
  40. if (searchRoomList.length > 0) {
  41. var searchRoom = searchRoomList[0];
  42. buildingList = $scope.buildingXYAxisList.filter(x => x.BuildingId == searchRoom.BuildingId);
  43. if (buildingList.length > 0) {
  44. $scope.goBuilding(buildingList[0]);
  45. var searchFloor = $scope.floorList.filter(x => x.BuildingFloorId == searchRoom.BuildingFloorId);
  46. $timeout(function () {
  47. $scope.floorClick(searchFloor[0]);
  48. }, 500);
  49. }
  50. }
  51. }
  52. };
  53. $scope.goBuilding = function (building) {
  54. $scope.nowBuilding = building;
  55. $scope.floorList = $scope.allFloorList.filter(e => e.BuildingId == $scope.nowBuilding.BuildingId);
  56. $scope.roomList = $scope.allRoomList.filter(e => e.BuildingId == $scope.nowBuilding.BuildingId);
  57. var img = $("#mapimg")[0];
  58. $scope.nowPositionStyle.left = (img.offsetLeft + building.MinXAxis * img.width) + "px";
  59. $scope.nowPositionStyle.top = (img.offsetTop + building.MinYAxis * img.height) + "px";
  60. $scope.nowPositionStyle.width = (building.MaxXAxis * img.width - building.MinXAxis * img.width) + "px";
  61. $scope.nowPositionStyle.height = (building.MaxYAxis * img.height - building.MinYAxis * img.height) + "px";
  62. $scope.coordinateStyle.left = (img.offsetLeft + building.XCenter * img.width - 22) + "px";
  63. $scope.coordinateStyle.top = (img.offsetTop + building.YCenter * img.height - 73) + "px";
  64. $scope.isShowMark = true;
  65. $scope.showModalType = 1;
  66. $timeout(function () {
  67. $scope.modalStyle.left = (img.offsetLeft + building.MaxXAxis * img.width) + "px";
  68. $scope.modalStyle.top = (img.offsetTop + building.MinYAxis * img.height) > 400 ? (img.offsetTop + building.MinYAxis * img.height - 420) : 20 + "px";
  69. $scope.isShowNowModal = true;
  70. }, 300);
  71. $timeout(function () {
  72. $scope.floorClick($scope.floorList[0]);
  73. }, 500);
  74. }
  75. $scope.floorClick = function (clickData) {
  76. var top = 10;
  77. var totalRoom = 0;
  78. var index = $.map($filter('filter')($scope.floorList, {}), function (x) { return x.BuildingFloorId; }).indexOf(clickData.BuildingFloorId);
  79. $scope.floorList.forEach((f, i) => {
  80. f.checked = clickData.Name == f.Name;
  81. if (i < index) {
  82. totalRoom += $scope.roomList.filter(e => e.FloorName == f.Name).length;
  83. }
  84. });
  85. $("#card-content").scrollTop(index == 0 ? 0 : (top + index * 20 + totalRoom * 40));
  86. };
  87. // 定义滚动事件的处理函数
  88. var scrollHandler = function () {
  89. var scrollTop = $("#card-content").scrollTop();
  90. var top = 10;
  91. var totalRoom = 0;
  92. $scope.floorList.forEach((f, i) => {
  93. $scope.roomList.filter(e => e.BuildingFloorId == f.BuildingFloorId).forEach((r, k) => {
  94. r.scrollTop = (i == 0 && k == 0) ? top : (top + i * 20 + totalRoom * 40);
  95. totalRoom += 1;
  96. });
  97. });
  98. var scrollRoom = $scope.roomList.filter(e => e.scrollTop >= scrollTop);
  99. if (scrollRoom.length > 0) {
  100. $scope.floorList.forEach((f, i) => {
  101. f.checked = scrollRoom[0].BuildingFloorId == f.BuildingFloorId;
  102. });
  103. }
  104. $scope.$apply();
  105. };
  106. angular.element($("#card-content")).on('scroll', scrollHandler);
  107. $scope.showModal = function () {
  108. $scope.isShowNowModal = true;
  109. $scope.showModalType = 1;
  110. };
  111. $scope.showRoom = function (room) {
  112. $scope.roomModel = room;
  113. $scope.showModalType = 2;
  114. };
  115. $scope.coloseRoom = function () {
  116. $scope.showModalType = 1;
  117. };
  118. $scope.isHightlight = function (room) {
  119. 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));
  120. };
  121. //加载列表数据
  122. $scope.getBuildingXYAxisList = function () {
  123. $http
  124. ({
  125. method: 'get', url: '../../api/build/building/GetBuildingXyAxisGroupList', params: {}
  126. }).then(function (result) {
  127. $scope.buildingXYAxisList = result.data.Data;
  128. }, function (resp) {
  129. });
  130. };
  131. $scope.getFloorList = function () {
  132. $http({
  133. method: "get",
  134. url: "../../api/build/building/GetFloorList",
  135. params: {
  136. }
  137. }).then(function (result) {
  138. $scope.allFloorList = result.data.Data;
  139. }, function (resp) {
  140. });
  141. };
  142. $scope.getRoomDepOrServiceList = function () {
  143. $http({
  144. method: "get",
  145. url: "../../api/build/room/GetRoomDepOrServiceList",
  146. params: {
  147. }
  148. }).then(function (result) {
  149. $scope.allRoomList = result.data.Data;
  150. }, function (resp) {
  151. });
  152. };
  153. $scope.getBuildingXYAxisList();
  154. $scope.getFloorList();
  155. $scope.getRoomDepOrServiceList();
  156. });
  157. })(angular);