index_20240524160308.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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">
  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. that.map.setMapStyle(mapStyle);
  131. for (let i = 0; i < dataList.length; i++) {
  132. let pointArray = [];
  133. for (let j = 0; j < dataList[i].polylinePath.length; j++) {
  134. pointArray.push(new BMap.Point(dataList[i].polylinePath[j].lng, dataList[i].polylinePath[j].lat))
  135. }
  136. // 创建小船图标
  137. var myIcon = new BMap.Icon(require("@/assets/images/ship.png"), new BMap.Size(52, 26));
  138. var marker = new BMap.Marker(new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat), {icon: myIcon}); // 创建点
  139. var opts = {
  140. width: 100, // 信息窗口宽度
  141. height: 80, // 信息窗口高度
  142. title: "游船信息", // 信息窗口标题
  143. }
  144. // marker添加点击事件
  145. marker.addEventListener('mouseover', function () {
  146. 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));
  147. });
  148. marker.addEventListener('mouseout', function () {
  149. this.map.closeInfoWindow();
  150. });
  151. this.map.addOverlay(marker);
  152. }
  153. ul = document.getElementById('myList');
  154. // 循环数组中的每个项目
  155. dataList.concat(dataList).forEach(function (item) {
  156. // 创建一个新的li元素
  157. var li = document.createElement('li');
  158. // 设置li元素的内容
  159. li.textContent = item.shipName;
  160. li.style.transform = 'translateX(22px)';
  161. li.style.cursor = 'pointer';
  162. // 添加点击事件处理程序
  163. li.addEventListener('click', (e) => {
  164. // 在这里添加你想执行的点击事件代码
  165. that.selectGpsByDid(item.registrationNumber)
  166. console.log(e.target)
  167. e.target.style.color = '#fff'
  168. // 可以进行其他操作,如触发其他函数或改变元素样式等
  169. });
  170. // 将li元素添加到ul中
  171. ul.appendChild(li);
  172. });
  173. } else {
  174. that.$modal.msgError("查询失败");
  175. }
  176. })
  177. },
  178. selectGpsByDid(val) {
  179. this.map.clearOverlays();
  180. let marker;
  181. let polyline;
  182. let opts;
  183. getGpsByDid(val).then(res => {
  184. if (res.code == 200) {
  185. let dataList = res.data
  186. for (let i = 0; i < dataList.length; i++) {
  187. let pointArray = [];
  188. for (let j = 0; j < dataList[i].polylinePath.length; j++) {
  189. pointArray.push(new BMap.Point(dataList[i].polylinePath[j].lng, dataList[i].polylinePath[j].lat))
  190. }
  191. polyline = new BMap.Polyline(pointArray, {
  192. strokeColor: dataList[i].color,
  193. strokeWeight: 5,
  194. strokeOpacity: 0.5
  195. });//创建折线
  196. // 创建小船图标
  197. var myIcon = new BMap.Icon(require("@/assets/images/ship.png"), new BMap.Size(52, 26));
  198. marker = new BMap.Marker(new BMap.Point(dataList[i].polylinePath[0].lng, dataList[i].polylinePath[0].lat), {icon: myIcon}); // 创建点
  199. opts = {
  200. width: 100, // 信息窗口宽度
  201. height: 80, // 信息窗口高度
  202. title: "游船信息", // 信息窗口标题
  203. }
  204. // marker添加点击事件
  205. marker.addEventListener('mouseover', function () {
  206. 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));
  207. });
  208. marker.addEventListener('mouseout', function () {
  209. this.map.closeInfoWindow();
  210. });
  211. this.map.addOverlay(polyline);
  212. this.map.addOverlay(marker);
  213. }
  214. } else {
  215. this.$modal.msgError("查询失败");
  216. }
  217. })
  218. }
  219. },
  220. }
  221. </script>
  222. <style lang="scss" scoped>
  223. @import "@/assets/styles/shh_body.scss";
  224. @import "@/assets/styles/shh_index.scss";
  225. .listContain{
  226. height: 465px;
  227. overflow: hidden;
  228. overflow-y: scroll;
  229. }
  230. .listContain::-webkit-scrollbar{
  231. display: none;
  232. }
  233. </style>