index.vue 7.4 KB

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