map-index.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. //加载列表数据
  151. $scope.getBuildingXYAxisList = function () {
  152. $http
  153. ({
  154. method: 'get', url: '../../api/build/building/GetBuildingXyAxisGroupList', params: {}
  155. }).then(function (result) {
  156. $scope.buildingXYAxisList = result.data.Data;
  157. }, function (resp) {
  158. });
  159. };
  160. $scope.getFloorList = function () {
  161. $http({
  162. method: "get",
  163. url: "../../api/build/building/GetFloorList",
  164. params: {
  165. }
  166. }).then(function (result) {
  167. $scope.allFloorList = result.data.Data;
  168. }, function (resp) {
  169. });
  170. };
  171. $scope.getRoomDepOrServiceList = function () {
  172. $http({
  173. method: "get",
  174. url: "../../api/build/room/GetRoomDepOrServiceList",
  175. params: {
  176. }
  177. }).then(function (result) {
  178. $scope.allRoomList = result.data.Data;
  179. }, function (resp) {
  180. });
  181. };
  182. $scope.getBuildingXYAxisList();
  183. $scope.getFloorList();
  184. $scope.getRoomDepOrServiceList();
  185. });
  186. })(angular);