index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="main-content">
  3. <view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
  4. <view class="home-banner-left">
  5. <!-- <img src="/static/serverImg/home/address.png" alt=""
  6. style="width: 41.67rpx;height: 41.67rpx;margin-right: 8rpx;"> -->
  7. <up-icon name="map" color="#fff" size="25" ></up-icon>
  8. <text>{{ data.address }}</text>
  9. </view>
  10. <view class="home-banner-cente">金邻助家</view>
  11. <view class="home-banner-rigth">
  12. <!-- <up-icon name="bell" :size="25" color="rgba(46, 46, 46, 1)"></up-icon> -->
  13. </view>
  14. </view>
  15. <view class="home-box" :style="`margin-top: ${globalData.navBarHeight}px `">
  16. <view class="home-main">
  17. <view class="custom-swiper">
  18. <up-swiper :list="list3" indicator indicatorMode="line" circular></up-swiper>
  19. </view>
  20. </view>
  21. <view class="home-grid">
  22. <Client />
  23. </view>
  24. <view class="home-grid hot-box" v-if="userType === 1">
  25. <view v-for="(item, index) in hotList" :key="index + 'hot'" class="hot-item">
  26. <img :src="item" alt="" style="width: 100%;height: 160rpx;">
  27. </view>
  28. </view>
  29. <view class="home-g-bgc">
  30. <view class="home-grid2">
  31. <view class="serve-title hot-box-title" v-if="userType === 1">超值专区</view>
  32. <view class="hot-swiper">
  33. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular ></up-swiper>
  34. </view>
  35. </view>
  36. <view class="home-ranking home-grid2">
  37. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  38. <RankingList v-if="userType === 2" />
  39. </view>
  40. </view>
  41. <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status" :loadmoreText="loadmoreInfo.loadingText"
  42. :loadingText="loadmoreInfo.loadmoreText" :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" v-if="userType == 1"/>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup>
  47. import {
  48. ref,
  49. reactive,
  50. onMounted
  51. } from 'vue';
  52. import {
  53. onLoad,
  54. onShow
  55. } from "@dcloudio/uni-app";
  56. import RankingList from '@/pages/common/rankingList/index.vue';
  57. import ServIces from "@/components/Services/services.vue"
  58. import {
  59. Client
  60. } from "@/components/Client/new_file.vue"
  61. import {
  62. volunteerinfolist,
  63. } from "@/api/volunteerDetailsApi/details.js"
  64. import { slideshow } from '@/api/home.js'
  65. const total = ref(0)
  66. const listData = ref([])
  67. const rightList = ref([])
  68. const leftList = ref([])
  69. const userType = uni.getStorageSync('userType') //读取本地存储
  70. const globalData = ref({
  71. statusBarHeight: 47,
  72. navBarHeight: 91
  73. });
  74. const data = reactive({
  75. address: '重庆市',
  76. queryValue: ''
  77. })
  78. const list3 = ref([]);
  79. const ValueZone = ref([]);
  80. const hotList = ref([])
  81. // 分页
  82. const pages = ref({
  83. current: 1,
  84. pageSize: 10,
  85. total: 0
  86. })
  87. const loadmoreInfo = ref({
  88. status: 'loadmore',
  89. loadingText: '努力加载中...',
  90. loadmoreText: '点击加载更多~',
  91. nomoreText: '已经到底啦~'
  92. })
  93. const getList = async () => {
  94. try {
  95. loadmoreInfo.value.status = 'loading'
  96. const res = await volunteerinfolist();
  97. if (!res || !res.rows) {
  98. return;
  99. }
  100. // 判断是否已经到了最后一页
  101. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  102. loadmoreInfo.value.status = 'nomore'
  103. } else {
  104. loadmoreInfo.value.status = 'loadmore'
  105. }
  106. listData.value.push(...res.rows)
  107. let leftArr = [];
  108. let rightArr = [];
  109. listData.value.forEach((item, index) => {
  110. index % 2 !== 0 ? leftArr.push(item) : rightArr.push(item);
  111. });
  112. leftList.value = leftArr;
  113. rightList.value = rightArr;
  114. pages.value.total = res.total;
  115. } catch (error) {
  116. listData.value = []
  117. pages.value.total = 0
  118. console.error('Error fetching data:', error);
  119. } finally {
  120. loadmoreInfo.value.status = 'loadmore'
  121. }
  122. }
  123. const getBanners = async () => {
  124. try {
  125. const res = await slideshow(7);
  126. if (res.code === 200 && res.data.picture) {
  127. list3.value = res.data.picture.split(',');
  128. }
  129. const value_res = await slideshow(8);
  130. if (value_res.code === 200 && value_res.data.picture) {
  131. ValueZone.value = value_res.data.picture.split(',');
  132. }
  133. const hot_res = await slideshow(11);
  134. if (hot_res.code === 200 && hot_res.data.picture) {
  135. hotList.value = hot_res.data.picture.split(',');
  136. }
  137. } catch (error) {
  138. console.log('error', error);
  139. }
  140. }
  141. onShow(() => {
  142. getList()
  143. getBanners();
  144. // 在 App.vue 中初始化
  145. uni.getSystemInfo({
  146. success: (res) => {
  147. const statusBarHeight = res.statusBarHeight;
  148. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  149. globalData.value = { statusBarHeight, navBarHeight };
  150. console.log('statusBarHeight', statusBarHeight, navBarHeight);
  151. }
  152. });
  153. })
  154. </script>
  155. <style scoped lang="scss">
  156. .main-content {
  157. background: rgba(255, 255, 255, 1);
  158. .home-banner {
  159. display: flex;
  160. align-items: flex-end;
  161. justify-content: space-between;
  162. // background: rgba(255, 255, 255, 1);
  163. // background-color: #ED806A;
  164. background-color: rgba(221, 60, 62, 1);
  165. box-shadow: 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 2.08rpx 4.17rpx rgba(0, 0, 0, 0.05);
  166. padding: 20rpx 16rpx;
  167. color: #fff;
  168. position: fixed;
  169. top: 0px;
  170. left: 0px;
  171. right: 0;
  172. z-index: 99;
  173. }
  174. .home-banner-left {
  175. display: flex;
  176. align-items: center;
  177. width: 30%;
  178. }
  179. .home-banner-center {
  180. flex: 1;
  181. font-size: 38rpx;
  182. }
  183. .home-banner-rigth {
  184. width: 30%;
  185. }
  186. .home-main {
  187. padding: 12px 16px 0;
  188. }
  189. .home-ranking {
  190. padding: 24rpx 16px;
  191. }
  192. }
  193. .hot-box-title {
  194. padding: 0 32rpx;
  195. }
  196. .hot-swiper {
  197. padding: 24rpx 32rpx 0;
  198. }
  199. .hot-box {
  200. padding: 24rpx 32rpx;
  201. display: grid;
  202. grid-template-columns: repeat(2, 1fr);
  203. gap: 8rpx;
  204. .hot-item {
  205. // padding: 32rpx 16rpx;
  206. // border-radius: 10rpx;
  207. }
  208. }
  209. .home-grid2 {
  210. margin-bottom: 32rpx;
  211. background: #fff;
  212. padding: 12px 0;
  213. border-radius: 8px;
  214. }
  215. .home-g-bgc {
  216. background: #f7f7f7;
  217. padding: 24rpx;
  218. }
  219. </style>