yz.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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.name }}</view>
  14. <view class="addr">地址:{{ item.detailed_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. aedmarker: [],
  66. loaded: false,
  67. loadtype: 'more',
  68. page: 1,
  69. limit: 1000,
  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. // obj.loadData();
  119. try {
  120. let locationAddress
  121. // #ifdef H5
  122. let wxOjb = require('jweixin-module');
  123. locationAddress = wxOjb.getLocation;
  124. // #endif
  125. // #ifdef MP
  126. locationAddress = uni.getLocation;
  127. // #endif
  128. wxOjb.ready(() => {
  129. console.log('加载完毕注册事件');
  130. locationAddress({
  131. type: 'gcj02',
  132. success: function(res) {
  133. console.log('获取经纬度', res);
  134. obj.longitude = res.longitude
  135. obj.latitude = res.latitude
  136. obj.marker = [{
  137. latitude: obj.latitude,
  138. longitude: obj.longitude,
  139. iconPath: '/static/img/img19.png',
  140. width: '45',
  141. height: '45',
  142. }, ]
  143. obj.loadData();
  144. },
  145. fail(e) {
  146. console.log('失败', e);
  147. window.location.reload();
  148. }
  149. });
  150. })
  151. } catch (e) {
  152. console.log(e);
  153. let locationAddress
  154. // #ifdef H5
  155. let wxOjb = require('jweixin-module');
  156. locationAddress = wxOjb.getLocation;
  157. // #endif
  158. // #ifdef MP
  159. locationAddress = uni.getLocation;
  160. // #endif
  161. wxOjb.ready(() => {
  162. console.log('加载完毕注册事件');
  163. locationAddress({
  164. type: 'gcj02',
  165. success: function(res) {
  166. console.log('获取经纬度1', res);
  167. obj.longitude = res.longitude
  168. obj.latitude = res.latitude
  169. obj.loadData();
  170. },
  171. fail(e) {
  172. console.log('失败', e);
  173. }
  174. });
  175. })
  176. }
  177. },
  178. computed: {
  179. ...mapState('user', ['hasLogin', 'userInfo'])
  180. },
  181. methods: {
  182. ...mapMutations('user', ['setUserInfo']),
  183. // 地图渲染完毕事件
  184. mapChange(e) {
  185. console.log(e);
  186. },
  187. // 载入数据
  188. async loadData() {
  189. let obj = this;
  190. if(obj.loadtype == 'loading' || obj.loadtype == 'noMore') {
  191. return
  192. }
  193. obj.loadtype = 'loading'
  194. getListMechanism({
  195. page: obj.page,
  196. limit: obj.limit,
  197. }).then(({data}) => {
  198. console.log(data, 999);
  199. for (let i = 0; i < data.length; i++) {
  200. data[i].space = obj.space(obj.latitude, obj.longitude, data[i].latitude, data[i].longitude);
  201. }
  202. let arr1 = data.sort(obj.sortBy('space'))
  203. obj.AEDList = obj.AEDList.concat(data);
  204. console.log(obj.AEDList, 'obj.AEDList+++++++');
  205. let arr = data.map(item => ({
  206. latitude: item.latitude,
  207. longitude: item.longitude,
  208. iconPath: '/static/icon/yz.png',
  209. width: '35',
  210. height: '35',
  211. id: item.id,
  212. address: item.address
  213. }));
  214. obj.aedmarker = obj.marker.concat(arr)
  215. // obj.markerList = data;
  216. obj.loaded = true
  217. obj.page++;
  218. if (obj.limit == data.length) {
  219. obj.loadtype = 'more';
  220. } else {
  221. obj.loadtype = 'noMore';
  222. }
  223. })
  224. },
  225. sortBy(field) {
  226. //根据传过来的字段进行排序,y-x 得分从高到低,x-y 从低到高
  227. return (x, y) => {
  228. return x[field] - y[field]
  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.pow(Math.sin(b / 2), 2)));
  238. s = s * 6378.137;
  239. s = Math.round(s * 10000) / 10000;
  240. return s * 1000; // 单位米
  241. },
  242. openAddress(item) {
  243. let obj = this;
  244. obj.latitude2 = item.latitude;
  245. obj.longitude2 = item.longitude;
  246. obj.address = item.detailed_address;
  247. this.$refs.popup.open();
  248. },
  249. // 调用高德
  250. toGaodeMap() {
  251. let latitude = this.latitude2;
  252. let longitude = this.longitude2;
  253. let address = this.address;
  254. console.log('选择高德', latitude, longitude, address);
  255. window.location.href = `https://uri.amap.com/marker?position=${longitude},${latitude}&name=${address}`;
  256. },
  257. // 调用腾讯
  258. totengxunMap() {
  259. let latitude = this.latitude2;
  260. let longitude = this.longitude2;
  261. let address = this.address;
  262. console.log('选择腾讯', latitude, longitude);
  263. window.location.href = `http://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};addr:${address}`;
  264. },
  265. // 调用百度
  266. tobaiDuMap() {
  267. let latitude = this.latitude2;
  268. let longitude = this.longitude2;
  269. let latitude6 = this.latitude;
  270. let longitude6 = this.longitude;
  271. let address = this.address;
  272. console.log('选择百度', latitude, longitude);
  273. console.log('获取当前经纬度', latitude6, longitude6);
  274. 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`;
  275. //`bdapp://map/navi?location=${longitude},${latitude}&coord_type=gc02&title=${address}&content=${address}&output=html&src=andr.baidu.openAPIdemo `
  276. },
  277. }
  278. }
  279. </script>
  280. <style lang="scss">
  281. body,
  282. page {
  283. height: 100%;
  284. width: 100%;
  285. background-color: #fff;
  286. }
  287. .content {
  288. height: 100%;
  289. width: 100%;
  290. background-color: #fff;
  291. }
  292. .map {
  293. width: 100%;
  294. height: 600rpx;
  295. }
  296. /* #ifdef H5 */
  297. .location {
  298. overflow-y: scroll; //溢出就滑动起来
  299. // z-index: 990;
  300. position: fixed;
  301. bottom: 0;
  302. height: 55%;
  303. width: 100%;
  304. background-color: #fff;
  305. padding: 24rpx;
  306. //搜索框
  307. .Search-box {
  308. // z-index: 999;
  309. height: 80rpx;
  310. // position: fixed;
  311. // top: 0;
  312. // left: 0;
  313. // width: 100%;
  314. // background: #FFFFFF;
  315. // padding-top: 10rpx;
  316. padding-right: 24rpx;
  317. padding-left: 24rpx;
  318. .Search-box-sort {
  319. float: left;
  320. margin-left: 32rpx;
  321. margin-right: 19rpx;
  322. .sort-text {
  323. width: 57rpx;
  324. height: 29rpx;
  325. font-size: 30rpx;
  326. font-weight: 500;
  327. color: rgba(51, 51, 51, 1);
  328. line-height: 58rpx;
  329. margin-right: 19rpx;
  330. }
  331. .sort-img {
  332. width: 21rpx;
  333. height: 11rpx;
  334. margin-bottom: 4rpx;
  335. }
  336. }
  337. .Search-box-size {
  338. // width:70%;
  339. height: 58rpx;
  340. border-radius: 32rpx;
  341. background-color: #f1f1f1;
  342. padding-left: 36rpx;
  343. display: flex;
  344. align-items: center;
  345. .box-img {
  346. height: 32rpx;
  347. width: 32rpx;
  348. margin-right: 16rpx;
  349. }
  350. // .box-right{
  351. // height: 58rpx;
  352. // // width: 100%;
  353. // background-color: pink;
  354. // }
  355. .box-word {
  356. width: 100%;
  357. font-size: 26rpx;
  358. font-weight: 500;
  359. color: rgba(205, 203, 203, 1);
  360. line-height: 55rpx;
  361. }
  362. }
  363. }
  364. .location-item {
  365. z-index: 1000;
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. border-bottom: 1rpx solid #E7E8EA;
  370. padding: 15rpx 0;
  371. .box-left {
  372. display: flex;
  373. .img01 {
  374. width: 8rpx;
  375. height: 28rpx;
  376. margin-right: 18rpx;
  377. image {
  378. width: 8rpx;
  379. height: 28rpx;
  380. }
  381. }
  382. .img02 {
  383. width: 117rpx;
  384. height: 117rpx;
  385. border-radius: 50%;
  386. image {
  387. width: 117rpx;
  388. height: 117rpx;
  389. border-radius: 50%;
  390. }
  391. }
  392. .info {
  393. margin-left: 16rpx;
  394. .info-header {
  395. display: flex;
  396. align-items: center;
  397. .name {
  398. font-size: 32rpx;
  399. color: #333333;
  400. }
  401. .distance {
  402. margin-left: 25rpx;
  403. font-size: 28rpx;
  404. color: #303133;
  405. }
  406. .location-icon {
  407. margin-left: 10rpx;
  408. width: 20rpx;
  409. height: 26rpx;
  410. image {
  411. width: 20rpx;
  412. height: 26rpx;
  413. display: inline;
  414. }
  415. }
  416. }
  417. .address {
  418. font-size: 26rpx;
  419. color: #333333;
  420. margin-top: 33rpx;
  421. }
  422. }
  423. }
  424. .box-right {
  425. .img {
  426. height: 107rpx;
  427. image {
  428. width: 107rpx;
  429. height: 107rpx;
  430. }
  431. }
  432. .called {
  433. margin-right: 16rpx;
  434. height: 107rpx;
  435. line-height: 107rpx;
  436. font-size: 28rpx;
  437. color: #CB131C;
  438. }
  439. }
  440. }
  441. }
  442. /* #endif */
  443. .list-tpl {
  444. background-color: #ffffff;
  445. margin: 25rpx 0rpx;
  446. padding: 25rpx 25rpx;
  447. font-size: 28rpx;
  448. border-radius: 15rpx;
  449. display: flex;
  450. justify-content: space-between;
  451. align-items: center;
  452. border-bottom: 1px solid #f1f1f1;
  453. .list-left {
  454. display: flex;
  455. width: 100%;
  456. .number {
  457. font-size: 32rpx;
  458. margin-right: 14rpx;
  459. }
  460. .info {
  461. width: 100%;
  462. .title {
  463. font-size: 32rpx;
  464. color: #222222;
  465. font-weight: 500;
  466. }
  467. .addr {
  468. width: 400rpx;
  469. margin-top: 20rpx;
  470. font-size: 20rpx;
  471. font-family: PingFang SC;
  472. font-weight: 500;
  473. color: #999999;
  474. }
  475. }
  476. }
  477. .image {
  478. width: 10%;
  479. text-align: center;
  480. image {
  481. width: 50rpx;
  482. height: 50rpx;
  483. }
  484. .tip {
  485. color: #7f7f7f;
  486. font-size: 21rpx;
  487. }
  488. }
  489. }
  490. .popup_row {
  491. width: 100%;
  492. height: 500rpx;
  493. background-color: #ffffff;
  494. border-radius: 20rpx;
  495. display: flex;
  496. justify-content: center;
  497. align-items: center;
  498. .rows {
  499. width: 100%;
  500. padding: 0 24rpx;
  501. .rows-item {
  502. height: 80rpx;
  503. line-height: 80rpx;
  504. text-align: center;
  505. width: 100%;
  506. font-size: 32rpx;
  507. color: #303133;
  508. }
  509. }
  510. }
  511. </style>