location.vue 14 KB

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