location.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. mapChange(e) {
  218. console.log(e);
  219. },
  220. // 载入数据
  221. async loadData() {
  222. let obj = this;
  223. getdis({
  224. lng1: obj.longitude,
  225. lat1: obj.latitude
  226. }).then((res) => {
  227. // uni.showModal({
  228. // title:'值',
  229. // content:JSON.stringify(res)
  230. // })
  231. let data = res.data;
  232. uni.hideLoading();
  233. console.log('请求数据', data);
  234. // obj.phone = data.phone
  235. console.log('data.phone333',data.phone)
  236. data = data.map(d => {
  237. return {
  238. ...d,
  239. iscall: true
  240. }
  241. })
  242. obj.list = data;
  243. let arr = data.map(item => ({
  244. latitude: item.latitude,
  245. longitude: item.longitude,
  246. iconPath: '/static/img/img014.png',
  247. width: '35',
  248. height: '35',
  249. id: item.id,
  250. address: item.address
  251. }))
  252. obj.marker = obj.marker.concat(arr)
  253. }).catch(err => {
  254. console.log(err);
  255. uni.hideLoading();
  256. // uni.showModal({
  257. // title: '失败',
  258. // content: JSON.stringify(err)
  259. // });
  260. });
  261. },
  262. cancel(){
  263. this.$refs.popup.close();
  264. },
  265. comfirm1:function () {
  266. let obj = this
  267. if ( obj.to_phone.toString().trim() == '' ){
  268. // uni.showModal({
  269. // title:'输入框为空',
  270. // // content:JSON.stringify(obj)
  271. // })
  272. } else {
  273. console.log('obj.to_phone1111',obj.to_phone)
  274. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  275. if (!reg.test(obj.to_phone)) {
  276. obj.$api.msg('请填写正确的手机号码');
  277. return;
  278. }
  279. console.log('name:',obj.name)
  280. console.log('uid:',obj.uid)
  281. console.log('phone',obj.phone)
  282. console.log('to_phone',obj.to_phone)
  283. console.log('longitude',obj.longitude)
  284. console.log('latitude',obj.latitude)
  285. console.log('iscall',obj.iscall)
  286. tocall({
  287. name: obj.name,
  288. uid: obj.uid,
  289. phone: obj.phone,
  290. longitude: obj.longitude,
  291. latitude: obj.latitude,
  292. to_phone:obj.to_phone
  293. }).then((data) => {
  294. console.log(99988,data)
  295. uni.showModal({
  296. title:'请耐心等待救援',
  297. success: res => {
  298. if (res.confirm) {
  299. window.location.reload(); //重新刷新页面
  300. }
  301. }
  302. })
  303. obj.$refs.popup.close();
  304. obj.iscall = false
  305. console.log(123,obj.iscall)
  306. })
  307. }
  308. },
  309. // comfirm2:function (item,index) {
  310. // let obj = this
  311. // },
  312. // 立即救援
  313. rescue(item, index) {
  314. let obj = this;
  315. uni.showModal({
  316. content: '是否发起求救?',
  317. success: res => {
  318. if (res.confirm) {
  319. this.$refs.popup.open(item,index);
  320. obj.name = item.name;
  321. obj.uid = item.uid;
  322. obj.phone = item.phone;
  323. obj.iscall = false
  324. console.log('点击救援时item.phone:',obj.phone)
  325. }
  326. }
  327. })
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss">
  333. body,
  334. page {
  335. height: 100%;
  336. width: 100%;
  337. background-color: #fff;
  338. }
  339. .content {
  340. height: 100%;
  341. width: 100%;
  342. background-color: #fff;
  343. }
  344. .map{
  345. width: 100%;
  346. height: 600rpx;
  347. }
  348. /* #ifdef H5 */
  349. .location {
  350. overflow-y: scroll; //溢出就滑动起来
  351. // z-index: 990;
  352. position: fixed;
  353. bottom: 0;
  354. height: 55%;
  355. width: 100%;
  356. background-color: #fff;
  357. padding: 24rpx;
  358. //搜索框
  359. .Search-box {
  360. // z-index: 999;
  361. height: 80rpx;
  362. // position: fixed;
  363. // top: 0;
  364. // left: 0;
  365. // width: 100%;
  366. // background: #FFFFFF;
  367. // padding-top: 10rpx;
  368. padding-right: 24rpx;
  369. padding-left: 24rpx;
  370. .Search-box-sort {
  371. float: left;
  372. margin-left: 32rpx;
  373. margin-right: 19rpx;
  374. .sort-text {
  375. width: 57rpx;
  376. height: 29rpx;
  377. font-size: 30rpx;
  378. font-weight: 500;
  379. color: rgba(51, 51, 51, 1);
  380. line-height: 58rpx;
  381. margin-right: 19rpx;
  382. }
  383. .sort-img {
  384. width: 21rpx;
  385. height: 11rpx;
  386. margin-bottom: 4rpx;
  387. }
  388. }
  389. .Search-box-size {
  390. // width:70%;
  391. height: 58rpx;
  392. border-radius: 32rpx;
  393. background-color: #f1f1f1;
  394. padding-left: 36rpx;
  395. display: flex;
  396. align-items: center;
  397. .box-img {
  398. height: 32rpx;
  399. width: 32rpx;
  400. margin-right: 16rpx;
  401. }
  402. // .box-right{
  403. // height: 58rpx;
  404. // // width: 100%;
  405. // background-color: pink;
  406. // }
  407. .box-word {
  408. width: 100%;
  409. font-size: 26rpx;
  410. font-weight: 500;
  411. color: rgba(205, 203, 203, 1);
  412. line-height: 55rpx;
  413. }
  414. }
  415. }
  416. .location-item {
  417. z-index: 1000;
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: center;
  421. border-bottom: 1rpx solid #E7E8EA;
  422. padding: 15rpx 0;
  423. .box-left {
  424. display: flex;
  425. .img01 {
  426. width: 8rpx;
  427. height: 28rpx;
  428. margin-right: 18rpx;
  429. image {
  430. width: 8rpx;
  431. height: 28rpx;
  432. }
  433. }
  434. .img02 {
  435. width: 117rpx;
  436. height: 117rpx;
  437. border-radius: 50%;
  438. image {
  439. width: 117rpx;
  440. height: 117rpx;
  441. border-radius: 50%;
  442. }
  443. }
  444. .info {
  445. margin-left: 16rpx;
  446. .info-header {
  447. display: flex;
  448. align-items: center;
  449. .name {
  450. font-size: 32rpx;
  451. color: #333333;
  452. }
  453. .distance {
  454. margin-left: 25rpx;
  455. font-size: 28rpx;
  456. color: #303133;
  457. }
  458. .location-icon {
  459. margin-left: 10rpx;
  460. width: 20rpx;
  461. height: 26rpx;
  462. image {
  463. width: 20rpx;
  464. height: 26rpx;
  465. display: inline;
  466. }
  467. }
  468. }
  469. .address {
  470. font-size: 26rpx;
  471. color: #333333;
  472. margin-top: 33rpx;
  473. }
  474. }
  475. }
  476. .box-right {
  477. .img {
  478. height: 107rpx;
  479. image {
  480. width: 107rpx;
  481. height: 107rpx;
  482. }
  483. }
  484. .called {
  485. margin-right: 16rpx;
  486. height: 107rpx;
  487. line-height: 107rpx;
  488. font-size: 28rpx;
  489. color: #CB131C;
  490. }
  491. }
  492. }
  493. }
  494. .popup_row{
  495. // margin-top: 108rpx;
  496. height: 440rpx;
  497. border-radius: 25rpx;
  498. width: 100%;
  499. padding: 24rpx;
  500. background-color: #f8f8f8;
  501. z-index: 999;
  502. .title{
  503. border-bottom: 2rpx solid #F2F2F2;
  504. color: #E63931;
  505. font-size: 32rpx;
  506. padding-left: 4rpx;
  507. padding-bottom: 16rpx;
  508. display: flex;
  509. justify-content: space-between;
  510. // align-items: center;
  511. .cancel{
  512. margin-left: 52rpx;
  513. width: 36rpx;
  514. height: 36rpx;
  515. image{
  516. width: 36rpx;
  517. height: 36rpx;
  518. }
  519. }
  520. }
  521. .inpBox{
  522. margin-top: 52rpx;
  523. border: 2px solid #f2f2f2;
  524. padding: 12rpx 24rpx;
  525. color: #FF9797;
  526. border-radius: 8rpx;
  527. .input-placeholder {
  528. // height: 70rpx;
  529. font-size: 32rpx;
  530. color: #FF9797;
  531. }
  532. }
  533. .inpedit{
  534. margin-top: 24rpx;
  535. margin-left: 14rpx;
  536. font-size: 28rpx;
  537. color: #FF9797;
  538. }
  539. .comfirm{
  540. display: flex;
  541. justify-content: flex-end;
  542. margin-top: 54rpx;
  543. .comfirm1{
  544. padding: 12rpx 24rpx;
  545. border-radius: 12rpx;
  546. color: #FFFFFF;
  547. background-color: #E63931;
  548. }
  549. }
  550. }
  551. /* #endif */
  552. </style>