aid.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <template>
  2. <view class="content">
  3. <view id="map" class="map">
  4. <map @updated='mapChange' id="map_1" ref='map_1' style="width:750rpx; height: 600rpx" :latitude="latitude"
  5. :longitude="longitude" :markers="jhzmarker"></map>
  6. </view>
  7. <scroll-view scroll-y="true" class="scroll-wrapper" :style="{'height': height}" @scrolltolower="loadData">
  8. <espempty v-if="loaded && AEDList.length === 0" :tit="'救护站列表为空'"></espempty>
  9. <view class="list-tpl flex" @click="openAddress(item)" v-for="(item, index) in AEDList" :key="item.id">
  10. <template>
  11. <view class="list-left">
  12. <view class="info">
  13. <view class="title">{{ item.name }}</view>
  14. <view class="addr">地址:{{ item.address }}</view>
  15. </view>
  16. </view>
  17. <view class="image">
  18. <image src="../../static/img/img10.png"></image>
  19. <view class="tip" v-if="item.space > 999">>999m</view>
  20. <view class="tip" v-else>{{ item.space }}m</view>
  21. </view>
  22. </template>
  23. </view>
  24. <uni-load-more :status="loadtype"></uni-load-more>
  25. </scroll-view>
  26. <uni-popup ref="popup" type="bottom" @click="close">
  27. <view class="popup_row">
  28. <view class="rows">
  29. <view class="rows-item" @click="toGaodeMap">高德地图</view>
  30. <view class="rows-item" @click="tobaiDuMap">百度地图</view>
  31. <view class="rows-item" @click="totengxunMap">腾讯地图</view>
  32. </view>
  33. </view>
  34. </uni-popup>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. mapState,
  40. mapMutations
  41. } from 'vuex';
  42. import espempty from '@/components/espempty';
  43. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  44. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  45. import {
  46. getdis,
  47. tocall,
  48. getListMechanism
  49. } from '@/api/index.js';
  50. import {
  51. userinfo
  52. } from '@/api/user.js';
  53. import {
  54. getcomAddress
  55. } from '@/api/index.js';
  56. export default {
  57. components: {
  58. uniPopup,
  59. espempty,
  60. uniLoadMore
  61. },
  62. //相关配置参数
  63. data() {
  64. return {
  65. loaded: false,
  66. jhzmarker: [],
  67. loadtype: 'more',
  68. page: 1,
  69. limit: 10,
  70. AEDList: [],
  71. height: '',
  72. list: [],
  73. latitude: '',
  74. longitude: '',
  75. current: 0,
  76. name: '',
  77. uid: '',
  78. name: '',
  79. phone: '',
  80. to_phone: '',
  81. marker: [],
  82. specificAdd: '',
  83. addressData: {
  84. name: '',
  85. mobile: '',
  86. latitude: 0, //纬度
  87. longitude: 0, //经度
  88. address: {
  89. province: '',
  90. city: '',
  91. district: '',
  92. detail: '',
  93. },
  94. area: '',
  95. default: false
  96. },
  97. }
  98. },
  99. onReady(res) {
  100. var _this = this;
  101. uni.getSystemInfo({
  102. success: resu => {
  103. const query = uni.createSelectorQuery();
  104. query.select('.scroll-wrapper').boundingClientRect();
  105. query.exec(function(res) {
  106. console.log(res, 'ddddddddddddd');
  107. _this.height = resu.windowHeight - res[0].top + 'px';
  108. console.log('打印页面的剩余高度', _this.height);
  109. });
  110. },
  111. fail: res => {}
  112. });
  113. },
  114. onLoad() {
  115. let obj = this;
  116. console.log('开始加载事件');
  117. // obj.loadBaseData();
  118. // uni.showLoading({
  119. // title: '加载中',
  120. // mask: true
  121. // });
  122. // obj.loadData();
  123. try {
  124. let locationAddress
  125. // #ifdef H5
  126. let wxOjb = require('jweixin-module');
  127. locationAddress = wxOjb.getLocation;
  128. // #endif
  129. // #ifdef MP
  130. locationAddress = uni.getLocation;
  131. // #endif
  132. wxOjb.ready(() => {
  133. console.log('加载完毕注册事件');
  134. locationAddress({
  135. type: 'gcj02',
  136. success: function(res) {
  137. console.log('获取经纬度', res);
  138. obj.longitude = res.longitude
  139. obj.latitude = res.latitude
  140. obj.marker = [{
  141. latitude: obj.latitude,
  142. longitude: obj.longitude,
  143. iconPath: '/static/img/img19.png',
  144. width: '45',
  145. height: '45',
  146. }, ]
  147. obj.loadData();
  148. },
  149. fail(e) {
  150. console.log('失败', e);
  151. window.location.reload();
  152. }
  153. });
  154. })
  155. } catch (e) {
  156. console.log(e);
  157. let locationAddress
  158. // #ifdef H5
  159. let wxOjb = require('jweixin-module');
  160. locationAddress = wxOjb.getLocation;
  161. // #endif
  162. // #ifdef MP
  163. locationAddress = uni.getLocation;
  164. // #endif
  165. wxOjb.ready(() => {
  166. console.log('加载完毕注册事件');
  167. locationAddress({
  168. type: 'gcj02',
  169. success: function(res) {
  170. console.log('获取经纬度1', res);
  171. obj.longitude = res.longitude
  172. obj.latitude = res.latitude
  173. obj.loadData();
  174. },
  175. fail(e) {
  176. console.log('失败', e);
  177. }
  178. });
  179. })
  180. }
  181. },
  182. computed: {
  183. ...mapState('user', ['hasLogin', 'userInfo'])
  184. },
  185. methods: {
  186. ...mapMutations('user', ['setUserInfo']),
  187. // 地图渲染完毕事件
  188. mapChange(e) {
  189. console.log(e);
  190. },
  191. // 载入数据
  192. async loadData() {
  193. let obj = this;
  194. if (obj.loadtype == 'loading' || obj.loadtype == 'noMore') {
  195. return
  196. }
  197. getListMechanism({
  198. page: obj.page,
  199. limit: obj.limit,
  200. }).then(({
  201. data
  202. }) => {
  203. uni.hideLoading();
  204. console.log(data, 999);
  205. for (let i = 0; i < data.length; i++) {
  206. data[i].space = obj.space(obj.latitude, obj.longitude, data[i].latitude, data[i]
  207. .longitude);
  208. }
  209. let arr = data.map(item => ({
  210. latitude: item.latitude,
  211. longitude: item.longitude,
  212. iconPath: '/static/img/img014.png',
  213. width: '35',
  214. height: '35',
  215. id: item.id,
  216. address: item.address
  217. }));
  218. obj.jhzmarker = obj.marker.concat(arr)
  219. obj.AEDList = obj.AEDList.concat(data);
  220. console.log(obj.AEDList, 'obj.AEDList+++++++');
  221. // obj.markerList = data;
  222. obj.loaded = true
  223. if (obj.limit == data.length) {
  224. obj.loadtype = 'more';
  225. obj.page++;
  226. } else {
  227. obj.loadtype = 'noMore';
  228. }
  229. })
  230. },
  231. space(lat1, lng1, lat2, lng2) {
  232. console.log(lat1, lng1, lat2, lng2);
  233. var radLat1 = (lat1 * Math.PI) / 180.0;
  234. var radLat2 = (lat2 * Math.PI) / 180.0;
  235. var a = radLat1 - radLat2;
  236. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  237. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math
  238. .pow(Math.sin(b / 2), 2)));
  239. s = s * 6378.137;
  240. s = Math.round(s * 10000) / 10000;
  241. return s * 1000; // 单位米
  242. },
  243. openAddress(item) {
  244. let obj = this;
  245. obj.latitude2 = item.latitude;
  246. obj.longitude2 = item.longitude;
  247. obj.address = item.address;
  248. this.$refs.popup.open();
  249. },
  250. // 调用高德
  251. toGaodeMap() {
  252. uni.showLoading({
  253. title: '打开中..'
  254. })
  255. let latitude = this.latitude2;
  256. let longitude = this.longitude2;
  257. let address = this.address;
  258. console.log('选择高德', latitude, longitude, address);
  259. window.location.href = `https://uri.amap.com/marker?position=${longitude},${latitude}&name=${address}`;
  260. },
  261. // 调用腾讯
  262. totengxunMap() {
  263. uni.showLoading({
  264. title: '打开中..'
  265. })
  266. let latitude = this.latitude2;
  267. let longitude = this.longitude2;
  268. let address = this.address;
  269. console.log('选择腾讯', latitude, longitude);
  270. window.location.href =
  271. `http://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};addr:${address}`;
  272. },
  273. // 调用百度
  274. tobaiDuMap() {
  275. uni.showLoading({
  276. title: '打开中..'
  277. })
  278. function bd_encrypt(gg_lng, gg_lat) {
  279. var X_PI = Math.PI * 3000.0 / 180.0;
  280. var x = gg_lng,
  281. y = gg_lat;
  282. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
  283. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
  284. var bd_lng = z * Math.cos(theta) + 0.0065;
  285. var bd_lat = z * Math.sin(theta) + 0.006;
  286. return {
  287. lat: bd_lat,
  288. lng: bd_lng
  289. }
  290. }
  291. let towhere = bd_encrypt(this.longitude2, this.latitude2)
  292. let formwhere = bd_encrypt(this.longitude, this.latitude)
  293. let latitude6 = towhere.lat;
  294. let longitude6 = towhere.lng;
  295. let latitude = formwhere.lat
  296. let longitude = formwhere.lng
  297. let address = this.address;
  298. console.log('选择百度', latitude, longitude);
  299. console.log('获取当前经纬度', latitude6, longitude6);
  300. window.location.href =
  301. `http://api.map.baidu.com/direction?origin=latlng:${latitude},${longitude}|name:我的位置&destination=${latitude6},${longitude6}&mode=driving&region=${address}&output=html&src=webapp.baidu.openAPIdemo`;
  302. },
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. body,
  308. page {
  309. height: 100%;
  310. width: 100%;
  311. background-color: #fff;
  312. }
  313. .content {
  314. height: 100%;
  315. width: 100%;
  316. background-color: #fff;
  317. }
  318. .map {
  319. width: 100%;
  320. height: 600rpx;
  321. }
  322. /* #ifdef H5 */
  323. .location {
  324. overflow-y: scroll; //溢出就滑动起来
  325. // z-index: 990;
  326. position: fixed;
  327. bottom: 0;
  328. height: 55%;
  329. width: 100%;
  330. background-color: #fff;
  331. padding: 24rpx;
  332. //搜索框
  333. .Search-box {
  334. // z-index: 999;
  335. height: 80rpx;
  336. // position: fixed;
  337. // top: 0;
  338. // left: 0;
  339. // width: 100%;
  340. // background: #FFFFFF;
  341. // padding-top: 10rpx;
  342. padding-right: 24rpx;
  343. padding-left: 24rpx;
  344. .Search-box-sort {
  345. float: left;
  346. margin-left: 32rpx;
  347. margin-right: 19rpx;
  348. .sort-text {
  349. width: 57rpx;
  350. height: 29rpx;
  351. font-size: 30rpx;
  352. font-weight: 500;
  353. color: rgba(51, 51, 51, 1);
  354. line-height: 58rpx;
  355. margin-right: 19rpx;
  356. }
  357. .sort-img {
  358. width: 21rpx;
  359. height: 11rpx;
  360. margin-bottom: 4rpx;
  361. }
  362. }
  363. .Search-box-size {
  364. // width:70%;
  365. height: 58rpx;
  366. border-radius: 32rpx;
  367. background-color: #f1f1f1;
  368. padding-left: 36rpx;
  369. display: flex;
  370. align-items: center;
  371. .box-img {
  372. height: 32rpx;
  373. width: 32rpx;
  374. margin-right: 16rpx;
  375. }
  376. // .box-right{
  377. // height: 58rpx;
  378. // // width: 100%;
  379. // background-color: pink;
  380. // }
  381. .box-word {
  382. width: 100%;
  383. font-size: 26rpx;
  384. font-weight: 500;
  385. color: rgba(205, 203, 203, 1);
  386. line-height: 55rpx;
  387. }
  388. }
  389. }
  390. .location-item {
  391. z-index: 1000;
  392. display: flex;
  393. justify-content: space-between;
  394. align-items: center;
  395. border-bottom: 1rpx solid #E7E8EA;
  396. padding: 15rpx 0;
  397. .box-left {
  398. display: flex;
  399. .img01 {
  400. width: 8rpx;
  401. height: 28rpx;
  402. margin-right: 18rpx;
  403. image {
  404. width: 8rpx;
  405. height: 28rpx;
  406. }
  407. }
  408. .img02 {
  409. width: 117rpx;
  410. height: 117rpx;
  411. border-radius: 50%;
  412. image {
  413. width: 117rpx;
  414. height: 117rpx;
  415. border-radius: 50%;
  416. }
  417. }
  418. .info {
  419. margin-left: 16rpx;
  420. .info-header {
  421. display: flex;
  422. align-items: center;
  423. .name {
  424. font-size: 32rpx;
  425. color: #333333;
  426. }
  427. .distance {
  428. margin-left: 25rpx;
  429. font-size: 28rpx;
  430. color: #303133;
  431. }
  432. .location-icon {
  433. margin-left: 10rpx;
  434. width: 20rpx;
  435. height: 26rpx;
  436. image {
  437. width: 20rpx;
  438. height: 26rpx;
  439. display: inline;
  440. }
  441. }
  442. }
  443. .address {
  444. font-size: 26rpx;
  445. color: #333333;
  446. margin-top: 33rpx;
  447. }
  448. }
  449. }
  450. .box-right {
  451. .img {
  452. height: 107rpx;
  453. image {
  454. width: 107rpx;
  455. height: 107rpx;
  456. }
  457. }
  458. .called {
  459. margin-right: 16rpx;
  460. height: 107rpx;
  461. line-height: 107rpx;
  462. font-size: 28rpx;
  463. color: #CB131C;
  464. }
  465. }
  466. }
  467. }
  468. /* #endif */
  469. .list-tpl {
  470. background-color: #ffffff;
  471. margin: 25rpx 0rpx;
  472. padding: 25rpx 25rpx;
  473. font-size: 28rpx;
  474. border-radius: 15rpx;
  475. display: flex;
  476. justify-content: space-between;
  477. align-items: center;
  478. border-bottom: 1px solid #f1f1f1;
  479. .list-left {
  480. display: flex;
  481. width: 100%;
  482. .number {
  483. font-size: 32rpx;
  484. margin-right: 14rpx;
  485. }
  486. .info {
  487. width: 100%;
  488. .title {
  489. font-size: 32rpx;
  490. color: #222222;
  491. font-weight: 500;
  492. }
  493. .addr {
  494. width: 400rpx;
  495. margin-top: 20rpx;
  496. font-size: 20rpx;
  497. font-family: PingFang SC;
  498. font-weight: 500;
  499. color: #999999;
  500. }
  501. }
  502. }
  503. .image {
  504. width: 10%;
  505. text-align: center;
  506. image {
  507. width: 50rpx;
  508. height: 50rpx;
  509. }
  510. .tip {
  511. color: #7f7f7f;
  512. font-size: 21rpx;
  513. }
  514. }
  515. }
  516. .popup_row {
  517. width: 100%;
  518. height: 500rpx;
  519. background-color: #ffffff;
  520. border-radius: 20rpx;
  521. display: flex;
  522. justify-content: center;
  523. align-items: center;
  524. .rows {
  525. width: 100%;
  526. padding: 0 24rpx;
  527. .rows-item {
  528. height: 80rpx;
  529. line-height: 80rpx;
  530. text-align: center;
  531. width: 100%;
  532. font-size: 32rpx;
  533. color: #303133;
  534. }
  535. }
  536. }
  537. </style>