location.vue 14 KB

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