index.vue 11 KB

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