index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. provide
  53. } from 'vue';
  54. import {
  55. onLoad,
  56. onShow,
  57. onReachBottom,
  58. onUnload
  59. } from "@dcloudio/uni-app";
  60. import RankingList from '@/pages/common/rankingList/index.vue';
  61. import ServIces from "@/components/Services/services.vue"
  62. import {
  63. Client
  64. } from "@/components/Client/new_file.vue"
  65. import {
  66. volunteerinfolist,
  67. } from "@/api/volunteerDetailsApi/details.js"
  68. import {
  69. slideshow
  70. } from '@/api/home.js'
  71. import {
  72. useDict
  73. } from '@/utils/dict.js';
  74. import { citySelectorNavigateTo } from '@/utils/adress'
  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 cityClick = () => {
  103. console.log('cityClick', data.address);
  104. citySelectorNavigateTo(data.address)
  105. }
  106. const loadmoreInfo = ref({
  107. status: 'loadmore',
  108. loadingText: '努力加载中...',
  109. loadmoreText: '点击加载更多~',
  110. nomoreText: '已经到底啦~'
  111. })
  112. // 加载更多
  113. async function handleLoadmore(e) {
  114. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  115. pages.value.current += 1;
  116. loadmoreInfo.value.status = 'loading';
  117. await getList();
  118. } else {
  119. loadmoreInfo.value.status = 'nomore';
  120. }
  121. }
  122. const getList = async () => {
  123. try {
  124. loadmoreInfo.value.status = 'loading';
  125. const params = {
  126. pageNum: pages.value.current,
  127. pageSize: pages.value.pageSize,
  128. serviceCategory: pages.value.serviceCategory || '',
  129. // appStatus:pages.value.appStatus,
  130. };
  131. console.log('请求参数:', params); // 调试输出
  132. const res = await volunteerinfolist(params);
  133. if (!res || !res.rows) {
  134. return;
  135. }
  136. // 判断是否已经到了最后一页
  137. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  138. loadmoreInfo.value.status = 'nomore';
  139. } else {
  140. loadmoreInfo.value.status = 'loadmore';
  141. }
  142. // 将数据分成左右两列
  143. res.rows.forEach((item, index) => {
  144. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  145. });
  146. pages.value.total = res.total;
  147. } catch (error) {
  148. leftList.value = [];
  149. rightList.value = [];
  150. loadmoreInfo.value.status = 'loadmore';
  151. pages.value.total = 0;
  152. console.error('Error fetching data:', error);
  153. }
  154. };
  155. onReachBottom(() => {
  156. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  157. pages.value.current = pages.value.current + 1
  158. loadmoreInfo.value.status = 'nomore'
  159. getList()
  160. }
  161. })
  162. const getBanners = async () => {
  163. try {
  164. const res = await slideshow(7);
  165. if (res.code === 200 && res.data.picture) {
  166. list3.value = res.data.picture.split(',');
  167. }
  168. const value_res = await slideshow(8);
  169. if (value_res.code === 200 && value_res.data.picture) {
  170. ValueZone.value = value_res.data.picture.split(',');
  171. }
  172. const hot_res = await slideshow(11);
  173. if (hot_res.code === 200 && hot_res.data.picture) {
  174. hotList.value = hot_res.data.picture.split(',');
  175. }
  176. } catch (error) {
  177. console.log('error', error);
  178. }
  179. }
  180. onShow(() => {
  181. getList()
  182. getBanners();
  183. // 在 App.vue 中初始化
  184. uni.getSystemInfo({
  185. success: (res) => {
  186. const statusBarHeight = res.statusBarHeight;
  187. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  188. globalData.value = { statusBarHeight, navBarHeight };
  189. console.log('statusBarHeight', statusBarHeight, navBarHeight);
  190. }
  191. });
  192. if (citySelector) {
  193. const selectedCity = citySelector.getCity(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  194. console.log('citySelector', selectedCity,selectedCity.name)
  195. data.address = selectedCity.name;
  196. }
  197. })
  198. onUnload(() => {
  199. if (citySelector) {
  200. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  201. citySelector.setLocation(null);
  202. }
  203. })
  204. </script>
  205. <style scoped lang="scss">
  206. .main-content {
  207. background: rgba(255, 255, 255, 1);
  208. .home-banner {
  209. display: flex;
  210. align-items: flex-end;
  211. justify-content: space-between;
  212. // background: rgba(255, 255, 255, 1);
  213. // background-color: #ED806A;
  214. background-color: rgba(221, 60, 62, 1);
  215. 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);
  216. padding: 20rpx 16rpx;
  217. color: #fff;
  218. position: fixed;
  219. top: 0px;
  220. left: 0px;
  221. right: 0;
  222. z-index: 99;
  223. }
  224. .home-banner-left {
  225. display: flex;
  226. align-items: center;
  227. width: 30%;
  228. }
  229. .home-banner-center {
  230. flex: 1;
  231. font-size: 38rpx;
  232. }
  233. .home-banner-rigth {
  234. width: 30%;
  235. }
  236. .home-main {
  237. padding: 12px 16px 0;
  238. }
  239. .home-ranking {
  240. padding: 24rpx 16px;
  241. }
  242. }
  243. .hot-box-title {
  244. padding: 0 32rpx;
  245. }
  246. .hot-swiper {
  247. padding: 24rpx 32rpx 0;
  248. }
  249. .hot-box {
  250. padding: 24rpx 32rpx;
  251. display: grid;
  252. grid-template-columns: repeat(2, 1fr);
  253. gap: 8rpx;
  254. .hot-item {
  255. // padding: 32rpx 16rpx;
  256. // border-radius: 10rpx;
  257. }
  258. }
  259. .home-grid2 {
  260. margin-bottom: 32rpx;
  261. background: #fff;
  262. padding: 12px 0;
  263. border-radius: 8px;
  264. }
  265. .home-g-bgc {
  266. background: #f7f7f7;
  267. padding: 24rpx;
  268. }
  269. </style>