location.vue 13 KB

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