location.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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="marker"></map>
  6. </view>
  7. <view class="location">
  8. <!-- <view class="Search-box" @click="getLocation">
  9. <view class="Search-box-size">
  10. <image class="box-img" src="https://zhxc2030.com/img/img01.png"></image>
  11. <input class="box-word" placeholder="搜索地址" v-model="specificAdd" @input="searchlist">
  12. </view>
  13. </view> -->
  14. <view v-for="(item,index) in list" :key="item.id">
  15. <view class="location-item" >
  16. <view class="box-left">
  17. <view class="img01">
  18. <image src="../../static/img/line01.png" mode=""></image>
  19. </view>
  20. <view class="img02">
  21. <image :src="item.info.avatar" mode=""></image>
  22. </view>
  23. <view class="info">
  24. <view class="info-header">
  25. <view class="name">
  26. 救护员{{ index +1 }}
  27. </view>
  28. <view class="distance">
  29. {{ item.num }}km
  30. </view>
  31. <view class="location-icon">
  32. <image src="../../static/img/location-icon.png" mode=""></image>
  33. </view>
  34. </view>
  35. <view class="address">
  36. {{ item.detailed_address }}
  37. </view>
  38. </view>
  39. </view>
  40. <view class="box-right" @click="rescue(item,index)" >
  41. <view class="img" v-if="!item.is">
  42. <image src="../../static/img/rescue.png" mode=""></image>
  43. </view>
  44. <view class="called" v-if="item.is">
  45. 已呼叫
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <espempty v-if="list.length === 0"></espempty>
  51. </view>
  52. <uni-popup ref="popup" type="center" @click="close">
  53. <view class="popup_row">
  54. <view class="title">
  55. <view class="title-left">
  56. 请输入您的手机号,等待救援!
  57. </view>
  58. <view class="cancel" @click="cancel">
  59. <image src="../../static/img/cancel1.png" mode=""></image>
  60. </view>
  61. </view>
  62. <view class="inpBox">
  63. <input type="text" value="" placeholder="请输入您的手机号" v-model="to_phone"/>
  64. </view>
  65. <view class="inpedit">
  66. 可在方框中修改您的手机号
  67. </view>
  68. <view class="comfirm">
  69. <view class="comfirm1" @click="comfirm1()">
  70. 确认
  71. </view>
  72. </view>
  73. </view>
  74. </uni-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. mapState,
  80. mapMutations
  81. } from 'vuex';
  82. import espempty from '@/components/espempty';
  83. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  84. import {
  85. getdis,
  86. tocall
  87. } from '@/api/index.js';
  88. import {
  89. userinfo
  90. } from '@/api/user.js';
  91. import {
  92. getcomAddress
  93. } from '@/api/index.js';
  94. export default {
  95. components: {
  96. uniPopup,
  97. espempty,
  98. },
  99. //相关配置参数
  100. data() {
  101. return {
  102. list: [],
  103. latitude: '',
  104. longitude: '',
  105. current: 0,
  106. name: '',
  107. uid: '',
  108. name: '',
  109. phone: '',
  110. to_phone:'',
  111. marker: [],
  112. specificAdd:'',
  113. addressData: {
  114. name: '',
  115. mobile: '',
  116. latitude: 0, //纬度
  117. longitude: 0, //经度
  118. address: {
  119. province: '',
  120. city: '',
  121. district: '',
  122. detail: '',
  123. },
  124. area: '',
  125. default: false
  126. },
  127. }
  128. },
  129. onLoad() {
  130. let obj = this;
  131. console.log('开始加载事件');
  132. obj.loadBaseData()
  133. uni.showLoading({
  134. title: '加载中',
  135. mask: true
  136. });
  137. try {
  138. let locationAddress
  139. // #ifdef H5
  140. let wxOjb = require('jweixin-module');
  141. locationAddress = wxOjb.getLocation;
  142. // #endif
  143. // #ifdef MP
  144. locationAddress = uni.getLocation;
  145. // #endif
  146. wxOjb.ready(()=>{
  147. console.log('加载完毕注册事件');
  148. locationAddress({
  149. type: 'gcj02',
  150. success: function(res) {
  151. console.log('获取经纬度', res);
  152. obj.longitude = res.longitude
  153. obj.latitude = res.latitude
  154. obj.marker = [
  155. {
  156. latitude: obj.latitude,
  157. longitude: obj.longitude,
  158. iconPath: '/static/img/img19.png',
  159. width: '45',
  160. height: '45',
  161. },
  162. ]
  163. obj.loadData();
  164. },
  165. fail(e) {
  166. console.log('失败', e);
  167. window.location.reload();
  168. }
  169. });
  170. })
  171. } catch (e) {
  172. console.log(e);
  173. let locationAddress
  174. // #ifdef H5
  175. let wxOjb = require('jweixin-module');
  176. locationAddress = wxOjb.getLocation;
  177. // #endif
  178. // #ifdef MP
  179. locationAddress = uni.getLocation;
  180. // #endif
  181. wxOjb.ready(()=>{
  182. console.log('加载完毕注册事件');
  183. locationAddress({
  184. type: 'gcj02',
  185. success: function(res) {
  186. console.log('获取经纬度1', res);
  187. obj.longitude = res.longitude
  188. obj.latitude = res.latitude
  189. obj.loadData();
  190. },
  191. fail(e) {
  192. console.log('失败', e);
  193. }
  194. });
  195. })
  196. }
  197. },
  198. computed: {
  199. ...mapState('user', ['hasLogin', 'userInfo'])
  200. },
  201. methods: {
  202. ...mapMutations('user', ['setUserInfo']),
  203. loadBaseData() {
  204. userinfo({}).then(({
  205. data
  206. }) => {
  207. console.log(123,data)
  208. this.to_phone = data.phone
  209. this.setUserInfo(data);
  210. });
  211. },
  212. // 选择当前位置
  213. // chooseAddress() {
  214. // console.log('233')
  215. // let obj = this;
  216. // uni.chooseLocation({
  217. // success: function(res) {
  218. // console.log(res)
  219. // obj.addressData.area = res.name;
  220. // console.log('位置名称:' + res.name);
  221. // console.log('详细地址:' + res.address);
  222. // console.log('经度:' + res.longitude);
  223. // console.log('纬度:' + res.latitude);
  224. // obj.latitude = res.latitude;
  225. // obj.longitude = res.longitude;
  226. // obj.marker = [
  227. // {
  228. // latitude: obj.latitude,
  229. // longitude: obj.longitude,
  230. // iconPath: '/static/img/img19.png',
  231. // width: '48',
  232. // height: '48',
  233. // },
  234. // ]
  235. // obj.addressData.latitude = res.latitude;
  236. // obj.addressData.longitude = res.longitude;
  237. // obj.addressDetail = res.address;
  238. // console.log('common_address123',obj.addressDetail )
  239. // console.log('latitude123',obj.addressData.latitude )
  240. // console.log('longitude123',obj.addressData.longitude )
  241. // obj.loadData()
  242. // // getcomAddress({
  243. // // common_address: obj.addressDetail,
  244. // // longitude: obj.addressData.longitude,
  245. // // latitude: obj.addressData.latitude
  246. // // }).then(data => {
  247. // // console.log(333)
  248. // // console.log(data);
  249. // // if (data.status == 200) {
  250. // // obj.$api.msg('保存成功')
  251. // // }
  252. // // })
  253. // }
  254. // });
  255. // },
  256. // 地图渲染完毕事件
  257. mapChange(e) {
  258. console.log(e);
  259. },
  260. // 载入数据
  261. async loadData() {
  262. let obj = this;
  263. getdis({
  264. lng1: obj.longitude,
  265. lat1: obj.latitude
  266. }).then((res) => {
  267. // uni.showModal({
  268. // title:'值',
  269. // content:JSON.stringify(res)
  270. // })
  271. let data = res.data;
  272. uni.hideLoading();
  273. console.log('请求数据', data);
  274. // obj.phone = data.phone
  275. console.log('data.phone333',data.phone)
  276. data = data.map(d => {
  277. return {
  278. ...d,
  279. iscall: true
  280. }
  281. })
  282. obj.list = data;
  283. let arr = data.map(item => ({
  284. latitude: item.latitude,
  285. longitude: item.longitude,
  286. iconPath: '/static/img/img014.png',
  287. width: '35',
  288. height: '35',
  289. id: item.id,
  290. address: item.address
  291. }))
  292. obj.marker = obj.marker.concat(arr)
  293. }).catch(err => {
  294. console.log(err);
  295. uni.hideLoading();
  296. uni.showModal({
  297. title: '失败',
  298. content: JSON.stringify(err)
  299. });
  300. });
  301. },
  302. cancel(){
  303. this.$refs.popup.close();
  304. },
  305. comfirm1:function () {
  306. let obj = this
  307. if ( obj.to_phone.toString().trim() == '' ){
  308. // uni.showModal({
  309. // title:'输入框为空',
  310. // // content:JSON.stringify(obj)
  311. // })
  312. } else {
  313. console.log('obj.to_phone1111',obj.to_phone)
  314. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  315. if (!reg.test(obj.to_phone)) {
  316. obj.$api.msg('请填写正确的手机号码');
  317. return;
  318. }
  319. console.log('name:',obj.name)
  320. console.log('uid:',obj.uid)
  321. console.log('phone',obj.phone)
  322. console.log('to_phone',obj.to_phone)
  323. console.log('longitude',obj.longitude)
  324. console.log('latitude',obj.latitude)
  325. console.log('iscall',obj.iscall)
  326. tocall({
  327. name: obj.name,
  328. uid: obj.uid,
  329. phone: obj.phone,
  330. longitude: obj.longitude,
  331. latitude: obj.latitude,
  332. to_phone:obj.to_phone
  333. }).then((data) => {
  334. console.log(99988,data)
  335. uni.showModal({
  336. title:'请耐心等待救援',
  337. success: res => {
  338. if (res.confirm) {
  339. window.location.reload(); //重新刷新页面
  340. }
  341. }
  342. })
  343. obj.$refs.popup.close();
  344. obj.iscall = false
  345. console.log(123,obj.iscall)
  346. })
  347. }
  348. },
  349. // comfirm2:function (item,index) {
  350. // let obj = this
  351. // },
  352. // 立即救援
  353. rescue(item, index) {
  354. let obj = this;
  355. uni.showModal({
  356. content: '是否发起求救?',
  357. success: res => {
  358. if (res.confirm) {
  359. this.$refs.popup.open(item,index);
  360. obj.name = item.name;
  361. obj.uid = item.uid;
  362. obj.phone = item.phone;
  363. obj.iscall = false
  364. console.log('点击救援时item.phone:',obj.phone)
  365. }
  366. }
  367. })
  368. }
  369. }
  370. }
  371. </script>
  372. <style lang="scss">
  373. body,
  374. page {
  375. height: 100%;
  376. width: 100%;
  377. background-color: #fff;
  378. }
  379. .content {
  380. height: 100%;
  381. width: 100%;
  382. background-color: #fff;
  383. }
  384. .map{
  385. width: 100%;
  386. height: 600rpx;
  387. }
  388. /* #ifdef H5 */
  389. .location {
  390. overflow-y: scroll; //溢出就滑动起来
  391. // z-index: 990;
  392. position: fixed;
  393. bottom: 0;
  394. height: 55%;
  395. width: 100%;
  396. background-color: #fff;
  397. padding: 24rpx;
  398. //搜索框
  399. .Search-box {
  400. // z-index: 999;
  401. height: 80rpx;
  402. // position: fixed;
  403. // top: 0;
  404. // left: 0;
  405. // width: 100%;
  406. // background: #FFFFFF;
  407. // padding-top: 10rpx;
  408. padding-right: 24rpx;
  409. padding-left: 24rpx;
  410. .Search-box-sort {
  411. float: left;
  412. margin-left: 32rpx;
  413. margin-right: 19rpx;
  414. .sort-text {
  415. width: 57rpx;
  416. height: 29rpx;
  417. font-size: 30rpx;
  418. font-weight: 500;
  419. color: rgba(51, 51, 51, 1);
  420. line-height: 58rpx;
  421. margin-right: 19rpx;
  422. }
  423. .sort-img {
  424. width: 21rpx;
  425. height: 11rpx;
  426. margin-bottom: 4rpx;
  427. }
  428. }
  429. .Search-box-size {
  430. // width:70%;
  431. height: 58rpx;
  432. border-radius: 32rpx;
  433. background-color: #f1f1f1;
  434. padding-left: 36rpx;
  435. display: flex;
  436. align-items: center;
  437. .box-img {
  438. height: 32rpx;
  439. width: 32rpx;
  440. margin-right: 16rpx;
  441. }
  442. // .box-right{
  443. // height: 58rpx;
  444. // // width: 100%;
  445. // background-color: pink;
  446. // }
  447. .box-word {
  448. width: 100%;
  449. font-size: 26rpx;
  450. font-weight: 500;
  451. color: rgba(205, 203, 203, 1);
  452. line-height: 55rpx;
  453. }
  454. }
  455. }
  456. .location-item {
  457. z-index: 1000;
  458. display: flex;
  459. justify-content: space-between;
  460. align-items: center;
  461. border-bottom: 1rpx solid #E7E8EA;
  462. padding: 15rpx 0;
  463. .box-left {
  464. display: flex;
  465. .img01 {
  466. width: 8rpx;
  467. height: 28rpx;
  468. margin-right: 18rpx;
  469. image {
  470. width: 8rpx;
  471. height: 28rpx;
  472. }
  473. }
  474. .img02 {
  475. width: 117rpx;
  476. height: 117rpx;
  477. border-radius: 50%;
  478. image {
  479. width: 117rpx;
  480. height: 117rpx;
  481. border-radius: 50%;
  482. }
  483. }
  484. .info {
  485. margin-left: 16rpx;
  486. .info-header {
  487. display: flex;
  488. align-items: center;
  489. .name {
  490. font-size: 32rpx;
  491. color: #333333;
  492. }
  493. .distance {
  494. margin-left: 25rpx;
  495. font-size: 28rpx;
  496. color: #303133;
  497. }
  498. .location-icon {
  499. margin-left: 10rpx;
  500. width: 20rpx;
  501. height: 26rpx;
  502. image {
  503. width: 20rpx;
  504. height: 26rpx;
  505. display: inline;
  506. }
  507. }
  508. }
  509. .address {
  510. font-size: 26rpx;
  511. color: #333333;
  512. margin-top: 33rpx;
  513. }
  514. }
  515. }
  516. .box-right {
  517. .img {
  518. height: 107rpx;
  519. image {
  520. width: 107rpx;
  521. height: 107rpx;
  522. }
  523. }
  524. .called {
  525. margin-right: 16rpx;
  526. height: 107rpx;
  527. line-height: 107rpx;
  528. font-size: 28rpx;
  529. color: #CB131C;
  530. }
  531. }
  532. }
  533. }
  534. .popup_row{
  535. // margin-top: 108rpx;
  536. height: 440rpx;
  537. border-radius: 25rpx;
  538. width: 100%;
  539. padding: 24rpx;
  540. background-color: #f8f8f8;
  541. z-index: 999;
  542. .title{
  543. border-bottom: 2rpx solid #F2F2F2;
  544. color: #E63931;
  545. font-size: 32rpx;
  546. padding-left: 4rpx;
  547. padding-bottom: 16rpx;
  548. display: flex;
  549. justify-content: space-between;
  550. // align-items: center;
  551. .cancel{
  552. margin-left: 52rpx;
  553. width: 36rpx;
  554. height: 36rpx;
  555. image{
  556. width: 36rpx;
  557. height: 36rpx;
  558. }
  559. }
  560. }
  561. .inpBox{
  562. margin-top: 52rpx;
  563. border: 2px solid #f2f2f2;
  564. padding: 12rpx 24rpx;
  565. color: #FF9797;
  566. border-radius: 8rpx;
  567. .input-placeholder {
  568. // height: 70rpx;
  569. font-size: 32rpx;
  570. color: #FF9797;
  571. }
  572. }
  573. .inpedit{
  574. margin-top: 24rpx;
  575. margin-left: 14rpx;
  576. font-size: 28rpx;
  577. color: #FF9797;
  578. }
  579. .comfirm{
  580. display: flex;
  581. justify-content: flex-end;
  582. margin-top: 54rpx;
  583. .comfirm1{
  584. padding: 12rpx 24rpx;
  585. border-radius: 12rpx;
  586. color: #FFFFFF;
  587. background-color: #E63931;
  588. }
  589. }
  590. }
  591. /* #endif */
  592. </style>