map - 副本.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. uni.showToast({
  105. title: "暂未有该商户信息",
  106. });
  107. //console.log(e);
  108. this.showMarkerWindow = false;
  109. this.markerId = e.detail.markerId;
  110. var item = this.data.find(v => v.company_id == this.markerId);
  111. //console.log(item);
  112. if (item) {
  113. this.getTargetInfo(item);
  114. } else {
  115. uni.showToast({
  116. title: "暂未有该商户信息",
  117. });
  118. }
  119. },
  120. getTargetInfo(item) {
  121. this.targetInfo.name = item.name;
  122. this.targetInfo.address = item.address;
  123. this.targetInfo.corporation_name = item.corporation_name;
  124. this.targetInfo.phone = item.phone;
  125. this.targetInfo.smoke = item.smoke;
  126. this.targetInfo.smoke_over = item.smoke_over;
  127. this.targetInfo.voc_density = item.voc_density;
  128. this.targetInfo.voc_over = item.voc_over;
  129. this.showMarkerWindow = true;
  130. },
  131. },
  132. };
  133. </script>
  134. <style lang="scss">
  135. .map-box {
  136. width: 100%;
  137. height: calc(100vh - 94px);
  138. overflow: hidden;
  139. .map {
  140. width: 100%;
  141. height: calc(100vh - 72px);
  142. }
  143. }
  144. // #ifndef H5
  145. .map-box {
  146. height: calc(100vh - 44px);
  147. .map {
  148. height: calc(100vh - 22px);
  149. }
  150. }
  151. // #endif
  152. // #ifdef H5
  153. .map-box {
  154. height: calc(100vh - 94px);
  155. .map {
  156. height: calc(100vh - 72px);
  157. }
  158. }
  159. // #endif
  160. .marker-info {
  161. background: #fff;
  162. height: 265px;
  163. width: calc(100vw - 30px);
  164. position: absolute;
  165. bottom: 50px;
  166. display: flex;
  167. flex-direction: column;
  168. padding: 15px;
  169. border-radius: 10px 10px 0 0;
  170. border-top: 5px solid $uni-color-primary;
  171. border-bottom: none;
  172. background-color: #f5f5f5;
  173. .close-btn {
  174. position: absolute;
  175. right: 5px;
  176. top: 5px;
  177. width: 30px;
  178. height: 30px;
  179. cursor: pointer;
  180. background-color: $uni-color-primary;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. border-radius: 50%;
  185. z-index: 1000;
  186. image {
  187. width: 100%;
  188. height: 100%;
  189. }
  190. }
  191. }
  192. </style>