location.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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"></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. },
  152. methods: {
  153. ...mapMutations('user', ['setUserInfo']),
  154. // 获取本地坐标
  155. getLocal() {
  156. let obj = this;
  157. let weichatBrowser = uni.getStorageSync('weichatBrowser')
  158. if(weichatBrowser) {
  159. let wxOjb = require('jweixin-module');
  160. wxOjb.ready(() => {
  161. console.log('加载完毕注册事件');
  162. wxOjb.getLocation({
  163. type: 'gcj02',
  164. success(e) {
  165. console.log(e)
  166. obj.latitude = Math.abs(e.latitude)
  167. obj.longitude = Math.abs(e.longitude)
  168. console.log('本地坐标', obj.latitude, obj.longitude)
  169. geocoder({
  170. latitude: obj.latitude,
  171. longitude: obj.longitude
  172. }).then(res => {
  173. console.log(res)
  174. obj.user_address = res.data.result.address
  175. console.log(obj.user_address, 'obj.user_address')
  176. })
  177. let item = {
  178. id: 0,
  179. latitude: obj.latitude,
  180. longitude: obj.longitude,
  181. iconPath: '/static/img/img19.png',
  182. width: '35',
  183. height: '35',
  184. }
  185. obj.marker.push(item)
  186. obj.getRescuerList(obj.latitude, obj.longitude)
  187. },
  188. fail(err) {
  189. obj.getLocal()
  190. }
  191. })
  192. })
  193. }else {
  194. uni.getLocation({
  195. type: 'gcj02',
  196. success(e) {
  197. console.log(e)
  198. obj.latitude = Math.abs(e.latitude)
  199. obj.longitude = Math.abs(e.longitude)
  200. console.log('本地坐标', obj.latitude, obj.longitude)
  201. geocoder({
  202. latitude: obj.latitude,
  203. longitude: obj.longitude
  204. }).then(res => {
  205. console.log(res)
  206. obj.user_address = res.data.result.address
  207. console.log(obj.user_address, 'obj.user_address')
  208. })
  209. let item = {
  210. id: 0,
  211. latitude: obj.latitude,
  212. longitude: obj.longitude,
  213. iconPath: '/static/img/img19.png',
  214. width: '35',
  215. height: '35',
  216. }
  217. obj.marker.push(item)
  218. obj.getRescuerList(obj.latitude, obj.longitude)
  219. },
  220. fail(err) {
  221. obj.getLocal()
  222. }
  223. })
  224. }
  225. },
  226. // 获取救援者列表
  227. getRescuerList(lat, lon) {
  228. let obj = this
  229. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  230. return
  231. }
  232. obj.loadingType = 'loading'
  233. getRescuerList({
  234. page: obj.page,
  235. limit: obj.limit,
  236. latitude: lat,
  237. longitude: lon,
  238. }).then(res => {
  239. // this.peoplelist = res.data
  240. let arr = []
  241. res.data.forEach(item => {
  242. let pro = {
  243. id: item.id * 1,
  244. latitude: item.latitude,
  245. longitude: item.longitude,
  246. iconPath: '/static/img/img014.png',
  247. width: '35',
  248. height: '35',
  249. }
  250. arr.push(pro)
  251. })
  252. obj.list = obj.list.concat(res.data)
  253. obj.marker = obj.marker.concat(arr)
  254. if (res.data.length == obj.limit) {
  255. obj.loadingType = 'more'
  256. } else {
  257. obj.loadingType = 'noMore'
  258. }
  259. obj.$set(obj, 'loaded', true)
  260. })
  261. },
  262. loadBaseData() {
  263. userinfo({}).then(({
  264. data
  265. }) => {
  266. console.log(123, data)
  267. this.to_phone = data.mobile
  268. this.setUserInfo(data);
  269. });
  270. },
  271. // 地图渲染完毕事件
  272. mapChange(e) {
  273. console.log(e);
  274. },
  275. cancel() {
  276. this.$refs.popup.close();
  277. },
  278. comfirm1: function() {
  279. let obj = this
  280. if (obj.to_phone.toString().trim() == '') {
  281. return obj.$api.msg('请输入手机号码')
  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. sos({
  290. mobile: obj.to_phone,
  291. address: obj.user_address,
  292. latitude: obj.latitude,
  293. longitude: obj.longitude,
  294. rescuers_id: obj.rescuers_id,
  295. rescuers_user_id: obj.user_id
  296. }).then(res => {
  297. uni.showModal({
  298. title: '请耐心等待救援',
  299. success: res => {
  300. if (res.confirm) {
  301. window.location.reload(); //重新刷新页面
  302. }
  303. }
  304. })
  305. obj.$refs.popup.close();
  306. })
  307. }
  308. },
  309. // 立即救援
  310. rescue(item, index) {
  311. let obj = this;
  312. console.log(item, 'jiuzhu item')
  313. uni.showModal({
  314. content: '是否发起求救?',
  315. success: res => {
  316. if (res.confirm) {
  317. this.$refs.popup.open(item, index);
  318. obj.rescuers_id = item.id
  319. obj.user_id = item.user_id
  320. }
  321. }
  322. })
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss">
  328. body,
  329. page {
  330. height: 100%;
  331. width: 100%;
  332. background-color: #fff;
  333. }
  334. .content {
  335. height: 100%;
  336. width: 100%;
  337. background-color: #fff;
  338. }
  339. .map {
  340. width: 100%;
  341. height: 600rpx;
  342. }
  343. /* #ifdef H5 */
  344. .location {
  345. overflow-y: scroll; //溢出就滑动起来
  346. // z-index: 990;
  347. position: fixed;
  348. bottom: 0;
  349. height: 55%;
  350. width: 100%;
  351. background-color: #fff;
  352. padding: 24rpx;
  353. //搜索框
  354. .Search-box {
  355. // z-index: 999;
  356. height: 80rpx;
  357. // position: fixed;
  358. // top: 0;
  359. // left: 0;
  360. // width: 100%;
  361. // background: #FFFFFF;
  362. // padding-top: 10rpx;
  363. padding-right: 24rpx;
  364. padding-left: 24rpx;
  365. .Search-box-sort {
  366. float: left;
  367. margin-left: 32rpx;
  368. margin-right: 19rpx;
  369. .sort-text {
  370. width: 57rpx;
  371. height: 29rpx;
  372. font-size: 30rpx;
  373. font-weight: 500;
  374. color: rgba(51, 51, 51, 1);
  375. line-height: 58rpx;
  376. margin-right: 19rpx;
  377. }
  378. .sort-img {
  379. width: 21rpx;
  380. height: 11rpx;
  381. margin-bottom: 4rpx;
  382. }
  383. }
  384. .Search-box-size {
  385. // width:70%;
  386. height: 58rpx;
  387. border-radius: 32rpx;
  388. background-color: #f1f1f1;
  389. padding-left: 36rpx;
  390. display: flex;
  391. align-items: center;
  392. .box-img {
  393. height: 32rpx;
  394. width: 32rpx;
  395. margin-right: 16rpx;
  396. }
  397. // .box-right{
  398. // height: 58rpx;
  399. // // width: 100%;
  400. // background-color: pink;
  401. // }
  402. .box-word {
  403. width: 100%;
  404. font-size: 26rpx;
  405. font-weight: 500;
  406. color: rgba(205, 203, 203, 1);
  407. line-height: 55rpx;
  408. }
  409. }
  410. }
  411. .location-item {
  412. z-index: 1000;
  413. display: flex;
  414. justify-content: space-between;
  415. align-items: center;
  416. border-bottom: 1rpx solid #E7E8EA;
  417. padding: 15rpx 0;
  418. .box-left {
  419. display: flex;
  420. .img01 {
  421. width: 8rpx;
  422. height: 28rpx;
  423. margin-right: 18rpx;
  424. image {
  425. width: 8rpx;
  426. height: 28rpx;
  427. }
  428. }
  429. .img02 {
  430. width: 117rpx;
  431. height: 117rpx;
  432. border-radius: 50%;
  433. image {
  434. width: 117rpx;
  435. height: 117rpx;
  436. border-radius: 50%;
  437. }
  438. }
  439. .info {
  440. margin-left: 16rpx;
  441. .info-header {
  442. display: flex;
  443. align-items: center;
  444. .name {
  445. font-size: 32rpx;
  446. color: #333333;
  447. }
  448. .distance {
  449. margin-left: 25rpx;
  450. font-size: 28rpx;
  451. color: #303133;
  452. }
  453. .location-icon {
  454. margin-left: 10rpx;
  455. width: 20rpx;
  456. height: 26rpx;
  457. image {
  458. width: 20rpx;
  459. height: 26rpx;
  460. display: inline;
  461. }
  462. }
  463. }
  464. .address {
  465. font-size: 26rpx;
  466. color: #333333;
  467. margin-top: 33rpx;
  468. }
  469. }
  470. }
  471. .box-right {
  472. .img {
  473. height: 107rpx;
  474. image {
  475. width: 107rpx;
  476. height: 107rpx;
  477. }
  478. }
  479. .called {
  480. margin-right: 16rpx;
  481. height: 107rpx;
  482. line-height: 107rpx;
  483. font-size: 28rpx;
  484. color: #CB131C;
  485. }
  486. }
  487. }
  488. }
  489. .popup_row {
  490. // margin-top: 108rpx;
  491. height: 440rpx;
  492. border-radius: 25rpx;
  493. width: 100%;
  494. padding: 24rpx;
  495. background-color: #f8f8f8;
  496. z-index: 999;
  497. .title {
  498. border-bottom: 2rpx solid #F2F2F2;
  499. color: #E63931;
  500. font-size: 32rpx;
  501. padding-left: 4rpx;
  502. padding-bottom: 16rpx;
  503. display: flex;
  504. justify-content: space-between;
  505. // align-items: center;
  506. .cancel {
  507. margin-left: 52rpx;
  508. width: 36rpx;
  509. height: 36rpx;
  510. image {
  511. width: 36rpx;
  512. height: 36rpx;
  513. }
  514. }
  515. }
  516. .inpBox {
  517. margin-top: 52rpx;
  518. border: 2px solid #f2f2f2;
  519. padding: 12rpx 24rpx;
  520. color: #FF9797;
  521. border-radius: 8rpx;
  522. .input-placeholder {
  523. // height: 70rpx;
  524. font-size: 32rpx;
  525. color: #FF9797;
  526. }
  527. }
  528. .inpedit {
  529. margin-top: 24rpx;
  530. margin-left: 14rpx;
  531. font-size: 28rpx;
  532. color: #FF9797;
  533. }
  534. .comfirm {
  535. display: flex;
  536. justify-content: flex-end;
  537. margin-top: 54rpx;
  538. .comfirm1 {
  539. padding: 12rpx 24rpx;
  540. border-radius: 12rpx;
  541. color: #FFFFFF;
  542. background-color: #E63931;
  543. }
  544. }
  545. }
  546. /* #endif */
  547. </style>