location.vue 11 KB

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