location.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. // #ifdef H5
  299. from: 'weixin'
  300. // #endif
  301. }).then(res => {
  302. uni.showModal({
  303. title: '请耐心等待救援',
  304. success: res => {
  305. if (res.confirm) {
  306. window.location.reload(); //重新刷新页面
  307. }
  308. }
  309. })
  310. obj.$refs.popup.close();
  311. })
  312. }
  313. },
  314. // 立即救援
  315. rescue(item, index) {
  316. let obj = this;
  317. console.log(item, 'jiuzhu item')
  318. uni.showModal({
  319. content: '是否发起求救?',
  320. success: res => {
  321. if (res.confirm) {
  322. this.$refs.popup.open(item, index);
  323. obj.rescuers_id = item.id
  324. obj.user_id = item.user_id
  325. }
  326. }
  327. })
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss">
  333. body,
  334. page {
  335. height: 100%;
  336. width: 100%;
  337. background-color: #fff;
  338. }
  339. .content {
  340. height: 100%;
  341. width: 100%;
  342. background-color: #fff;
  343. }
  344. .map {
  345. width: 100%;
  346. height: 600rpx;
  347. }
  348. /* #ifdef H5 */
  349. .location {
  350. overflow-y: scroll; //溢出就滑动起来
  351. // z-index: 990;
  352. position: fixed;
  353. bottom: 0;
  354. height: 55%;
  355. width: 100%;
  356. background-color: #fff;
  357. padding: 24rpx;
  358. //搜索框
  359. .Search-box {
  360. // z-index: 999;
  361. height: 80rpx;
  362. // position: fixed;
  363. // top: 0;
  364. // left: 0;
  365. // width: 100%;
  366. // background: #FFFFFF;
  367. // padding-top: 10rpx;
  368. padding-right: 24rpx;
  369. padding-left: 24rpx;
  370. .Search-box-sort {
  371. float: left;
  372. margin-left: 32rpx;
  373. margin-right: 19rpx;
  374. .sort-text {
  375. width: 57rpx;
  376. height: 29rpx;
  377. font-size: 30rpx;
  378. font-weight: 500;
  379. color: rgba(51, 51, 51, 1);
  380. line-height: 58rpx;
  381. margin-right: 19rpx;
  382. }
  383. .sort-img {
  384. width: 21rpx;
  385. height: 11rpx;
  386. margin-bottom: 4rpx;
  387. }
  388. }
  389. .Search-box-size {
  390. // width:70%;
  391. height: 58rpx;
  392. border-radius: 32rpx;
  393. background-color: #f1f1f1;
  394. padding-left: 36rpx;
  395. display: flex;
  396. align-items: center;
  397. .box-img {
  398. height: 32rpx;
  399. width: 32rpx;
  400. margin-right: 16rpx;
  401. }
  402. // .box-right{
  403. // height: 58rpx;
  404. // // width: 100%;
  405. // background-color: pink;
  406. // }
  407. .box-word {
  408. width: 100%;
  409. font-size: 26rpx;
  410. font-weight: 500;
  411. color: rgba(205, 203, 203, 1);
  412. line-height: 55rpx;
  413. }
  414. }
  415. }
  416. .location-item {
  417. z-index: 1000;
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: center;
  421. border-bottom: 1rpx solid #E7E8EA;
  422. padding: 15rpx 0;
  423. .box-left {
  424. display: flex;
  425. .img01 {
  426. width: 8rpx;
  427. height: 28rpx;
  428. margin-right: 18rpx;
  429. image {
  430. width: 8rpx;
  431. height: 28rpx;
  432. }
  433. }
  434. .img02 {
  435. width: 117rpx;
  436. height: 117rpx;
  437. border-radius: 50%;
  438. image {
  439. width: 117rpx;
  440. height: 117rpx;
  441. border-radius: 50%;
  442. }
  443. }
  444. .info {
  445. margin-left: 16rpx;
  446. .info-header {
  447. display: flex;
  448. align-items: center;
  449. .name {
  450. font-size: 32rpx;
  451. color: #333333;
  452. }
  453. .distance {
  454. margin-left: 25rpx;
  455. font-size: 28rpx;
  456. color: #303133;
  457. }
  458. .location-icon {
  459. margin-left: 10rpx;
  460. width: 20rpx;
  461. height: 26rpx;
  462. image {
  463. width: 20rpx;
  464. height: 26rpx;
  465. display: inline;
  466. }
  467. }
  468. }
  469. .address {
  470. font-size: 26rpx;
  471. color: #333333;
  472. margin-top: 33rpx;
  473. }
  474. }
  475. }
  476. .box-right {
  477. .img {
  478. height: 107rpx;
  479. image {
  480. width: 107rpx;
  481. height: 107rpx;
  482. }
  483. }
  484. .called {
  485. margin-right: 16rpx;
  486. height: 107rpx;
  487. line-height: 107rpx;
  488. font-size: 28rpx;
  489. color: #CB131C;
  490. }
  491. }
  492. }
  493. }
  494. .popup_row {
  495. // margin-top: 108rpx;
  496. height: 440rpx;
  497. border-radius: 25rpx;
  498. width: 100%;
  499. padding: 24rpx;
  500. background-color: #f8f8f8;
  501. z-index: 999;
  502. .title {
  503. border-bottom: 2rpx solid #F2F2F2;
  504. color: #E63931;
  505. font-size: 32rpx;
  506. padding-left: 4rpx;
  507. padding-bottom: 16rpx;
  508. display: flex;
  509. justify-content: space-between;
  510. // align-items: center;
  511. .cancel {
  512. margin-left: 52rpx;
  513. width: 36rpx;
  514. height: 36rpx;
  515. image {
  516. width: 36rpx;
  517. height: 36rpx;
  518. }
  519. }
  520. }
  521. .inpBox {
  522. margin-top: 52rpx;
  523. border: 2px solid #f2f2f2;
  524. padding: 12rpx 24rpx;
  525. color: #FF9797;
  526. border-radius: 8rpx;
  527. .input-placeholder {
  528. // height: 70rpx;
  529. font-size: 32rpx;
  530. color: #FF9797;
  531. }
  532. }
  533. .inpedit {
  534. margin-top: 24rpx;
  535. margin-left: 14rpx;
  536. font-size: 28rpx;
  537. color: #FF9797;
  538. }
  539. .comfirm {
  540. display: flex;
  541. justify-content: flex-end;
  542. margin-top: 54rpx;
  543. .comfirm1 {
  544. padding: 12rpx 24rpx;
  545. border-radius: 12rpx;
  546. color: #FFFFFF;
  547. background-color: #E63931;
  548. }
  549. }
  550. }
  551. /* #endif */
  552. </style>