aed.vue 13 KB

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