location1.vue 13 KB

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