location.vue 12 KB

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