index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="main-content">
  3. <view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
  4. <view class="home-banner-left" @click="cityClick">
  5. <up-icon name="map" color="#fff" size="25"></up-icon>
  6. <text>{{ data.address }}</text>
  7. </view>
  8. <view class="home-banner-cente">金邻助家</view>
  9. <view class="home-banner-rigth">
  10. <!-- <up-icon name="bell" :size="25" color="rgba(46, 46, 46, 1)"></up-icon> -->
  11. </view>
  12. </view>
  13. <view class="home-box" :style="`margin-top: ${globalData.navBarHeight}px `">
  14. <view class="home-main">
  15. <view class="custom-swiper">
  16. <up-swiper :list="list3" indicator indicatorMode="line" circular></up-swiper>
  17. </view>
  18. </view>
  19. <view class="home-grid">
  20. <Client />
  21. </view>
  22. <view class="home-grid hot-box" v-if="userType === 1">
  23. <view v-for="(item, index) in hotList" :key="index + 'hot'" class="hot-item">
  24. <img :src="item" alt="" style="width: 100%;height: 160rpx;">
  25. </view>
  26. </view>
  27. <view class="home-g-bgc">
  28. <view class="home-grid2">
  29. <view class="serve-title hot-box-title" v-if="userType === 1">超值专区</view>
  30. <view class="hot-swiper">
  31. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular></up-swiper>
  32. </view>
  33. </view>
  34. <view class="home-ranking home-grid2">
  35. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  36. <RankingList v-if="userType === 2" />
  37. </view>
  38. </view>
  39. <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status"
  40. :loadmoreText="loadmoreInfo.loadingText" :loadingText="loadmoreInfo.loadmoreText"
  41. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" v-if="userType == 1" />
  42. </view>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. ref,
  48. reactive,
  49. onMounted
  50. } from 'vue';
  51. import {
  52. onLoad,
  53. onShow,
  54. onReachBottom,
  55. onUnload
  56. } from "@dcloudio/uni-app";
  57. import RankingList from '@/pages/common/rankingList/index.vue';
  58. import ServIces from "@/components/Services/services.vue"
  59. import {
  60. Client
  61. } from "@/components/Client/new_file.vue"
  62. import {
  63. volunteerinfolist,
  64. } from "@/api/volunteerDetailsApi/details.js"
  65. import {
  66. slideshow
  67. } from '@/api/home.js'
  68. import { citySelectorNavigateTo } from '@/utils/adress'
  69. const citySelector = requirePlugin('citySelector');
  70. const total = ref(0)
  71. const listData = ref([])
  72. const rightList = ref([])
  73. const leftList = ref([])
  74. const userType = uni.getStorageSync('userType') //读取本地存储
  75. const globalData = ref({
  76. statusBarHeight: 47,
  77. navBarHeight: 91
  78. });
  79. const data = reactive({
  80. address: '重庆市',
  81. queryValue: ''
  82. })
  83. const list3 = ref([]);
  84. const ValueZone = ref([]);
  85. const hotList = ref([])
  86. // 分页
  87. const pages = ref({
  88. current: 1,
  89. pageSize: 10,
  90. total: 0
  91. })
  92. const cityClick = () => {
  93. console.log('cityClick', data.address);
  94. citySelectorNavigateTo(data.address)
  95. }
  96. const loadmoreInfo = ref({
  97. status: 'loadmore',
  98. loadingText: '努力加载中...',
  99. loadmoreText: '点击加载更多~',
  100. nomoreText: '已经到底啦~'
  101. })
  102. // 加载更多
  103. async function handleLoadmore(e) {
  104. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  105. pages.value.current += 1;
  106. loadmoreInfo.value.status = 'loading';
  107. await getList();
  108. } else {
  109. loadmoreInfo.value.status = 'nomore';
  110. }
  111. }
  112. const getList = async () => {
  113. try {
  114. loadmoreInfo.value.status = 'loading';
  115. // 请求时传递分页参数
  116. const res = await volunteerinfolist({
  117. pageNum: pages.value.current, // 当前页码
  118. pageSize: pages.value.pageSize // 每页大小
  119. });
  120. console.log(res, '>>>>>>>res');
  121. if (!res || !res.rows) {
  122. return;
  123. }
  124. // 判断是否已经到了最后一页
  125. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  126. loadmoreInfo.value.status = 'nomore';
  127. } else {
  128. loadmoreInfo.value.status = 'loadmore';
  129. }
  130. // 将数据分成左右两列
  131. res.rows.forEach((item, index) => {
  132. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  133. });
  134. pages.value.total = res.total;
  135. } catch (error) {
  136. leftList.value = [];
  137. rightList.value = [];
  138. loadmoreInfo.value.status = 'loadmore';
  139. pages.value.total = 0;
  140. console.error('Error fetching data:', error);
  141. }
  142. };
  143. onReachBottom(() => {
  144. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  145. pages.value.current = pages.value.current + 1
  146. loadmoreInfo.value.status = 'nomore'
  147. getList()
  148. }
  149. })
  150. const getBanners = async () => {
  151. try {
  152. const res = await slideshow(7);
  153. if (res.code === 200 && res.data.picture) {
  154. list3.value = res.data.picture.split(',');
  155. }
  156. const value_res = await slideshow(8);
  157. if (value_res.code === 200 && value_res.data.picture) {
  158. ValueZone.value = value_res.data.picture.split(',');
  159. }
  160. const hot_res = await slideshow(11);
  161. if (hot_res.code === 200 && hot_res.data.picture) {
  162. hotList.value = hot_res.data.picture.split(',');
  163. }
  164. } catch (error) {
  165. console.log('error', error);
  166. }
  167. }
  168. onShow(() => {
  169. getList()
  170. getBanners();
  171. // 在 App.vue 中初始化
  172. uni.getSystemInfo({
  173. success: (res) => {
  174. const statusBarHeight = res.statusBarHeight;
  175. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  176. globalData.value = { statusBarHeight, navBarHeight };
  177. console.log('statusBarHeight', statusBarHeight, navBarHeight);
  178. }
  179. });
  180. if (citySelector) {
  181. const selectedCity = citySelector.getCity(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  182. console.log('citySelector', selectedCity,selectedCity.name)
  183. data.address = selectedCity.name;
  184. }
  185. })
  186. onUnload(() => {
  187. if (citySelector) {
  188. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  189. citySelector.setLocation(null);
  190. }
  191. })
  192. </script>
  193. <style scoped lang="scss">
  194. .main-content {
  195. background: rgba(255, 255, 255, 1);
  196. .home-banner {
  197. display: flex;
  198. align-items: flex-end;
  199. justify-content: space-between;
  200. // background: rgba(255, 255, 255, 1);
  201. // background-color: #ED806A;
  202. background-color: rgba(221, 60, 62, 1);
  203. 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);
  204. padding: 20rpx 16rpx;
  205. color: #fff;
  206. position: fixed;
  207. top: 0px;
  208. left: 0px;
  209. right: 0;
  210. z-index: 99;
  211. }
  212. .home-banner-left {
  213. display: flex;
  214. align-items: center;
  215. width: 30%;
  216. }
  217. .home-banner-center {
  218. flex: 1;
  219. font-size: 38rpx;
  220. }
  221. .home-banner-rigth {
  222. width: 30%;
  223. }
  224. .home-main {
  225. padding: 12px 16px 0;
  226. }
  227. .home-ranking {
  228. padding: 24rpx 16px;
  229. }
  230. }
  231. .hot-box-title {
  232. padding: 0 32rpx;
  233. }
  234. .hot-swiper {
  235. padding: 24rpx 32rpx 0;
  236. }
  237. .hot-box {
  238. padding: 24rpx 32rpx;
  239. display: grid;
  240. grid-template-columns: repeat(2, 1fr);
  241. gap: 8rpx;
  242. .hot-item {
  243. // padding: 32rpx 16rpx;
  244. // border-radius: 10rpx;
  245. }
  246. }
  247. .home-grid2 {
  248. margin-bottom: 32rpx;
  249. background: #fff;
  250. padding: 12px 0;
  251. border-radius: 8px;
  252. }
  253. .home-g-bgc {
  254. background: #f7f7f7;
  255. padding: 24rpx;
  256. }
  257. </style>