location.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. <espempty v-if="list.length === 0 && loaded"></espempty>
  49. </view>
  50. <uni-popup ref="popup" type="center" @click="close">
  51. <view class="popup_row">
  52. <view class="title">
  53. <view class="title-left">
  54. 请输入您的手机号,等待救援!
  55. </view>
  56. <view class="cancel" @click="cancel">
  57. <image src="../../static/img/cancel1.png" mode=""></image>
  58. </view>
  59. </view>
  60. <view class="inpBox">
  61. <input type="text" value="" placeholder="请输入您的手机号" v-model="to_phone" />
  62. </view>
  63. <view class="inpedit">
  64. 可在方框中修改您的手机号
  65. </view>
  66. <view class="comfirm">
  67. <view class="comfirm1" @click="comfirm1()">
  68. 确认
  69. </view>
  70. </view>
  71. </view>
  72. </uni-popup>
  73. </view>
  74. </template>
  75. <script>
  76. import {
  77. mapState,
  78. mapMutations
  79. } from 'vuex';
  80. import espempty from '@/components/espempty';
  81. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  82. import {
  83. getdis,
  84. tocall
  85. } from '@/api/index.js';
  86. import {
  87. userinfo
  88. } from '@/api/user.js';
  89. import {
  90. getcomAddress
  91. } from '@/api/index.js';
  92. import {
  93. getMechanismList,
  94. applyRescuer,
  95. getRescuerList,
  96. getApplyList,
  97. sos,
  98. geocoder
  99. } from '@/api/category.js'
  100. export default {
  101. components: {
  102. uniPopup,
  103. espempty,
  104. },
  105. //相关配置参数
  106. data() {
  107. return {
  108. user_id: '',
  109. rescuers_id: 0,
  110. loadingType: 'more',
  111. loaded: false,
  112. page: 1,
  113. limit: 100,
  114. list: [],
  115. latitude: '',
  116. longitude: '',
  117. current: 0,
  118. name: '',
  119. uid: '',
  120. name: '',
  121. phone: '',
  122. to_phone: '',
  123. marker: [],
  124. specificAdd: '',
  125. user_address: '', //用户地址逆解析
  126. addressData: {
  127. name: '',
  128. mobile: '',
  129. latitude: 0, //纬度
  130. longitude: 0, //经度
  131. address: {
  132. province: '',
  133. city: '',
  134. district: '',
  135. detail: '',
  136. },
  137. area: '',
  138. default: false
  139. },
  140. }
  141. },
  142. onLoad() {
  143. let obj = this;
  144. obj.getLocal()
  145. console.log('开始加载事件');
  146. obj.loadBaseData();
  147. },
  148. computed: {
  149. ...mapState('user', ['hasLogin', 'userInfo'])
  150. },
  151. methods: {
  152. ...mapMutations('user', ['setUserInfo']),
  153. // 获取本地坐标
  154. getLocal() {
  155. let obj = this;
  156. console.log('ddddddddddddddddddddddddd')
  157. uni.getLocation({
  158. type: 'gcj02',
  159. success(e) {
  160. console.log(e)
  161. obj.latitude = Math.abs(e.latitude)
  162. obj.longitude = Math.abs(e.longitude)
  163. console.log('本地坐标', obj.latitude, obj.longitude)
  164. geocoder({
  165. latitude: obj.latitude,
  166. longitude: obj.longitude
  167. }).then(res => {
  168. console.log(res)
  169. obj.user_address = res.data.result.address
  170. console.log(obj.user_address, 'obj.user_address')
  171. })
  172. let item = {
  173. id: 0,
  174. latitude: obj.latitude,
  175. longitude: obj.longitude,
  176. iconPath: '/static/img/img19.png',
  177. width: '35',
  178. height: '35',
  179. }
  180. obj.marker.push(item)
  181. obj.getRescuerList(obj.latitude, obj.longitude)
  182. }
  183. })
  184. },
  185. // 获取救援者列表
  186. getRescuerList(lat, lon) {
  187. let obj = this
  188. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  189. return
  190. }
  191. obj.loadingType = 'loading'
  192. getRescuerList({
  193. page: obj.page,
  194. limit: obj.limit,
  195. latitude: lat,
  196. longitude: lon,
  197. }).then(res => {
  198. // this.peoplelist = res.data
  199. let arr = []
  200. res.data.forEach(item => {
  201. let pro = {
  202. id: item.id * 1,
  203. latitude: item.latitude,
  204. longitude: item.longitude,
  205. iconPath: '/static/img/img014.png',
  206. width: '35',
  207. height: '35',
  208. }
  209. arr.push(pro)
  210. })
  211. obj.list = obj.list.concat(res.data)
  212. obj.marker = obj.marker.concat(arr)
  213. if (res.data.length == obj.limit) {
  214. obj.loadingType = 'more'
  215. } else {
  216. obj.loadingType = 'noMore'
  217. }
  218. obj.$set(obj, 'loaded', true)
  219. })
  220. },
  221. loadBaseData() {
  222. userinfo({}).then(({
  223. data
  224. }) => {
  225. console.log(123, data)
  226. this.to_phone = data.mobile
  227. this.setUserInfo(data);
  228. });
  229. },
  230. // 地图渲染完毕事件
  231. mapChange(e) {
  232. console.log(e);
  233. },
  234. cancel() {
  235. this.$refs.popup.close();
  236. },
  237. comfirm1: function() {
  238. let obj = this
  239. if (obj.to_phone.toString().trim() == '') {
  240. return obj.$api.msg('请输入手机号码')
  241. } else {
  242. console.log('obj.to_phone1111', obj.to_phone)
  243. const reg = /^(\+?0?86-?)?1[\d]\d{9}$/;
  244. if (!reg.test(obj.to_phone)) {
  245. obj.$api.msg('请填写正确的手机号码');
  246. return;
  247. }
  248. sos({
  249. mobile: obj.to_phone,
  250. address: obj.user_address,
  251. latitude: obj.latitude,
  252. longitude: obj.longitude,
  253. rescuers_id: obj.rescuers_id,
  254. user_id: obj.user_id
  255. }).then(res => {
  256. uni.showModal({
  257. title: '请耐心等待救援',
  258. success: res => {
  259. if (res.confirm) {
  260. window.location.reload(); //重新刷新页面
  261. }
  262. }
  263. })
  264. obj.$refs.popup.close();
  265. })
  266. }
  267. },
  268. // 立即救援
  269. rescue(item, index) {
  270. let obj = this;
  271. console.log(item, 'jiuzhu item')
  272. uni.showModal({
  273. content: '是否发起求救?',
  274. success: res => {
  275. if (res.confirm) {
  276. this.$refs.popup.open(item, index);
  277. obj.rescuers_id = item.id
  278. obj.user_id = item.user_id
  279. }
  280. }
  281. })
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="scss">
  287. body,
  288. page {
  289. height: 100%;
  290. width: 100%;
  291. background-color: #fff;
  292. }
  293. .content {
  294. height: 100%;
  295. width: 100%;
  296. background-color: #fff;
  297. }
  298. .map {
  299. width: 100%;
  300. height: 600rpx;
  301. }
  302. /* #ifdef H5 */
  303. .location {
  304. overflow-y: scroll; //溢出就滑动起来
  305. // z-index: 990;
  306. position: fixed;
  307. bottom: 0;
  308. height: 55%;
  309. width: 100%;
  310. background-color: #fff;
  311. padding: 24rpx;
  312. //搜索框
  313. .Search-box {
  314. // z-index: 999;
  315. height: 80rpx;
  316. // position: fixed;
  317. // top: 0;
  318. // left: 0;
  319. // width: 100%;
  320. // background: #FFFFFF;
  321. // padding-top: 10rpx;
  322. padding-right: 24rpx;
  323. padding-left: 24rpx;
  324. .Search-box-sort {
  325. float: left;
  326. margin-left: 32rpx;
  327. margin-right: 19rpx;
  328. .sort-text {
  329. width: 57rpx;
  330. height: 29rpx;
  331. font-size: 30rpx;
  332. font-weight: 500;
  333. color: rgba(51, 51, 51, 1);
  334. line-height: 58rpx;
  335. margin-right: 19rpx;
  336. }
  337. .sort-img {
  338. width: 21rpx;
  339. height: 11rpx;
  340. margin-bottom: 4rpx;
  341. }
  342. }
  343. .Search-box-size {
  344. // width:70%;
  345. height: 58rpx;
  346. border-radius: 32rpx;
  347. background-color: #f1f1f1;
  348. padding-left: 36rpx;
  349. display: flex;
  350. align-items: center;
  351. .box-img {
  352. height: 32rpx;
  353. width: 32rpx;
  354. margin-right: 16rpx;
  355. }
  356. // .box-right{
  357. // height: 58rpx;
  358. // // width: 100%;
  359. // background-color: pink;
  360. // }
  361. .box-word {
  362. width: 100%;
  363. font-size: 26rpx;
  364. font-weight: 500;
  365. color: rgba(205, 203, 203, 1);
  366. line-height: 55rpx;
  367. }
  368. }
  369. }
  370. .location-item {
  371. z-index: 1000;
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. border-bottom: 1rpx solid #E7E8EA;
  376. padding: 15rpx 0;
  377. .box-left {
  378. display: flex;
  379. .img01 {
  380. width: 8rpx;
  381. height: 28rpx;
  382. margin-right: 18rpx;
  383. image {
  384. width: 8rpx;
  385. height: 28rpx;
  386. }
  387. }
  388. .img02 {
  389. width: 117rpx;
  390. height: 117rpx;
  391. border-radius: 50%;
  392. image {
  393. width: 117rpx;
  394. height: 117rpx;
  395. border-radius: 50%;
  396. }
  397. }
  398. .info {
  399. margin-left: 16rpx;
  400. .info-header {
  401. display: flex;
  402. align-items: center;
  403. .name {
  404. font-size: 32rpx;
  405. color: #333333;
  406. }
  407. .distance {
  408. margin-left: 25rpx;
  409. font-size: 28rpx;
  410. color: #303133;
  411. }
  412. .location-icon {
  413. margin-left: 10rpx;
  414. width: 20rpx;
  415. height: 26rpx;
  416. image {
  417. width: 20rpx;
  418. height: 26rpx;
  419. display: inline;
  420. }
  421. }
  422. }
  423. .address {
  424. font-size: 26rpx;
  425. color: #333333;
  426. margin-top: 33rpx;
  427. }
  428. }
  429. }
  430. .box-right {
  431. .img {
  432. height: 107rpx;
  433. image {
  434. width: 107rpx;
  435. height: 107rpx;
  436. }
  437. }
  438. .called {
  439. margin-right: 16rpx;
  440. height: 107rpx;
  441. line-height: 107rpx;
  442. font-size: 28rpx;
  443. color: #CB131C;
  444. }
  445. }
  446. }
  447. }
  448. .popup_row {
  449. // margin-top: 108rpx;
  450. height: 440rpx;
  451. border-radius: 25rpx;
  452. width: 100%;
  453. padding: 24rpx;
  454. background-color: #f8f8f8;
  455. z-index: 999;
  456. .title {
  457. border-bottom: 2rpx solid #F2F2F2;
  458. color: #E63931;
  459. font-size: 32rpx;
  460. padding-left: 4rpx;
  461. padding-bottom: 16rpx;
  462. display: flex;
  463. justify-content: space-between;
  464. // align-items: center;
  465. .cancel {
  466. margin-left: 52rpx;
  467. width: 36rpx;
  468. height: 36rpx;
  469. image {
  470. width: 36rpx;
  471. height: 36rpx;
  472. }
  473. }
  474. }
  475. .inpBox {
  476. margin-top: 52rpx;
  477. border: 2px solid #f2f2f2;
  478. padding: 12rpx 24rpx;
  479. color: #FF9797;
  480. border-radius: 8rpx;
  481. .input-placeholder {
  482. // height: 70rpx;
  483. font-size: 32rpx;
  484. color: #FF9797;
  485. }
  486. }
  487. .inpedit {
  488. margin-top: 24rpx;
  489. margin-left: 14rpx;
  490. font-size: 28rpx;
  491. color: #FF9797;
  492. }
  493. .comfirm {
  494. display: flex;
  495. justify-content: flex-end;
  496. margin-top: 54rpx;
  497. .comfirm1 {
  498. padding: 12rpx 24rpx;
  499. border-radius: 12rpx;
  500. color: #FFFFFF;
  501. background-color: #E63931;
  502. }
  503. }
  504. }
  505. /* #endif */
  506. </style>