location.vue 12 KB

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