index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 {
  75. citySelectorNavigateTo
  76. } from '@/utils/adress'
  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. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  189. globalData.value = {
  190. statusBarHeight,
  191. navBarHeight
  192. };
  193. }
  194. });
  195. if (citySelector) {
  196. const selectedCity = citySelector.getCity(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
  197. data.address = selectedCity.name;
  198. }
  199. })
  200. onMounted(() => {
  201. getList()
  202. })
  203. onUnload(() => {
  204. if (citySelector) {
  205. // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
  206. citySelector.setLocation(null);
  207. }
  208. })
  209. </script>
  210. <style scoped lang="scss">
  211. .main-content {
  212. background: rgba(255, 255, 255, 1);
  213. .home-banner {
  214. display: flex;
  215. align-items: flex-end;
  216. justify-content: space-between;
  217. // background: rgba(255, 255, 255, 1);
  218. // background-color: #ED806A;
  219. background-color: rgba(221, 60, 62, 1);
  220. 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);
  221. padding: 20rpx 16rpx;
  222. color: #fff;
  223. position: fixed;
  224. top: 0px;
  225. left: 0px;
  226. right: 0;
  227. z-index: 99;
  228. }
  229. .home-banner-left {
  230. display: flex;
  231. align-items: center;
  232. width: 30%;
  233. }
  234. .home-banner-center {
  235. flex: 1;
  236. font-size: 38rpx;
  237. }
  238. .home-banner-rigth {
  239. width: 30%;
  240. }
  241. .home-main {
  242. padding: 12px 16px 0;
  243. }
  244. .home-ranking {
  245. padding: 24rpx 16px;
  246. }
  247. }
  248. .hot-box-title {
  249. padding: 0 32rpx;
  250. }
  251. .hot-swiper {
  252. padding: 24rpx 32rpx 0;
  253. }
  254. .hot-box {
  255. padding: 24rpx 32rpx;
  256. display: grid;
  257. grid-template-columns: repeat(2, 1fr);
  258. gap: 8rpx;
  259. .hot-item {
  260. // padding: 32rpx 16rpx;
  261. // border-radius: 10rpx;
  262. }
  263. }
  264. .home-grid2 {
  265. margin-bottom: 32rpx;
  266. background: #fff;
  267. padding: 12px 0;
  268. border-radius: 8px;
  269. }
  270. .home-g-bgc {
  271. background: #f7f7f7;
  272. padding: 24rpx;
  273. }
  274. </style>