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. },
  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: '',
  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/jiuyuan.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. re_url: obj.$store.state.baseURL + '/index/#/pages/applic/rescuerecords',
  297. }).then(res => {
  298. uni.showModal({
  299. title: '请耐心等待救援',
  300. success: res => {
  301. if (res.confirm) {
  302. window.location.reload(); //重新刷新页面
  303. }
  304. }
  305. })
  306. obj.$refs.popup.close();
  307. })
  308. }
  309. },
  310. // 立即救援
  311. rescue(item, index) {
  312. let obj = this;
  313. console.log(item, 'jiuzhu item')
  314. uni.showModal({
  315. content: '是否发起求救?',
  316. success: res => {
  317. if (res.confirm) {
  318. this.$refs.popup.open(item, index);
  319. obj.rescuers_id = item.id
  320. obj.user_id = item.user_id
  321. }
  322. }
  323. })
  324. }
  325. }
  326. }
  327. </script>
  328. <style lang="scss">
  329. body,
  330. page {
  331. height: 100%;
  332. width: 100%;
  333. background-color: #fff;
  334. }
  335. .content {
  336. height: 100%;
  337. width: 100%;
  338. background-color: #fff;
  339. }
  340. .map {
  341. width: 100%;
  342. height: 600rpx;
  343. }
  344. /* #ifdef H5 */
  345. .location {
  346. overflow-y: scroll; //溢出就滑动起来
  347. // z-index: 990;
  348. position: fixed;
  349. bottom: 0;
  350. height: 55%;
  351. width: 100%;
  352. background-color: #fff;
  353. padding: 24rpx;
  354. //搜索框
  355. .Search-box {
  356. // z-index: 999;
  357. height: 80rpx;
  358. // position: fixed;
  359. // top: 0;
  360. // left: 0;
  361. // width: 100%;
  362. // background: #FFFFFF;
  363. // padding-top: 10rpx;
  364. padding-right: 24rpx;
  365. padding-left: 24rpx;
  366. .Search-box-sort {
  367. float: left;
  368. margin-left: 32rpx;
  369. margin-right: 19rpx;
  370. .sort-text {
  371. width: 57rpx;
  372. height: 29rpx;
  373. font-size: 30rpx;
  374. font-weight: 500;
  375. color: rgba(51, 51, 51, 1);
  376. line-height: 58rpx;
  377. margin-right: 19rpx;
  378. }
  379. .sort-img {
  380. width: 21rpx;
  381. height: 11rpx;
  382. margin-bottom: 4rpx;
  383. }
  384. }
  385. .Search-box-size {
  386. // width:70%;
  387. height: 58rpx;
  388. border-radius: 32rpx;
  389. background-color: #f1f1f1;
  390. padding-left: 36rpx;
  391. display: flex;
  392. align-items: center;
  393. .box-img {
  394. height: 32rpx;
  395. width: 32rpx;
  396. margin-right: 16rpx;
  397. }
  398. // .box-right{
  399. // height: 58rpx;
  400. // // width: 100%;
  401. // background-color: pink;
  402. // }
  403. .box-word {
  404. width: 100%;
  405. font-size: 26rpx;
  406. font-weight: 500;
  407. color: rgba(205, 203, 203, 1);
  408. line-height: 55rpx;
  409. }
  410. }
  411. }
  412. .location-item {
  413. z-index: 1000;
  414. display: flex;
  415. justify-content: space-between;
  416. align-items: center;
  417. border-bottom: 1rpx solid #E7E8EA;
  418. padding: 15rpx 0;
  419. .box-left {
  420. display: flex;
  421. .img01 {
  422. width: 8rpx;
  423. height: 28rpx;
  424. margin-right: 18rpx;
  425. image {
  426. width: 8rpx;
  427. height: 28rpx;
  428. }
  429. }
  430. .img02 {
  431. width: 117rpx;
  432. height: 117rpx;
  433. border-radius: 50%;
  434. image {
  435. width: 117rpx;
  436. height: 117rpx;
  437. border-radius: 50%;
  438. }
  439. }
  440. .info {
  441. margin-left: 16rpx;
  442. .info-header {
  443. display: flex;
  444. align-items: center;
  445. .name {
  446. font-size: 32rpx;
  447. color: #333333;
  448. }
  449. .distance {
  450. margin-left: 25rpx;
  451. font-size: 28rpx;
  452. color: #303133;
  453. }
  454. .location-icon {
  455. margin-left: 10rpx;
  456. width: 20rpx;
  457. height: 26rpx;
  458. image {
  459. width: 20rpx;
  460. height: 26rpx;
  461. display: inline;
  462. }
  463. }
  464. }
  465. .address {
  466. font-size: 26rpx;
  467. color: #333333;
  468. margin-top: 33rpx;
  469. }
  470. }
  471. }
  472. .box-right {
  473. flex-shrink: 0;
  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>