aid.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. getDistance
  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. getDistance({
  198. lng1: obj.longitude,
  199. lat1: obj.latitude
  200. }).then(({data}) => {
  201. uni.hideLoading();
  202. console.log(data, 999);
  203. for (let i = 0; i < data.length; i++) {
  204. data[i].space = obj.space(obj.latitude, obj.longitude, data[i].latitude, data[i].longitude);
  205. }
  206. let arr = data.map(item => ({
  207. latitude: item.latitude,
  208. longitude: item.longitude,
  209. iconPath: '/static/icon/jhz.png',
  210. width: '35',
  211. height: '35',
  212. id: item.id,
  213. address: item.address
  214. }));
  215. obj.jhzmarker = obj.marker.concat(arr)
  216. obj.AEDList = obj.AEDList.concat(data);
  217. console.log(obj.AEDList, 'obj.AEDList+++++++');
  218. // obj.markerList = data;
  219. obj.loaded = true
  220. if (obj.limit == data.length) {
  221. obj.loadtype = 'more';
  222. obj.page++;
  223. } else {
  224. obj.loadtype = 'noMore';
  225. }
  226. })
  227. },
  228. space(lat1, lng1, lat2, lng2) {
  229. console.log(lat1, lng1, lat2, lng2);
  230. var radLat1 = (lat1 * Math.PI) / 180.0;
  231. var radLat2 = (lat2 * Math.PI) / 180.0;
  232. var a = radLat1 - radLat2;
  233. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  234. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  235. s = s * 6378.137;
  236. s = Math.round(s * 10000) / 10000;
  237. return s * 1000; // 单位米
  238. },
  239. openAddress(item) {
  240. let obj = this;
  241. obj.latitude2 = item.latitude;
  242. obj.longitude2 = item.longitude;
  243. obj.address = item.address;
  244. this.$refs.popup.open();
  245. },
  246. // 调用高德
  247. toGaodeMap() {
  248. let latitude = this.latitude2;
  249. let longitude = this.longitude2;
  250. let address = this.address;
  251. console.log('选择高德', latitude, longitude, address);
  252. window.location.href = `https://uri.amap.com/marker?position=${longitude},${latitude}&name=${address}`;
  253. },
  254. // 调用腾讯
  255. totengxunMap() {
  256. let latitude = this.latitude2;
  257. let longitude = this.longitude2;
  258. let address = this.address;
  259. console.log('选择腾讯', latitude, longitude);
  260. window.location.href = `http://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};addr:${address}`;
  261. },
  262. // 调用百度
  263. tobaiDuMap() {
  264. let latitude = this.latitude2;
  265. let longitude = this.longitude2;
  266. let latitude6 = this.latitude;
  267. let longitude6 = this.longitude;
  268. let address = this.address;
  269. console.log('选择百度', latitude, longitude);
  270. console.log('获取当前经纬度', latitude6, longitude6);
  271. window.location.href = `http://api.map.baidu.com/direction?origin=latlng:${latitude6},${longitude6}|name:我的位置&destination=${latitude},${longitude}&mode=driving&region=${address}&output=html&src=webapp.baidu.openAPIdemo`;
  272. //`bdapp://map/navi?location=${longitude},${latitude}&coord_type=gc02&title=${address}&content=${address}&output=html&src=andr.baidu.openAPIdemo `
  273. },
  274. }
  275. }
  276. </script>
  277. <style lang="scss">
  278. body,
  279. page {
  280. height: 100%;
  281. width: 100%;
  282. background-color: #fff;
  283. }
  284. .content {
  285. height: 100%;
  286. width: 100%;
  287. background-color: #fff;
  288. }
  289. .map {
  290. width: 100%;
  291. height: 600rpx;
  292. }
  293. /* #ifdef H5 */
  294. .location {
  295. overflow-y: scroll; //溢出就滑动起来
  296. // z-index: 990;
  297. position: fixed;
  298. bottom: 0;
  299. height: 55%;
  300. width: 100%;
  301. background-color: #fff;
  302. padding: 24rpx;
  303. //搜索框
  304. .Search-box {
  305. // z-index: 999;
  306. height: 80rpx;
  307. // position: fixed;
  308. // top: 0;
  309. // left: 0;
  310. // width: 100%;
  311. // background: #FFFFFF;
  312. // padding-top: 10rpx;
  313. padding-right: 24rpx;
  314. padding-left: 24rpx;
  315. .Search-box-sort {
  316. float: left;
  317. margin-left: 32rpx;
  318. margin-right: 19rpx;
  319. .sort-text {
  320. width: 57rpx;
  321. height: 29rpx;
  322. font-size: 30rpx;
  323. font-weight: 500;
  324. color: rgba(51, 51, 51, 1);
  325. line-height: 58rpx;
  326. margin-right: 19rpx;
  327. }
  328. .sort-img {
  329. width: 21rpx;
  330. height: 11rpx;
  331. margin-bottom: 4rpx;
  332. }
  333. }
  334. .Search-box-size {
  335. // width:70%;
  336. height: 58rpx;
  337. border-radius: 32rpx;
  338. background-color: #f1f1f1;
  339. padding-left: 36rpx;
  340. display: flex;
  341. align-items: center;
  342. .box-img {
  343. height: 32rpx;
  344. width: 32rpx;
  345. margin-right: 16rpx;
  346. }
  347. // .box-right{
  348. // height: 58rpx;
  349. // // width: 100%;
  350. // background-color: pink;
  351. // }
  352. .box-word {
  353. width: 100%;
  354. font-size: 26rpx;
  355. font-weight: 500;
  356. color: rgba(205, 203, 203, 1);
  357. line-height: 55rpx;
  358. }
  359. }
  360. }
  361. .location-item {
  362. z-index: 1000;
  363. display: flex;
  364. justify-content: space-between;
  365. align-items: center;
  366. border-bottom: 1rpx solid #E7E8EA;
  367. padding: 15rpx 0;
  368. .box-left {
  369. display: flex;
  370. .img01 {
  371. width: 8rpx;
  372. height: 28rpx;
  373. margin-right: 18rpx;
  374. image {
  375. width: 8rpx;
  376. height: 28rpx;
  377. }
  378. }
  379. .img02 {
  380. width: 117rpx;
  381. height: 117rpx;
  382. border-radius: 50%;
  383. image {
  384. width: 117rpx;
  385. height: 117rpx;
  386. border-radius: 50%;
  387. }
  388. }
  389. .info {
  390. margin-left: 16rpx;
  391. .info-header {
  392. display: flex;
  393. align-items: center;
  394. .name {
  395. font-size: 32rpx;
  396. color: #333333;
  397. }
  398. .distance {
  399. margin-left: 25rpx;
  400. font-size: 28rpx;
  401. color: #303133;
  402. }
  403. .location-icon {
  404. margin-left: 10rpx;
  405. width: 20rpx;
  406. height: 26rpx;
  407. image {
  408. width: 20rpx;
  409. height: 26rpx;
  410. display: inline;
  411. }
  412. }
  413. }
  414. .address {
  415. font-size: 26rpx;
  416. color: #333333;
  417. margin-top: 33rpx;
  418. }
  419. }
  420. }
  421. .box-right {
  422. .img {
  423. height: 107rpx;
  424. image {
  425. width: 107rpx;
  426. height: 107rpx;
  427. }
  428. }
  429. .called {
  430. margin-right: 16rpx;
  431. height: 107rpx;
  432. line-height: 107rpx;
  433. font-size: 28rpx;
  434. color: #CB131C;
  435. }
  436. }
  437. }
  438. }
  439. /* #endif */
  440. .list-tpl {
  441. background-color: #ffffff;
  442. margin: 25rpx 0rpx;
  443. padding: 25rpx 25rpx;
  444. font-size: 28rpx;
  445. border-radius: 15rpx;
  446. display: flex;
  447. justify-content: space-between;
  448. align-items: center;
  449. border-bottom: 1px solid #f1f1f1;
  450. .list-left {
  451. display: flex;
  452. width: 100%;
  453. .number {
  454. font-size: 32rpx;
  455. margin-right: 14rpx;
  456. }
  457. .info {
  458. width: 100%;
  459. .title {
  460. font-size: 32rpx;
  461. color: #222222;
  462. font-weight: 500;
  463. }
  464. .addr {
  465. width: 400rpx;
  466. margin-top: 20rpx;
  467. font-size: 20rpx;
  468. font-family: PingFang SC;
  469. font-weight: 500;
  470. color: #999999;
  471. }
  472. }
  473. }
  474. .image {
  475. width: 10%;
  476. text-align: center;
  477. image {
  478. width: 50rpx;
  479. height: 50rpx;
  480. }
  481. .tip {
  482. color: #7f7f7f;
  483. font-size: 21rpx;
  484. }
  485. }
  486. }
  487. .popup_row {
  488. width: 100%;
  489. height: 500rpx;
  490. background-color: #ffffff;
  491. border-radius: 20rpx;
  492. display: flex;
  493. justify-content: center;
  494. align-items: center;
  495. .rows {
  496. width: 100%;
  497. padding: 0 24rpx;
  498. .rows-item {
  499. height: 80rpx;
  500. line-height: 80rpx;
  501. text-align: center;
  502. width: 100%;
  503. font-size: 32rpx;
  504. color: #303133;
  505. }
  506. }
  507. }
  508. </style>