index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="container">
  3. <template v-if="swiperList.length == 0">
  4. <u-skeleton rows="1" class="skeleton-full" loading :rowsHeight="170" :title="false"></u-skeleton>
  5. <view style="margin: 30rpx 0">
  6. <u-skeleton rows="2" title loading avatar avatarSize="120" avatarShape="square" :rowsHeight="28"
  7. :titleHeight="32"></u-skeleton>
  8. </view>
  9. </template>
  10. <template v-else>
  11. <view class="banner-box">
  12. <u--image v-if="swiperList.length == 1" :src="swiperList[0]" mode="aspectFill" :fade="true"
  13. duration="450" :lazy-load="true" width="100%" height="340rpx"></u--image>
  14. <u-swiper v-else :list="swiperList" @change="change" @click="toLinkPage" :autoplay="false" radius="0"
  15. height="340rpx"></u-swiper>
  16. </view>
  17. <view class="hospital-box">
  18. <view class="hospital-list">
  19. <view class="hospital-item" v-for="item,index in hospitalList" :key="index">
  20. <u--image :src="item.logoUrl" mode="aspectFill" :fade="true" duration="450" :lazy-load="true"
  21. width="262rpx" height="200rpx"></u--image>
  22. <view class="hospital-info">
  23. <view class="info-top">
  24. <view class="hospital-name">{{item.name || '-'}}</view>
  25. <view class="hospital-distance">{{item.relativeDistance || 0}}{{item.distanceUnit}}
  26. </view>
  27. </view>
  28. <view class="info-bottom">
  29. <view class="info-bottom-l">
  30. <span class="hospital-address">
  31. <u-icon name="map-fill" color="#999999" size="14"></u-icon>
  32. <span class="address">{{item.address || '-'}}</span>
  33. </span>
  34. <!-- <view class="hospital-area">所在区:{{item.areaName || '-'}}</view> -->
  35. </view>
  36. </view>
  37. <view class="btn-box">
  38. <view class="hospital-btn" @click="toPlaceOrder(item)">去下单</view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="footer-box">
  44. <image src="/static/icon-home.png" mode="aspectFill"></image>
  45. <span class="tip">润康优护为你提供服务</span>
  46. </view>
  47. </view>
  48. </template>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. linkList,
  54. getHospitalList
  55. } from "@/api/home.js"
  56. export default {
  57. data() {
  58. return {
  59. swiperList: [],
  60. userInfo: {},
  61. currents: 0,
  62. hospitalList: [],
  63. coordinates: '',
  64. pageSize: 10,
  65. pageNo: 1,
  66. botLoadingShow: 0, //0不显示 1显示 3.显示没有更多了
  67. loadingShow: false,
  68. status: 'loadmore',
  69. loadingText: '努力加载中',
  70. loadmoreText: '上拉或点击加载更多',
  71. nomoreText: '实在没有了',
  72. total: 0,
  73. };
  74. },
  75. async onLoad() {
  76. //获取当前定位信息
  77. // uni.getLocation({
  78. // type: 'gcj02',
  79. // success: (res) => {
  80. // console.log('当前位置的经度:' + res.longitude);
  81. // console.log('当前位置的纬度:' + res.latitude);
  82. // this.coordinates = res.longitude + ',' + res.latitude;
  83. // this.getList();
  84. // }
  85. // });
  86. this.realoadData();
  87. },
  88. onShow() {
  89. wx.showShareMenu({
  90. withShareTicket: true,
  91. menus: ['shareAppMessage', 'shareTimeline']
  92. });
  93. },
  94. methods: {
  95. async realoadData() {
  96. this.getBannerList();
  97. //定位缓存
  98. let locationInfo = uni.getStorageSync('locationInfo');
  99. if (locationInfo) {
  100. this.coordinates = locationInfo.longitude + ',' + locationInfo.latitude;
  101. this.getList();
  102. //再去判断是否有最新的定位信息
  103. let data = await this.$utils.getLocation();
  104. if (data.long != locationInfo.longitude || data.lat != locationInfo.latitude) {
  105. // 如果有新的定位,刷新列表
  106. uni.setStorageSync('locationInfo', {
  107. longitude: data.long,
  108. latitude: data.lat
  109. })
  110. this.getList();
  111. }
  112. } else {
  113. // 无缓存信息
  114. let data = await this.$utils.getLocation();
  115. if (data) {
  116. //有授权定位
  117. console.log('当前位置的经度:' + data.long);
  118. console.log('当前位置的纬度:' + data.lat);
  119. this.coordinates = data.long + ',' + data.lat;
  120. uni.setStorageSync('locationInfo', {
  121. longitude: data.long,
  122. latitude: data.lat
  123. })
  124. this.getList();
  125. } else {
  126. // 无授权定位
  127. this.coordinates = undefined;
  128. this.getList();
  129. }
  130. }
  131. },
  132. getList() {
  133. let that = this;
  134. uni.showLoading({
  135. title: '加载中',
  136. mask: true,
  137. });
  138. let param = {
  139. coordinates: that.coordinates
  140. };
  141. getHospitalList(param).then(res => {
  142. let data = res.data;
  143. if (data) {
  144. this.hospitalList = data; //在列表后面新增新获取的数据
  145. // if (this.hospitalList.length >= this.total) {
  146. // this.status = 'nomore';
  147. // return;
  148. // }
  149. } else {
  150. that.status = 'nomore';
  151. }
  152. }).finally(() => {
  153. uni.hideLoading();
  154. })
  155. },
  156. toPlaceOrder(obj) {
  157. // let item = {
  158. // id: obj.id,
  159. // name: obj.name,
  160. // address: obj.address,
  161. // logoUrl: obj.logoUrl,
  162. // areaName: obj.areaName,
  163. // }
  164. uni.navigateTo({
  165. url: '/pages/order/placeAnOrder?id=' + obj.id
  166. })
  167. },
  168. getBannerList() {
  169. let that = this;
  170. linkList('home_top_banner').then(res => {
  171. res.data.forEach(item => {
  172. that.swiperList.push(item.image)
  173. })
  174. }).finally(() => {})
  175. },
  176. toLinkPage() {
  177. },
  178. //下拉刷新
  179. onPullDownRefresh() {
  180. this.pageNo = 1;
  181. this.swiperList = [];
  182. this.hospitalList = [];
  183. this.realoadData();
  184. uni.stopPullDownRefresh();
  185. },
  186. //上拉加载
  187. // onReachBottom() {
  188. // this.pageNo++;
  189. // this.getList();
  190. // },
  191. change(index) {
  192. this.currents = index;
  193. },
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage: function() {
  198. const nickName = '您的好友'
  199. const title = '润护通为您提供服务',
  200. path = `/pages/tabBar/index`
  201. // imageUrl = 'https://www.baidu.com.cn/img/20211108/activity.png'
  202. return {
  203. title,
  204. path
  205. // imageUrl
  206. };
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .container {
  213. background-color: #fff;
  214. min-height: 100vh;
  215. .banner-box {
  216. width: 100%;
  217. height: 340rpx;
  218. image {
  219. width: 100%;
  220. height: 340rpx !important;
  221. }
  222. .u--image {
  223. width: 100%;
  224. height: 340rpx !important;
  225. }
  226. }
  227. .hospital-box {
  228. display: flex;
  229. flex-direction: column;
  230. min-height: calc(100vh - 340rpx);
  231. background-color: #fff;
  232. .hospital-list {
  233. padding: 0 30rpx 40rpx;
  234. flex: 1;
  235. .hospital-item {
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. padding: 30rpx 0;
  240. border-bottom: 1rpx solid #f0f0f0;
  241. // &:last-child {
  242. // border-bottom: none;
  243. // }
  244. // image {
  245. // width: 262rpx;
  246. // height: 200rpx;
  247. // border-radius: 20rpx;
  248. // margin-right: 17rpx;
  249. // }
  250. .hospital-info {
  251. flex: 1;
  252. margin-left: 17rpx;
  253. .info-top {
  254. display: flex;
  255. justify-content: space-between;
  256. align-items: center;
  257. .hospital-name {
  258. width: 300rpx;
  259. font-size: 30rpx;
  260. font-weight: bold;
  261. // word-break: break-all;
  262. display: -webkit-box;
  263. -webkit-line-clamp: 1;
  264. /* 设置显示的行数 */
  265. -webkit-box-orient: vertical;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. max-width: 300px;
  269. /* 设置最大宽度,根据需要调整 */
  270. //超过一行使用省略号
  271. }
  272. .hospital-distance {
  273. text-align: right;
  274. margin: 15rpx 0;
  275. font-size: 28rpx;
  276. color: #999;
  277. }
  278. }
  279. .info-bottom {
  280. display: flex;
  281. flex-direction: column;
  282. // justify-content: space-between;
  283. // align-items: center;
  284. .info-bottom-l {
  285. flex: 1;
  286. .hospital-address {
  287. display: flex;
  288. justify-content: flex-start;
  289. align-items: flex-start;
  290. width: 100%;
  291. margin-top: 10rpx;
  292. font-weight: 500;
  293. line-height: 40rpx;
  294. overflow: hidden; //超出的文本隐藏
  295. text-overflow: ellipsis; //溢出用省略号显示
  296. white-space: normal; //处理元素中的 空白
  297. display: -webkit-box;
  298. -webkit-line-clamp: 2;
  299. -webkit-box-orient: vertical;
  300. display: -moz-box;
  301. -moz-line-clamp: 2;
  302. -moz-box-orient: vertical;
  303. overflow-wrap: break-word;
  304. word-break: break-all;
  305. ::v-deep .u-icon {
  306. display: inline-block;
  307. }
  308. // u-icon和span在同一行,换行时文字在icon下面
  309. .address {
  310. font-size: 28rpx;
  311. margin-left: 5rpx;
  312. color: #999999;
  313. }
  314. }
  315. .hospital-area {
  316. font-size: 28rpx;
  317. color: #999;
  318. }
  319. }
  320. }
  321. .btn-box {
  322. display: flex;
  323. justify-content: flex-end;
  324. align-items: center;
  325. margin-top: 20rpx;
  326. .hospital-btn {
  327. width: 165rpx;
  328. height: 60rpx;
  329. margin-left: 10rpx;
  330. line-height: 60rpx;
  331. text-align: center;
  332. background: #4B91D1;
  333. color: #fff;
  334. font-size: 24rpx;
  335. border-radius: 30rpx;
  336. justify-content: flex-end;
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }
  343. .footer-box {
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. // position: fixed;
  348. // bottom: 0;
  349. // left: 0;
  350. width: 100%;
  351. padding: 32rpx 0;
  352. background-color: #fff;
  353. image {
  354. width: 25rpx;
  355. height: 25rpx;
  356. }
  357. .tip {
  358. margin-left: 7rpx;
  359. color: #B3B3B3;
  360. font-size: 26rpx;
  361. line-height: 26rpx;
  362. }
  363. }
  364. }
  365. /* 骨架屏容器样式 */
  366. .skeleton-full {
  367. width: 100%;
  368. height: 100%;
  369. }
  370. /* 关键:使用深度选择器修改骨架屏内部样式 */
  371. ::v-deep .u-skeleton__wrapper__content__rows {
  372. width: 100% !important;
  373. }
  374. </style>