map.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view>
  3. <view class="map-box"><map scale="12" class="map" :latitude="latitude" :longitude="longitude" @markertap="markerClick" :markers="markers" style=""></map></view>
  4. <view v-if="showMarkerWindow" class="marker-info">
  5. <view class="close-btn" @click="showMarkerWindow = false"><image src="/static/image/close.png"></image></view>
  6. <scroll-view scroll-y="true" style="height: 100%;">
  7. <u-cell-group>
  8. <u-cell :title="targetInfo.name" :label="targetInfo.address"></u-cell>
  9. <u-cell title="联系人" :label="targetInfo.corporation_name" :value="targetInfo.phone"></u-cell>
  10. <u-cell title="油烟" :label="targetInfo.smoke" :value="'超标:' + targetInfo.smoke_over"></u-cell>
  11. <u-cell title="颗粒物" :label="targetInfo.voc_density" :value="'超标:' + targetInfo.voc_over"></u-cell>
  12. </u-cell-group>
  13. </scroll-view>
  14. </view>
  15. <tabbar :currentTab="1"></tabbar>
  16. </view>
  17. </template>
  18. <script>
  19. import api from "@/common/api.js";
  20. import { log } from "@/utils/base.js";
  21. import tabbar from "@/components/tabbar";
  22. export default {
  23. components: {
  24. tabbar,
  25. },
  26. data() {
  27. return {
  28. markerId: 0,
  29. latitude: 31.98774,
  30. longitude: 118.810091,
  31. data: [],
  32. markers: [
  33. // {
  34. // latitude: 39.909,
  35. // longitude: 116.39742,
  36. // width: 30,
  37. // height: 30,
  38. // iconPath: "/static/image/blue-location.png",
  39. // },
  40. ],
  41. search: {
  42. pageIndex: 1,
  43. pageSize: 10000,
  44. params: {
  45. org_id: "",
  46. },
  47. },
  48. targetInfo: {},
  49. showMarkerWindow: false,
  50. };
  51. },
  52. onLoad(opt) {
  53. this.id = opt.id ? decodeURIComponent(opt.id) : "";
  54. const title = opt.name ? decodeURIComponent(opt.name) : "";
  55. if (title) {
  56. uni.setNavigationBarTitle({
  57. title: `在线监测 — ${title}`,
  58. });
  59. }
  60. },
  61. mounted() {
  62. this.getOrg();
  63. },
  64. methods: {
  65. getOrg() {
  66. api.getOrgList().then(({ data }) => {
  67. this.search.params.org_id = data[0].key;
  68. this.getInfo();
  69. });
  70. },
  71. getInfo() {
  72. api.getCompanyListByOrg(this.search).then(({ rows, total }) => {
  73. this.data = rows;
  74. if (rows && rows.length) {
  75. let row = undefined;
  76. rows.forEach(v => {
  77. if (v.company_id == this.id) {
  78. row = v;
  79. }
  80. const mark = {
  81. id: v.company_id,
  82. latitude: v.latitude,
  83. longitude: v.longitude,
  84. width: 30,
  85. height: 30,
  86. iconPath: v.run_state == 0 ? "/static/image/blue-location.png" : "/static/image/red-location.png",
  87. // customCallout: {
  88. // anchorX: -1,
  89. // anchorY: 46,
  90. // display: "ALWAYS",
  91. // },
  92. };
  93. this.markers.push(mark);
  94. });
  95. row = row || rows[0];
  96. if (row) {
  97. this.latitude = row.latitude;
  98. this.longitude = row.longitude;
  99. }
  100. }
  101. });
  102. },
  103. markerClick(e) {
  104. //console.log(e);
  105. this.showMarkerWindow = false;
  106. this.markerId = e.detail.markerId;
  107. var item = this.data.find(v => v.company_id == this.markerId);
  108. //console.log(item);
  109. if (item) {
  110. this.getTargetInfo(item);
  111. } else {
  112. uni.showToast({
  113. title: "暂未有该商户信息",
  114. });
  115. }
  116. },
  117. getTargetInfo(item) {
  118. this.targetInfo.name = item.name;
  119. this.targetInfo.address = item.address;
  120. this.targetInfo.corporation_name = item.corporation_name;
  121. this.targetInfo.phone = item.phone;
  122. this.targetInfo.smoke = item.smoke;
  123. this.targetInfo.smoke_over = item.smoke_over;
  124. this.targetInfo.voc_density = item.voc_density;
  125. this.targetInfo.voc_over = item.voc_over;
  126. this.showMarkerWindow = true;
  127. },
  128. },
  129. };
  130. </script>
  131. <style lang="scss">
  132. .map-box {
  133. width: 100%;
  134. height: calc(100vh - 94px);
  135. overflow: hidden;
  136. .map {
  137. width: 100%;
  138. height: calc(100vh - 72px);
  139. }
  140. }
  141. // #ifndef H5
  142. .map-box {
  143. height: calc(100vh - 44px);
  144. .map {
  145. height: calc(100vh - 22px);
  146. }
  147. }
  148. // #endif
  149. // #ifdef H5
  150. .map-box {
  151. height: calc(100vh - 94px);
  152. .map {
  153. height: calc(100vh - 72px);
  154. }
  155. }
  156. // #endif
  157. .marker-info {
  158. background: #fff;
  159. height: 265px;
  160. width: calc(100vw - 30px);
  161. position: absolute;
  162. bottom: 50px;
  163. display: flex;
  164. flex-direction: column;
  165. padding: 15px;
  166. border-radius: 10px 10px 0 0;
  167. border-top: 5px solid $uni-color-primary;
  168. border-bottom: none;
  169. background-color: #f5f5f5;
  170. .close-btn {
  171. position: absolute;
  172. right: 5px;
  173. top: 5px;
  174. width: 30px;
  175. height: 30px;
  176. cursor: pointer;
  177. background-color: $uni-color-primary;
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. border-radius: 50%;
  182. z-index: 1000;
  183. image {
  184. width: 100%;
  185. height: 100%;
  186. }
  187. }
  188. }
  189. </style>