location.vue 11 KB

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