index.vue 7.2 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 citySelector = requirePlugin('citySelector');
  84. const {
  85. lrr_service_category
  86. } = useDict('lrr_service_category');
  87. const globalData = ref({
  88. statusBarHeight: 47,
  89. navBarHeight: 91
  90. });
  91. const data = reactive({
  92. address: '重庆市',
  93. queryValue: ''
  94. })
  95. // 分页
  96. const pages = ref({
  97. current: 1,
  98. pageSize: 10,
  99. total: 0,
  100. serviceCategory: '',
  101. // appStatus:"2",
  102. })
  103. const cityClick = () => {
  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. const res = await volunteerinfolist(params);
  132. if (!res || !res.rows) {
  133. return;
  134. }
  135. // 判断是否已经到了最后一页
  136. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  137. loadmoreInfo.value.status = 'nomore';
  138. } else {
  139. loadmoreInfo.value.status = 'loadmore';
  140. }
  141. // 将数据分成左右两列
  142. res.rows.forEach((item, index) => {
  143. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  144. });
  145. pages.value.total = res.total;
  146. } catch (error) {
  147. leftList.value = [];
  148. rightList.value = [];
  149. loadmoreInfo.value.status = 'loadmore';
  150. pages.value.total = 0;
  151. console.error('Error fetching data:', error);
  152. }
  153. };
  154. onReachBottom(() => {
  155. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  156. pages.value.current = pages.value.current + 1
  157. loadmoreInfo.value.status = 'nomore'
  158. getList()
  159. }
  160. })
  161. const getBanners = async () => {
  162. try {
  163. const res = await slideshow(7);
  164. if (res.code === 200 && res.data.picture) {
  165. list3.value = res.data.picture.split(',');
  166. }
  167. const value_res = await slideshow(8);
  168. if (value_res.code === 200 && value_res.data.picture) {
  169. ValueZone.value = value_res.data.picture.split(',');
  170. }
  171. const hot_res = await slideshow(11);
  172. if (hot_res.code === 200 && hot_res.data.picture) {
  173. hotList.value = hot_res.data.picture.split(',');
  174. }
  175. } catch (error) {
  176. console.log('error', error);
  177. }
  178. }
  179. onShow(() => {
  180. getBanners();
  181. // 在 App.vue 中初始化
  182. uni.getSystemInfo({
  183. success: (res) => {
  184. const statusBarHeight = res.statusBarHeight;
  185. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  186. globalData.value = { statusBarHeight, navBarHeight };
  187. }
  188. });
  189. if (citySelector) {
  190. const selectedCity = citySelector.getCity(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  191. data.address = selectedCity.name;
  192. }
  193. })
  194. onMounted(() => {
  195. getList()
  196. })
  197. onUnload(() => {
  198. if (citySelector) {
  199. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  200. citySelector.setLocation(null);
  201. }
  202. })
  203. </script>
  204. <style scoped lang="scss">
  205. .main-content {
  206. background: rgba(255, 255, 255, 1);
  207. .home-banner {
  208. display: flex;
  209. align-items: flex-end;
  210. justify-content: space-between;
  211. // background: rgba(255, 255, 255, 1);
  212. // background-color: #ED806A;
  213. background-color: rgba(221, 60, 62, 1);
  214. 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);
  215. padding: 20rpx 16rpx;
  216. color: #fff;
  217. position: fixed;
  218. top: 0px;
  219. left: 0px;
  220. right: 0;
  221. z-index: 99;
  222. }
  223. .home-banner-left {
  224. display: flex;
  225. align-items: center;
  226. width: 30%;
  227. }
  228. .home-banner-center {
  229. flex: 1;
  230. font-size: 38rpx;
  231. }
  232. .home-banner-rigth {
  233. width: 30%;
  234. }
  235. .home-main {
  236. padding: 12px 16px 0;
  237. }
  238. .home-ranking {
  239. padding: 24rpx 16px;
  240. }
  241. }
  242. .hot-box-title {
  243. padding: 0 32rpx;
  244. }
  245. .hot-swiper {
  246. padding: 24rpx 32rpx 0;
  247. }
  248. .hot-box {
  249. padding: 24rpx 32rpx;
  250. display: grid;
  251. grid-template-columns: repeat(2, 1fr);
  252. gap: 8rpx;
  253. .hot-item {
  254. // padding: 32rpx 16rpx;
  255. // border-radius: 10rpx;
  256. }
  257. }
  258. .home-grid2 {
  259. margin-bottom: 32rpx;
  260. background: #fff;
  261. padding: 12px 0;
  262. border-radius: 8px;
  263. }
  264. .home-g-bgc {
  265. background: #f7f7f7;
  266. padding: 24rpx;
  267. }
  268. </style>