index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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"
  42. :loadmoreText="loadmoreInfo.loadingText" :loadingText="loadmoreInfo.loadmoreText"
  43. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" v-if="userType == 1" />
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. ref,
  50. reactive,
  51. onMounted
  52. } from 'vue';
  53. import {
  54. provide
  55. } from 'vue';
  56. import {
  57. onLoad,
  58. onShow,
  59. onReachBottom
  60. } from "@dcloudio/uni-app";
  61. import RankingList from '@/pages/common/rankingList/index.vue';
  62. import ServIces from "@/components/Services/services.vue"
  63. import {
  64. Client
  65. } from "@/components/Client/new_file.vue"
  66. import {
  67. volunteerinfolist,
  68. } from "@/api/volunteerDetailsApi/details.js"
  69. import {
  70. slideshow
  71. } from '@/api/home.js'
  72. import {
  73. useDict
  74. } from '@/utils/dict.js';
  75. const total = ref(0)
  76. const listData = ref([])
  77. const rightList = ref([])
  78. const leftList = ref([])
  79. const list3 = ref([]);
  80. const ValueZone = ref([]);
  81. const hotList = ref([])
  82. const userType = uni.getStorageSync('userType') //读取本地存储
  83. const {
  84. lrr_service_category
  85. } = useDict('lrr_service_category');
  86. const globalData = ref({
  87. statusBarHeight: 47,
  88. navBarHeight: 91
  89. });
  90. const data = reactive({
  91. address: '重庆市',
  92. queryValue: ''
  93. })
  94. // 分页
  95. const pages = ref({
  96. current: 1,
  97. pageSize: 10,
  98. total: 0,
  99. serviceCategory: '',
  100. // appStatus:"2",
  101. })
  102. const loadmoreInfo = ref({
  103. status: 'loadmore',
  104. loadingText: '努力加载中...',
  105. loadmoreText: '点击加载更多~',
  106. nomoreText: '已经到底啦~'
  107. })
  108. // 加载更多
  109. async function handleLoadmore(e) {
  110. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  111. pages.value.current += 1;
  112. loadmoreInfo.value.status = 'loading';
  113. await getList();
  114. } else {
  115. loadmoreInfo.value.status = 'nomore';
  116. }
  117. }
  118. const getList = async () => {
  119. try {
  120. loadmoreInfo.value.status = 'loading';
  121. const params = {
  122. pageNum: pages.value.current,
  123. pageSize: pages.value.pageSize,
  124. serviceCategory: pages.value.serviceCategory || '',
  125. // appStatus:pages.value.appStatus,
  126. };
  127. console.log('请求参数:', params); // 调试输出
  128. const res = await volunteerinfolist(params);
  129. if (!res || !res.rows) {
  130. return;
  131. }
  132. // 判断是否已经到了最后一页
  133. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  134. loadmoreInfo.value.status = 'nomore';
  135. } else {
  136. loadmoreInfo.value.status = 'loadmore';
  137. }
  138. // 将数据分成左右两列
  139. res.rows.forEach((item, index) => {
  140. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  141. });
  142. pages.value.total = res.total;
  143. } catch (error) {
  144. leftList.value = [];
  145. rightList.value = [];
  146. loadmoreInfo.value.status = 'loadmore';
  147. pages.value.total = 0;
  148. console.error('Error fetching data:', error);
  149. }
  150. };
  151. onReachBottom(() => {
  152. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  153. pages.value.current = pages.value.current + 1
  154. loadmoreInfo.value.status = 'nomore'
  155. getList()
  156. }
  157. })
  158. const getBanners = async () => {
  159. try {
  160. const res = await slideshow(7);
  161. if (res.code === 200 && res.data.picture) {
  162. list3.value = res.data.picture.split(',');
  163. }
  164. const value_res = await slideshow(8);
  165. if (value_res.code === 200 && value_res.data.picture) {
  166. ValueZone.value = value_res.data.picture.split(',');
  167. }
  168. const hot_res = await slideshow(11);
  169. if (hot_res.code === 200 && hot_res.data.picture) {
  170. hotList.value = hot_res.data.picture.split(',');
  171. }
  172. } catch (error) {
  173. console.log('error', error);
  174. }
  175. }
  176. onShow(() => {
  177. getList()
  178. getBanners();
  179. // getListData()
  180. // 在 App.vue 中初始化
  181. uni.getSystemInfo({
  182. success: (res) => {
  183. const statusBarHeight = res.statusBarHeight;
  184. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  185. globalData.value = {
  186. statusBarHeight,
  187. navBarHeight
  188. };
  189. console.log('statusBarHeight', statusBarHeight, navBarHeight);
  190. }
  191. });
  192. })
  193. </script>
  194. <style scoped lang="scss">
  195. .main-content {
  196. background: rgba(255, 255, 255, 1);
  197. .home-banner {
  198. display: flex;
  199. align-items: flex-end;
  200. justify-content: space-between;
  201. // background: rgba(255, 255, 255, 1);
  202. // background-color: #ED806A;
  203. background-color: rgba(221, 60, 62, 1);
  204. 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);
  205. padding: 20rpx 16rpx;
  206. color: #fff;
  207. position: fixed;
  208. top: 0px;
  209. left: 0px;
  210. right: 0;
  211. z-index: 99;
  212. }
  213. .home-banner-left {
  214. display: flex;
  215. align-items: center;
  216. width: 30%;
  217. }
  218. .home-banner-center {
  219. flex: 1;
  220. font-size: 38rpx;
  221. }
  222. .home-banner-rigth {
  223. width: 30%;
  224. }
  225. .home-main {
  226. padding: 12px 16px 0;
  227. }
  228. .home-ranking {
  229. padding: 24rpx 16px;
  230. }
  231. }
  232. .hot-box-title {
  233. padding: 0 32rpx;
  234. }
  235. .hot-swiper {
  236. padding: 24rpx 32rpx 0;
  237. }
  238. .hot-box {
  239. padding: 24rpx 32rpx;
  240. display: grid;
  241. grid-template-columns: repeat(2, 1fr);
  242. gap: 8rpx;
  243. .hot-item {
  244. // padding: 32rpx 16rpx;
  245. // border-radius: 10rpx;
  246. }
  247. }
  248. .home-grid2 {
  249. margin-bottom: 32rpx;
  250. background: #fff;
  251. padding: 12px 0;
  252. border-radius: 8px;
  253. }
  254. .home-g-bgc {
  255. background: #f7f7f7;
  256. padding: 24rpx;
  257. }
  258. </style>