index.vue 7.1 KB

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