location.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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:"30.353495",
  104. longitude: "114.316738",
  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. // latitude:"30.353495",
  169. // longitude: "114.316738",
  170. obj.longitude = "114.316738"
  171. obj.latitude = "30.353495"
  172. obj.marker = [
  173. {
  174. latitude: obj.latitude,
  175. longitude: obj.longitude,
  176. iconPath: '/static/img/img19.png',
  177. width: '45',
  178. height: '45',
  179. },
  180. ]
  181. obj.loadData();
  182. }
  183. });
  184. })
  185. } catch (e) {
  186. console.log(e);
  187. let locationAddress
  188. // #ifdef H5
  189. let wxOjb = require('jweixin-module');
  190. locationAddress = wxOjb.getLocation;
  191. // #endif
  192. // #ifdef MP
  193. locationAddress = uni.getLocation;
  194. // #endif
  195. wxOjb.ready(()=>{
  196. console.log('加载完毕注册事件');
  197. locationAddress({
  198. type: 'gcj02',
  199. success: function(res) {
  200. console.log('获取经纬度1', res);
  201. obj.longitude = res.longitude
  202. obj.latitude = res.latitude
  203. obj.loadData();
  204. },
  205. fail(e) {
  206. obj.longitude = "114.316738"
  207. obj.latitude = "30.353495"
  208. obj.marker = [
  209. {
  210. latitude: obj.latitude,
  211. longitude: obj.longitude,
  212. iconPath: '/static/img/img19.png',
  213. width: '45',
  214. height: '45',
  215. },
  216. ]
  217. obj.loadData();
  218. }
  219. });
  220. })
  221. }
  222. },
  223. computed: {
  224. ...mapState('user', ['hasLogin', 'userInfo'])
  225. },
  226. methods: {
  227. ...mapMutations('user', ['setUserInfo']),
  228. loadBaseData() {
  229. userinfo({}).then(({
  230. data
  231. }) => {
  232. console.log(123,data)
  233. this.to_phone = data.phone
  234. this.setUserInfo(data);
  235. });
  236. },
  237. // 选择当前位置
  238. // chooseAddress() {
  239. // console.log('233')
  240. // let obj = this;
  241. // uni.chooseLocation({
  242. // success: function(res) {
  243. // console.log(res)
  244. // obj.addressData.area = res.name;
  245. // console.log('位置名称:' + res.name);
  246. // console.log('详细地址:' + res.address);
  247. // console.log('经度:' + res.longitude);
  248. // console.log('纬度:' + res.latitude);
  249. // obj.latitude = res.latitude;
  250. // obj.longitude = res.longitude;
  251. // obj.marker = [
  252. // {
  253. // latitude: obj.latitude,
  254. // longitude: obj.longitude,
  255. // iconPath: '/static/img/img19.png',
  256. // width: '48',
  257. // height: '48',
  258. // },
  259. // ]
  260. // obj.addressData.latitude = res.latitude;
  261. // obj.addressData.longitude = res.longitude;
  262. // obj.addressDetail = res.address;
  263. // console.log('common_address123',obj.addressDetail )
  264. // console.log('latitude123',obj.addressData.latitude )
  265. // console.log('longitude123',obj.addressData.longitude )
  266. // obj.loadData()
  267. // // getcomAddress({
  268. // // common_address: obj.addressDetail,
  269. // // longitude: obj.addressData.longitude,
  270. // // latitude: obj.addressData.latitude
  271. // // }).then(data => {
  272. // // console.log(333)
  273. // // console.log(data);
  274. // // if (data.status == 200) {
  275. // // obj.$api.msg('保存成功')
  276. // // }
  277. // // })
  278. // }
  279. // });
  280. // },
  281. // 地图渲染完毕事件
  282. mapChange(e) {
  283. console.log(e);
  284. },
  285. // 载入数据
  286. async loadData() {
  287. let obj = this;
  288. getdis({
  289. lng1: obj.longitude,
  290. lat1: obj.latitude
  291. }).then((res) => {
  292. // uni.showModal({
  293. // title:'值',
  294. // content:JSON.stringify(res)
  295. // })
  296. let data = res.data;
  297. uni.hideLoading();
  298. console.log('请求数据', data);
  299. // obj.phone = data.phone
  300. console.log('data.phone333',data.phone)
  301. data = data.map(d => {
  302. return {
  303. ...d,
  304. iscall: true
  305. }
  306. })
  307. obj.list = data;
  308. let arr = data.map(item => ({
  309. latitude: item.latitude,
  310. longitude: item.longitude,
  311. iconPath: '/static/img/img014.png',
  312. width: '35',
  313. height: '35',
  314. id: item.id,
  315. address: item.address
  316. }))
  317. obj.marker = obj.marker.concat(arr)
  318. }).catch(err => {
  319. console.log(err);
  320. uni.hideLoading();
  321. uni.showModal({
  322. title: '失败',
  323. content: JSON.stringify(err)
  324. });
  325. });
  326. },
  327. cancel(){
  328. this.$refs.popup.close();
  329. },
  330. comfirm1:function () {
  331. let obj = this
  332. if ( obj.to_phone.toString().trim() == '' ){
  333. // uni.showModal({
  334. // title:'输入框为空',
  335. // // content:JSON.stringify(obj)
  336. // })
  337. } else {
  338. console.log('obj.to_phone1111',obj.to_phone)
  339. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  340. if (!reg.test(obj.to_phone)) {
  341. obj.$api.msg('请填写正确的手机号码');
  342. return;
  343. }
  344. console.log('name:',obj.name)
  345. console.log('uid:',obj.uid)
  346. console.log('phone',obj.phone)
  347. console.log('to_phone',obj.to_phone)
  348. console.log('longitude',obj.longitude)
  349. console.log('latitude',obj.latitude)
  350. console.log('iscall',obj.iscall)
  351. tocall({
  352. name: obj.name,
  353. uid: obj.uid,
  354. phone: obj.phone,
  355. longitude: obj.longitude,
  356. latitude: obj.latitude,
  357. to_phone:obj.to_phone
  358. }).then((data) => {
  359. console.log(99988,data)
  360. uni.showModal({
  361. title:'请耐心等待救援',
  362. success: res => {
  363. if (res.confirm) {
  364. window.location.reload(); //重新刷新页面
  365. }
  366. }
  367. })
  368. obj.$refs.popup.close();
  369. obj.iscall = false
  370. console.log(123,obj.iscall)
  371. })
  372. }
  373. },
  374. // comfirm2:function (item,index) {
  375. // let obj = this
  376. // },
  377. // 立即救援
  378. rescue(item, index) {
  379. let obj = this;
  380. uni.showModal({
  381. content: '是否发起求救?',
  382. success: res => {
  383. if (res.confirm) {
  384. this.$refs.popup.open(item,index);
  385. obj.name = item.name;
  386. obj.uid = item.uid;
  387. obj.phone = item.phone;
  388. obj.iscall = false
  389. console.log('点击救援时item.phone:',obj.phone)
  390. }
  391. }
  392. })
  393. }
  394. }
  395. }
  396. </script>
  397. <style lang="scss">
  398. body,
  399. page {
  400. height: 100%;
  401. width: 100%;
  402. background-color: #fff;
  403. }
  404. .content {
  405. height: 100%;
  406. width: 100%;
  407. background-color: #fff;
  408. }
  409. .map{
  410. width: 100%;
  411. height: 600rpx;
  412. }
  413. /* #ifdef H5 */
  414. .location {
  415. overflow-y: scroll; //溢出就滑动起来
  416. // z-index: 990;
  417. position: fixed;
  418. bottom: 0;
  419. height: 55%;
  420. width: 100%;
  421. background-color: #fff;
  422. padding: 24rpx;
  423. //搜索框
  424. .Search-box {
  425. // z-index: 999;
  426. height: 80rpx;
  427. // position: fixed;
  428. // top: 0;
  429. // left: 0;
  430. // width: 100%;
  431. // background: #FFFFFF;
  432. // padding-top: 10rpx;
  433. padding-right: 24rpx;
  434. padding-left: 24rpx;
  435. .Search-box-sort {
  436. float: left;
  437. margin-left: 32rpx;
  438. margin-right: 19rpx;
  439. .sort-text {
  440. width: 57rpx;
  441. height: 29rpx;
  442. font-size: 30rpx;
  443. font-weight: 500;
  444. color: rgba(51, 51, 51, 1);
  445. line-height: 58rpx;
  446. margin-right: 19rpx;
  447. }
  448. .sort-img {
  449. width: 21rpx;
  450. height: 11rpx;
  451. margin-bottom: 4rpx;
  452. }
  453. }
  454. .Search-box-size {
  455. // width:70%;
  456. height: 58rpx;
  457. border-radius: 32rpx;
  458. background-color: #f1f1f1;
  459. padding-left: 36rpx;
  460. display: flex;
  461. align-items: center;
  462. .box-img {
  463. height: 32rpx;
  464. width: 32rpx;
  465. margin-right: 16rpx;
  466. }
  467. // .box-right{
  468. // height: 58rpx;
  469. // // width: 100%;
  470. // background-color: pink;
  471. // }
  472. .box-word {
  473. width: 100%;
  474. font-size: 26rpx;
  475. font-weight: 500;
  476. color: rgba(205, 203, 203, 1);
  477. line-height: 55rpx;
  478. }
  479. }
  480. }
  481. .location-item {
  482. z-index: 1000;
  483. display: flex;
  484. justify-content: space-between;
  485. align-items: center;
  486. border-bottom: 1rpx solid #E7E8EA;
  487. padding: 15rpx 0;
  488. .box-left {
  489. display: flex;
  490. .img01 {
  491. width: 8rpx;
  492. height: 28rpx;
  493. margin-right: 18rpx;
  494. image {
  495. width: 8rpx;
  496. height: 28rpx;
  497. }
  498. }
  499. .img02 {
  500. width: 117rpx;
  501. height: 117rpx;
  502. border-radius: 50%;
  503. image {
  504. width: 117rpx;
  505. height: 117rpx;
  506. border-radius: 50%;
  507. }
  508. }
  509. .info {
  510. margin-left: 16rpx;
  511. .info-header {
  512. display: flex;
  513. align-items: center;
  514. .name {
  515. font-size: 32rpx;
  516. color: #333333;
  517. }
  518. .distance {
  519. margin-left: 25rpx;
  520. font-size: 28rpx;
  521. color: #303133;
  522. }
  523. .location-icon {
  524. margin-left: 10rpx;
  525. width: 20rpx;
  526. height: 26rpx;
  527. image {
  528. width: 20rpx;
  529. height: 26rpx;
  530. display: inline;
  531. }
  532. }
  533. }
  534. .address {
  535. font-size: 26rpx;
  536. color: #333333;
  537. margin-top: 33rpx;
  538. }
  539. }
  540. }
  541. .box-right {
  542. .img {
  543. height: 107rpx;
  544. image {
  545. width: 107rpx;
  546. height: 107rpx;
  547. }
  548. }
  549. .called {
  550. margin-right: 16rpx;
  551. height: 107rpx;
  552. line-height: 107rpx;
  553. font-size: 28rpx;
  554. color: #CB131C;
  555. }
  556. }
  557. }
  558. }
  559. .popup_row{
  560. // margin-top: 108rpx;
  561. height: 440rpx;
  562. border-radius: 25rpx;
  563. width: 100%;
  564. padding: 24rpx;
  565. background-color: #f8f8f8;
  566. z-index: 999;
  567. .title{
  568. border-bottom: 2rpx solid #F2F2F2;
  569. color: #E63931;
  570. font-size: 32rpx;
  571. padding-left: 4rpx;
  572. padding-bottom: 16rpx;
  573. display: flex;
  574. justify-content: space-between;
  575. // align-items: center;
  576. .cancel{
  577. margin-left: 52rpx;
  578. width: 36rpx;
  579. height: 36rpx;
  580. image{
  581. width: 36rpx;
  582. height: 36rpx;
  583. }
  584. }
  585. }
  586. .inpBox{
  587. margin-top: 52rpx;
  588. border: 2px solid #f2f2f2;
  589. padding: 12rpx 24rpx;
  590. color: #FF9797;
  591. border-radius: 8rpx;
  592. .input-placeholder {
  593. // height: 70rpx;
  594. font-size: 32rpx;
  595. color: #FF9797;
  596. }
  597. }
  598. .inpedit{
  599. margin-top: 24rpx;
  600. margin-left: 14rpx;
  601. font-size: 28rpx;
  602. color: #FF9797;
  603. }
  604. .comfirm{
  605. display: flex;
  606. justify-content: flex-end;
  607. margin-top: 54rpx;
  608. .comfirm1{
  609. padding: 12rpx 24rpx;
  610. border-radius: 12rpx;
  611. color: #FFFFFF;
  612. background-color: #E63931;
  613. }
  614. }
  615. }
  616. /* #endif */
  617. </style>