index_20240525093445.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="body shh_body">
  3. <div class="header">
  4. <h1 class="header_title">松花湖景区通</h1>
  5. <span class="time">{{ currentTime }}</span>
  6. </div>
  7. <div id="parkCar" class="shh_part parkinglot">
  8. <div class="shh_part_div" v-for="(item,index) in parkingLots" :key="index">
  9. <img :src="getImgUrl(item.parkId)"/>
  10. <div class="shh_txt">
  11. <h1>{{ getParkingLotName(item.parkId) }}</h1>
  12. <table style="width: 100%;color: white;border-collapse: collapse;">
  13. <tr>
  14. <td>总车位数:{{ item.allSpaceNumber }}</td>
  15. </tr>
  16. <tr>
  17. <td>剩余车位:{{ item.remainSpaceNumber }}</td>
  18. <td style="padding: 0 25px;">已用车位:{{ item.useSpaceNumber }}</td>
  19. </tr>
  20. <tr>
  21. <td>当天出场车辆:{{ item.outParkCount }}</td>
  22. <td style="padding: 0 25px;">当前在场车辆:{{ item.inParkCount }}</td>
  23. </tr>
  24. <tr>
  25. <td>当天线下支付金额:{{ item.totalOutMoney }}</td>
  26. <td style="padding: 0 25px;">当天网络支付金额:{{ item.totalPreMoney }}</td>
  27. </tr>
  28. </table>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="selectDate">
  33. <div class="_moreMenu">
  34. <ul id="myList" class="listContain">
  35. </ul>
  36. </div>
  37. </div>
  38. <!--游船视图页面-->
  39. <div id="map"></div>
  40. </div>
  41. </template>
  42. <script>
  43. import {getGpsByDid, getShipRoute} from "@/api/ship/shipMapping";
  44. import {getParkData} from "@/api/park/parkLot";
  45. export default {
  46. name: "songhuaIndex",
  47. data() {
  48. return {
  49. dataSource: [],
  50. parkingLots: [],
  51. map: [],
  52. currentTime: ''
  53. }
  54. },
  55. mounted() {
  56. // 初始加载时间
  57. this.getCurrentTime();
  58. // 每秒刷新时间
  59. setInterval(() => {
  60. this.getCurrentTime();
  61. }, 1000);
  62. setInterval(() => {
  63. this.fetchParkingLots();
  64. }, 1000 * 60 * 2);
  65. },
  66. created() {
  67. this.handler();
  68. this.fetchParkingLots();
  69. },
  70. methods: {
  71. getCurrentTime() {
  72. const now = new Date();
  73. const year = now.getFullYear();
  74. const month = now.getMonth() + 1;
  75. const date = now.getDate();
  76. const day = now.getDay();
  77. const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  78. const hour = now.getHours();
  79. const minute = now.getMinutes();
  80. const second = now.getSeconds();
  81. const formattedMonth = month < 10 ? `0${month}` : month;
  82. const formattedDate = date < 10 ? `0${date}` : date;
  83. const formattedHour = hour < 10 ? `0${hour}` : hour;
  84. const formattedMinute = minute < 10 ? `0${minute}` : minute;
  85. const formattedSecond = second < 10 ? `0${second}` : second;
  86. this.currentTime = `${year}年${formattedMonth}月${formattedDate}日 ${weekDays[day]} ${formattedHour}:${formattedMinute}:${formattedSecond}`;
  87. },
  88. fetchParkingLots() {
  89. getParkData().then(response => {
  90. this.parkingLots = response.data;
  91. })
  92. },
  93. getImgUrl(parkId) {
  94. switch (parkId) {
  95. case "15305":
  96. return require("@/assets/images/shh_part" + 1 + ".png");
  97. case "15338":
  98. return require("@/assets/images/shh_part" + 2 + ".png");
  99. // 可以继续添加其他停车场的情况
  100. // default:
  101. // return "未知停车场";
  102. }
  103. },
  104. getParkingLotName(parkId) {
  105. // 在这里根据 parkId 返回停车场名称
  106. switch (parkId) {
  107. case "15305":
  108. return "一号松花湖停车场";
  109. case "15338":
  110. return "二号松花湖停车场";
  111. // 可以继续添加其他停车场的情况
  112. // default:
  113. // return "未知停车场";
  114. }
  115. },
  116. //地图
  117. handler() {
  118. getShipRoute().then(res => {
  119. let that = this
  120. if (res.code == 200) {
  121. that.dataSource = res.data
  122. let ul;
  123. let dataList = that.dataSource
  124. that.map = new BMap.Map('map'); // 创建Map实例
  125. that.map.centerAndZoom(new BMap.Point(126.85912, 43.671033), 13); // 初始化地图,设置中心点坐标和地图级别
  126. that.map.enableScrollWheelZoom(true);
  127. let mapStyle = {
  128. style: 'midnight',
  129. };
  130. // document.querySelector('.anchorBL').style.display = 'none';
  131. const HTMLCollections = document.querySelectorAll('.anchorBL')
  132. HTMLCollections[0].style.display = 'none';
  133. // [0,0].forEach((e,idx) => {
  134. // HTMLCollections[idx].style.display = 'none'
  135. // })
  136. that.map.setMapStyle(mapStyle);
  137. for (let i = 0; i < dataList.length; i++) {
  138. let pointArray = [];
  139. for (let j = 0; j < dataList[i].polylinePath.length; j++) {
  140. pointArray.push(new BMap.Point(dataList[i].polylinePath[j].lng, dataList[i].polylinePath[j].lat))
  141. }
  142. // 创建小船图标
  143. var myIcon = new BMap.Icon(require("@/assets/images/ship.png"), new BMap.Size(52, 26));
  144. var marker = new BMap.Marker(new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat), {icon: myIcon}); // 创建点
  145. var opts = {
  146. width: 100, // 信息窗口宽度
  147. height: 80, // 信息窗口高度
  148. title: "游船信息", // 信息窗口标题
  149. }
  150. // marker添加点击事件
  151. marker.addEventListener('mouseover', function () {
  152. this.map.openInfoWindow(new BMap.InfoWindow("游船名称:" + dataList[i].shipName + "</br>" + "游船型号:" + dataList[i].shipType + "</br>" + "驱动类型:" + dataList[i].propulsion + "</br>", opts), new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat));
  153. });
  154. marker.addEventListener('mouseout', function () {
  155. this.map.closeInfoWindow();
  156. });
  157. this.map.addOverlay(marker);
  158. }
  159. ul = document.getElementById('myList');
  160. // 循环数组中的每个项目
  161. dataList.concat(dataList).forEach(function (item) {
  162. // 创建一个新的li元素
  163. var li = document.createElement('li');
  164. // 设置li元素的内容
  165. li.textContent = item.shipName;
  166. li.style.transform = 'translateX(22px)';
  167. li.style.cursor = 'pointer';
  168. // 添加点击事件处理程序
  169. li.addEventListener('click', (e) => {
  170. // 重置状态
  171. const liSets = document.getElementById('myList').getElementsByTagName('li')
  172. const length = liSets.length;
  173. for (var i = 0; i < length; i++) {
  174. liSets[i].style.color = '#3CDFFF';
  175. }
  176. // 在这里添加你想执行的点击事件代码
  177. that.selectGpsByDid(item.registrationNumber)
  178. console.log(e.target)
  179. e.target.style.color = '#fff'
  180. // 可以进行其他操作,如触发其他函数或改变元素样式等
  181. });
  182. // 将li元素添加到ul中
  183. ul.appendChild(li);
  184. });
  185. } else {
  186. that.$modal.msgError("查询失败");
  187. }
  188. })
  189. },
  190. selectGpsByDid(val) {
  191. this.map.clearOverlays();
  192. let marker;
  193. let polyline;
  194. let opts;
  195. getGpsByDid(val).then(res => {
  196. if (res.code == 200) {
  197. let dataList = res.data
  198. for (let i = 0; i < dataList.length; i++) {
  199. let pointArray = [];
  200. for (let j = 0; j < dataList[i].polylinePath.length; j++) {
  201. pointArray.push(new BMap.Point(dataList[i].polylinePath[j].lng, dataList[i].polylinePath[j].lat))
  202. }
  203. polyline = new BMap.Polyline(pointArray, {
  204. strokeColor: dataList[i].color,
  205. strokeWeight: 5,
  206. strokeOpacity: 0.5
  207. });//创建折线
  208. // 创建小船图标
  209. var myIcon = new BMap.Icon(require("@/assets/images/ship.png"), new BMap.Size(52, 26));
  210. marker = new BMap.Marker(new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat), {icon: myIcon}); // 创建点
  211. opts = {
  212. width: 100, // 信息窗口宽度
  213. height: 80, // 信息窗口高度
  214. title: "游船信息", // 信息窗口标题
  215. }
  216. // marker添加点击事件
  217. marker.addEventListener('mouseover', function () {
  218. this.map.openInfoWindow(new BMap.InfoWindow("游船名称:" + dataList[i].shipName + "</br>" + "游船型号:" + dataList[i].shipType + "</br>" + "驱动类型:" + dataList[i].propulsion + "</br>", opts), new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat));
  219. });
  220. marker.addEventListener('mouseout', function () {
  221. this.map.closeInfoWindow();
  222. });
  223. this.map.addOverlay(polyline);
  224. this.map.addOverlay(marker);
  225. }
  226. } else {
  227. this.$modal.msgError("查询失败");
  228. }
  229. })
  230. }
  231. },
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. @import "@/assets/styles/shh_body.scss";
  236. @import "@/assets/styles/shh_index.scss";
  237. .listContain{
  238. height: 465px;
  239. overflow: hidden;
  240. overflow-y: scroll;
  241. }
  242. .listContain::-webkit-scrollbar{
  243. display: none;
  244. }
  245. .parkinglot{
  246. background: rgba(0, 0, 0, 0.5) !important;
  247. }
  248. .anchorBL{
  249. display: none !important;
  250. }
  251. .BMap_cpyCtrl{
  252. display: none !important;
  253. }
  254. </style>