index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <view class="content">
  3. <view id="container">
  4. <map class="map-box" id="map" show-location :markers="marker" :scale='scale' :latitude="latitude" :longitude="longitude"
  5. ref="map">
  6. </map>
  7. <image class="icon" @click="moveToLocation" src="/static/img/img015.png"></image>
  8. </view>
  9. <view class="swiper-box">
  10. <scroll-view class="cate-list" scroll-y @scrolltolower="loadData">
  11. <view class="nodata" v-if="list.length == 0">
  12. <image src="/static/img/img011.png"></image>
  13. <view class="text">很抱歉,附近没有救护人员!</view>
  14. </view>
  15. <view v-if="list.length > 0">
  16. <view v-for="(item, index) in list" :key="index" class="content-box flex">
  17. <view class="list flex_item">
  18. <view class="tip"></view>
  19. <view class="portrait">
  20. <image :src="item.avatar"></image>
  21. </view>
  22. <view class="info">
  23. <view class="name flex_item">
  24. <view class="info-name clamp">救援者{{ item.id }}</view>
  25. </view>
  26. <view class="address flex_item">
  27. <view class="juli">{{ item.distance }}m</view>
  28. <image src="../../static/img/img009.png"></image>
  29. </view>
  30. </view>
  31. <view class="btn submit" v-if="item.helped == 0" @click="Sos(item)">
  32. <image src="/static/img/img008.png"></image>
  33. </view>
  34. <view v-if="item.helped == 1" class="sos-type">已呼叫</view>
  35. </view>
  36. </view>
  37. <uni-load-more :status="loadingType"></uni-load-more>
  38. </view>
  39. </scroll-view>
  40. </view>
  41. <!-- <view class="Mask" v-show="MaskShow">
  42. <view class="Mask-box">
  43. <view class="title">求救信息</view>
  44. <textarea auto-height class="text" v-model="help_info" placeholder="请输入求救信息" />
  45. <textarea class="text"auto-height v-model="address" placeholder="请输入您的具体地址" />
  46. <view class="sos" @click="help">发送求救</view>
  47. </view>
  48. <view class="iconimage" @click="showCancel"><image src="../../static/img/delete.png"></image></view>
  49. </view> -->
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. mapState,
  55. mapMutations
  56. } from 'vuex';
  57. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  58. import {
  59. saveUrl,
  60. interceptor
  61. } from '@/utils/loginUtils.js';
  62. import empty from '@/components/empty';
  63. import {
  64. getAroundHelper,
  65. sendSos,
  66. newSos
  67. } from '@/api/record.js';
  68. import {
  69. openMap
  70. } from '@/utils/rocessor.js';
  71. import {
  72. getUserInfo
  73. } from '@/api/login.js';
  74. export default {
  75. data() {
  76. return {
  77. userInfo: '', //用户信息
  78. latitude: "",
  79. address: '', //请选择您的具体地址
  80. longitude: '',
  81. MaskShow: false,
  82. help_info: "", //求救信息
  83. scale: '16', //地图缩放程度
  84. marker: [],
  85. list: [],
  86. limit: 100, //每次加载数据条数
  87. page: 1, //当前页数
  88. loadingType: 'more', //加载更多状态
  89. loading: 0, //判断是否为点击搜索按钮跳转加载
  90. newSosList: '', //最新救援记录
  91. };
  92. },
  93. onLoad() {},
  94. computed: {
  95. ...mapState(['hasLogin'])
  96. },
  97. onShow() {
  98. if (this.hasLogin == false) {
  99. // 保存地址
  100. saveUrl();
  101. // 登录拦截
  102. // interceptor();
  103. } else {
  104. this.getAddressLocation();
  105. }
  106. this.loadBaseData()
  107. this.getAddressLocation();
  108. this.loadData();
  109. this.newSos();
  110. },
  111. //下拉刷新
  112. // onPullDownRefresh() {
  113. // this.page = 1
  114. // this.loadData('refresh');
  115. // },
  116. methods: {
  117. ...mapMutations(['setUserInfo', 'logout']),
  118. // 加载初始数据
  119. loadBaseData() {
  120. let obj = this;
  121. getUserInfo({}).then(({
  122. data
  123. }) => {
  124. obj.setUserInfo(data.user);
  125. }).catch((e) => {
  126. this.logout()
  127. console.log(e)
  128. });
  129. },
  130. //关闭弹窗
  131. showCancel() {
  132. this.MaskShow = false;
  133. },
  134. moveToLocation() {
  135. this.map = uni.createMapContext('map', this)
  136. this.map.moveToLocation({
  137. longitude: this.longitude,
  138. latitude: this.latitude,
  139. success: function() {
  140. console.log("成功将地图中心移到定位点")
  141. }
  142. })
  143. },
  144. loadData(type) {
  145. //这里是将订单挂载到tab列表下
  146. let obj = this;
  147. if (type != 'refresh') {
  148. console.log(obj.loadingType, '456')
  149. //没有更多数据直接跳出方法
  150. if (obj.loadingType === 'nomore') {
  151. return;
  152. } else {
  153. // 设置当前为数据载入中
  154. obj.loadingType = 'loading';
  155. }
  156. } else {
  157. //当重新加载数据时更新状态为可继续添加数据
  158. obj.loadingType = 'more';
  159. }
  160. getAroundHelper({
  161. page: obj.page,
  162. limit: obj.limit
  163. })
  164. .then(({
  165. data
  166. }) => {
  167. if (type === 'refresh') {
  168. obj.list = [];
  169. }
  170. let arr = data.map(e => {
  171. e.distance = e.distance.toFixed(2);
  172. return e;
  173. });
  174. obj.marker = data;
  175. let key = 'latitude';
  176. let ind = 'longitude';
  177. obj.marker.forEach((value, index) => {
  178. value['iconPath'] = '/static/img/img014.png';
  179. value['width'] = '35';
  180. value['height'] = '35';
  181. value[key] = value['lat'];
  182. value[ind] = value['lng'];
  183. });
  184. obj.list = obj.list.concat(arr);
  185. //判断是否还有下一页,有是more 没有是nomore
  186. if (obj.limit == obj.list.length) {
  187. obj.page++;
  188. obj.loadingType = 'more';
  189. } else {
  190. obj.loadingType = 'nomore';
  191. }
  192. // 判断是否为刷新数据
  193. if (type === 'refresh') {
  194. console.log('refresh')
  195. // 判断是否为点击搜索按钮跳转加载
  196. if (obj.loading == 1) {
  197. uni.hideLoading();
  198. } else {
  199. uni.stopPullDownRefresh();
  200. }
  201. }
  202. })
  203. .catch(e => {
  204. obj.loadingType = 'nomore';
  205. // obj.$api.msg(e.message);
  206. uni.hideLoading();
  207. });
  208. },
  209. newSos() {
  210. let obj = this;
  211. newSos({}).then((data) => {
  212. obj.newSosList = data.data;
  213. if (obj.newSosList == null) {
  214. console.log("暂无救援记录")
  215. } else {
  216. uni.showModal({
  217. title: '提示',
  218. content: '您有一条救援信息,点击查看',
  219. success: function(res) {
  220. if (res.confirm) {
  221. uni.switchTab({
  222. url: '/pages/record/rescue'
  223. })
  224. } else if (res.cancel) {
  225. console.log('用户点击取消');
  226. }
  227. }
  228. });
  229. }
  230. }).catch((e) => {
  231. console.log(e.message)
  232. });
  233. },
  234. //发送求救信号
  235. Sos(item) {
  236. let obj = this;
  237. sendSos({
  238. id: item.id,
  239. }).then((data) => {
  240. obj.$api.msg(data.msg);
  241. obj.page = 1
  242. obj.loadData('refresh');
  243. }).catch((e) => {
  244. obj.$api.msg(e.message);
  245. obj.page = 1
  246. obj.loadData('refresh');
  247. });
  248. },
  249. // 获取地址
  250. getAddressLocation() {
  251. let obj = this;
  252. uni.getLocation({
  253. type: 'gcj02',
  254. success(e) {
  255. obj.latitude = e.latitude;
  256. obj.longitude = e.longitude;
  257. uni.setStorageSync('Lat', e.latitude);
  258. uni.setStorageSync('Lng', e.longitude);
  259. obj.loadData('refresh');
  260. },
  261. fail(e) {
  262. obj.getLocation();
  263. }
  264. });
  265. },
  266. // 获取当前位置
  267. getLocation() {
  268. let obj = this;
  269. openMap().then(() => {
  270. obj.getAddressLocation();
  271. })
  272. .catch(e => {
  273. console.log('到这里')
  274. obj.latitude = Math.abs(28.372975)
  275. obj.longitude = Math.abs(121.385322)
  276. // obj.latitude = e.latitude;
  277. // obj.longitude = e.longitude;
  278. uni.setStorageSync('Lat', 28.372975);
  279. uni.setStorageSync('Lng', 121.385322);
  280. obj.loadData('refresh');
  281. // uni.showModal({
  282. // title: '提示',
  283. // content: '您未授权无法调用地图定位功能!',
  284. // showCancel: false,
  285. // success() {
  286. // obj.getLocation()
  287. // }
  288. // });
  289. });
  290. }
  291. }
  292. };
  293. </script>
  294. <style lang="scss">
  295. page {
  296. background: #ffffff;
  297. height: 100%;
  298. }
  299. .Mask {
  300. position: fixed;
  301. top: 0;
  302. width: 100%;
  303. height: 100%;
  304. background-color: rgba(51, 51, 51, 0.7);
  305. .Mask-box {
  306. text-align: center;
  307. margin: auto;
  308. margin-top: 200rpx;
  309. padding: 50rpx 50rpx;
  310. width: 80%;
  311. height: auto;
  312. left: 10%;
  313. background-color: #ffffff;
  314. border-radius: 15rpx;
  315. z-index: 999;
  316. .title {
  317. font-size: 35rpx;
  318. font-weight: 700;
  319. }
  320. .text {
  321. min-height: 120rpx;
  322. font-size: 30rpx;
  323. color: #848484;
  324. padding-top: 50rpx;
  325. border: 2rpx solid #F3F3F3;
  326. text-align: left !important;
  327. padding: 25rpx 25rpx;
  328. border-radius: 10rpx;
  329. margin: 50rpx 0rpx;
  330. width: 100%;
  331. }
  332. .sos {
  333. background: linear-gradient(90deg, rgba(255, 102, 102, 1), rgba(255, 79, 79, 1));
  334. width: 65%;
  335. margin: 0rpx auto;
  336. font-size: 30rpx;
  337. padding: 25rpx 25rpx;
  338. color: #ffffff;
  339. border-radius: 50rpx;
  340. border: none;
  341. }
  342. }
  343. .iconimage {
  344. text-align: center;
  345. margin-top: 60rpx;
  346. image {
  347. width: 80rpx;
  348. height: 80rpx;
  349. }
  350. }
  351. }
  352. .content {
  353. height: 100%;
  354. }
  355. .icon {
  356. position: fixed;
  357. top: 390rpx;
  358. right: 35rpx;
  359. width: 100rpx;
  360. height: 100rpx;
  361. }
  362. .map-box {
  363. width: 100%;
  364. height: 700rpx;
  365. }
  366. .nodata {
  367. width: 430rpx;
  368. margin: 0rpx auto;
  369. padding-top: 80rpx;
  370. image {
  371. width: 430rpx;
  372. height: 337rpx;
  373. }
  374. .text {
  375. text-align: center;
  376. color: #999999;
  377. font-size: 26rpx;
  378. }
  379. }
  380. .swiper-box {
  381. position: fixed;
  382. bottom: 0rpx;
  383. height: 50%;
  384. width: 100%;
  385. background-color: #ffffff;
  386. border-top-left-radius: 25rpx;
  387. border-top-right-radius: 25rpx;
  388. box-shadow: 0px -11px 42px 4px rgba(83, 87, 120, 0.2);
  389. .cate-list {
  390. height: 100%;
  391. }
  392. }
  393. .content-box {
  394. padding: 0rpx 30rpx;
  395. font-size: 24rpx;
  396. color: #666666;
  397. width: 100%;
  398. .list {
  399. padding: 25rpx 0rpx;
  400. margin-top: 25rpx;
  401. border-bottom: 2rpx solid #e7e8ea;
  402. width: 100%;
  403. position: relative;
  404. .tip {
  405. background-color: #ff4f4f;
  406. border-radius: 100rpx;
  407. width: 10rpx;
  408. height: 35rpx;
  409. position: absolute;
  410. top: 0;
  411. }
  412. .portrait {
  413. margin-left: 20rpx;
  414. width: 117rpx;
  415. height: 117rpx;
  416. image {
  417. width: 100%;
  418. height: 100%;
  419. border-radius: 15rpx;
  420. }
  421. }
  422. .sos-type {
  423. color: #FF4F4F;
  424. font-weight: bold;
  425. font-size: 28rpx;
  426. }
  427. .info {
  428. margin-left: 20rpx;
  429. width: 60%;
  430. .name {
  431. color: #333333;
  432. font-weight: bold;
  433. font-size: 32rpx;
  434. .info-name {
  435. margin-right: 35rpx;
  436. width: 90%;
  437. }
  438. }
  439. .address {
  440. margin-top: 15rpx;
  441. .juli {
  442. font-weight: normal;
  443. font-size: 28rpx;
  444. }
  445. image {
  446. margin-left: 15rpx;
  447. width: 25rpx;
  448. height: 30rpx;
  449. }
  450. }
  451. .adr {
  452. color: #333333;
  453. margin-top: 15rpx;
  454. }
  455. }
  456. .btn {
  457. width: 130rpx;
  458. height: 130rpx;
  459. image {
  460. width: 127rpx;
  461. height: 135rpx;
  462. }
  463. }
  464. }
  465. }
  466. </style>