index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 class="address-text">{{ data.address.name }}</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. settingHomeAddress
  72. } from '@/api/home.js'
  73. import {
  74. useDict
  75. } from '@/utils/dict.js';
  76. import { chooseLocationInit,locateTheCurrentAddress } from '@/utils/adress'
  77. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  78. const rightList = ref([])
  79. const leftList = ref([])
  80. const list3 = ref([]);
  81. const ValueZone = ref([]);
  82. const hotList = ref([])
  83. const userType = uni.getStorageSync('userType') //读取本地存储
  84. const globalData = ref({
  85. statusBarHeight: 47,
  86. navBarHeight: 91
  87. });
  88. const data = reactive({
  89. address: {
  90. name: '重庆市',
  91. latitude: 29.333000000000002,
  92. longitude: 105.94909000000001,
  93. cityCode:{
  94. code:[500000, 500100, 500118],
  95. data:["重庆市", "重庆市", "永川区"],
  96. index: [21, 0, 17]
  97. }
  98. },
  99. queryValue: ''
  100. })
  101. // 分页
  102. const pages = ref({
  103. current: 1,
  104. pageSize: 10,
  105. total: 0,
  106. serviceCategory: '',
  107. // appStatus:"2",
  108. })
  109. const cityClick = async () => {
  110. const {latitude,longitude} = data.address;
  111. const address = await chooseLocationInit({latitude,longitude});
  112. data.address = {...data.address,...address};
  113. settingAddress();
  114. console.log('address', address);
  115. }
  116. const loadmoreInfo = ref({
  117. status: 'loadmore',
  118. loadingText: '努力加载中...',
  119. loadmoreText: '点击加载更多~',
  120. nomoreText: '已经到底啦~'
  121. })
  122. // 加载更多
  123. async function handleLoadmore(e) {
  124. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  125. pages.value.current += 1;
  126. loadmoreInfo.value.status = 'loading';
  127. await getList();
  128. } else {
  129. loadmoreInfo.value.status = 'nomore';
  130. }
  131. }
  132. const getList = async () => {
  133. try {
  134. loadmoreInfo.value.status = 'loading';
  135. const params = {
  136. pageNum: pages.value.current,
  137. pageSize: pages.value.pageSize,
  138. serviceCategory: pages.value.serviceCategory || '',
  139. businessManagementId: 0,
  140. // appStatus:pages.value.appStatus,
  141. };
  142. const res = await volunteerinfolist(params);
  143. if (!res || !res.rows) {
  144. return;
  145. }
  146. <<<<<<< HEAD
  147. console.log('判断是否已经到了最后一页',pages.value.current >= Math.ceil(res.total / pages.value.pageSize));
  148. // 如果是第一页,先清空
  149. if (pages.value.current === 1) {
  150. leftList.value = [];
  151. rightList.value = [];
  152. }
  153. // 每次都追加新数据
  154. res.rows.forEach((item, index) => {
  155. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  156. });
  157. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  158. =======
  159. res.rows.forEach((item, index) => {
  160. index % 2 !== 0 ? rightList.value.push(item) : leftList.value.push(item);
  161. });
  162. pages.value.total = res.total;
  163. console.log('判断是否已经到了最后一页',pages.value.current, res.total,pages.value.pageSize);
  164. const isBottom = pages.value.current >= Math.ceil(res.total / pages.value.pageSize)
  165. // 判断是否已经到了最后一页
  166. if (isBottom) {
  167. >>>>>>> 9cb1dc3 (fix: 优化)
  168. loadmoreInfo.value.status = 'nomore';
  169. } else {
  170. loadmoreInfo.value.status = 'loadmore';
  171. }
  172. <<<<<<< HEAD
  173. pages.value.total = res.total;
  174. =======
  175. >>>>>>> 9cb1dc3 (fix: 优化)
  176. } catch (error) {
  177. leftList.value = [];
  178. rightList.value = [];
  179. loadmoreInfo.value.status = 'loadmore';
  180. pages.value.total = 0;
  181. console.error('Error fetching data:', error);
  182. }
  183. };
  184. onReachBottom(() => {
  185. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  186. pages.value.current = pages.value.current + 1
  187. loadmoreInfo.value.status = 'nomore'
  188. getList()
  189. }
  190. })
  191. const getBanners = async () => {
  192. try {
  193. const res = await slideshow(7);
  194. if (res.code === 200 && res.data.picture) {
  195. list3.value = res.data.picture.split(',');
  196. }
  197. const value_res = await slideshow(8);
  198. if (value_res.code === 200 && value_res.data.picture) {
  199. ValueZone.value = value_res.data.picture.split(',');
  200. }
  201. const hot_res = await slideshow(11);
  202. if (hot_res.code === 200 && hot_res.data.picture) {
  203. hotList.value = hot_res.data.picture.split(',');
  204. }
  205. } catch (error) {
  206. console.log('error', error);
  207. }
  208. }
  209. const settingAddress = async() => {
  210. try {
  211. const {address}=data;
  212. const {cityCode,latitude,longitude} = address;
  213. const parmas = {
  214. provinceName: cityCode.data[0], // 省
  215. provinceCode: cityCode.code[0],
  216. provinceInd: cityCode.index[0],
  217. cityName: cityCode.data[1], // 市
  218. cityCode: cityCode.code[1],
  219. cityInd: cityCode.index[1],
  220. districtName: cityCode.data[2],
  221. districtCode: cityCode.code[2],
  222. districtInd: cityCode.index[2],
  223. address: address.name,
  224. latitude,
  225. longitude
  226. }
  227. const res = await settingHomeAddress(parmas);
  228. console.log('res',res);
  229. userType === 1 && getList();
  230. } catch (error) {
  231. console.log('设置地址失败',error);
  232. }
  233. }
  234. onShow(() => {
  235. getBanners();
  236. // 在 App.vue 中初始化
  237. uni.getSystemInfo({
  238. success: (res) => {
  239. const statusBarHeight = res.statusBarHeight;
  240. console.log('res', res);
  241. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  242. globalData.value = { statusBarHeight, navBarHeight };
  243. }
  244. });
  245. })
  246. onMounted(() => {
  247. locateTheCurrentAddress().then(res => {
  248. console.log('locateTheCurrentAddress',res);
  249. data.address = res;
  250. settingAddress();
  251. }).catch(error => {
  252. console.log('获取地址失败!',error);
  253. getList()
  254. })
  255. })
  256. onUnload(() => {
  257. })
  258. </script>
  259. <style scoped lang="scss">
  260. .main-content {
  261. background: rgba(255, 255, 255, 1);
  262. .home-banner {
  263. display: flex;
  264. align-items: flex-end;
  265. justify-content: space-between;
  266. // background: rgba(255, 255, 255, 1);
  267. // background-color: #ED806A;
  268. background-color: rgba(221, 60, 62, 1);
  269. 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);
  270. padding: 20rpx 16rpx;
  271. color: #fff;
  272. position: fixed;
  273. top: 0px;
  274. left: 0px;
  275. right: 0;
  276. z-index: 99;
  277. bottom: 150rpx;
  278. }
  279. .home-box {
  280. padding-bottom: 150rpx;
  281. }
  282. .home-banner-left {
  283. display: flex;
  284. align-items: center;
  285. width: 30%;
  286. }
  287. .home-banner-center {
  288. flex: 1;
  289. font-size: 38rpx;
  290. }
  291. .home-banner-rigth {
  292. width: 30%;
  293. }
  294. .home-main {
  295. padding: 12px 16px 0;
  296. }
  297. .home-ranking {
  298. padding: 24rpx 16px;
  299. }
  300. }
  301. .hot-box-title {
  302. padding: 0 32rpx;
  303. }
  304. .hot-swiper {
  305. padding: 24rpx 32rpx 0;
  306. }
  307. .hot-box {
  308. padding: 24rpx 32rpx;
  309. display: grid;
  310. grid-template-columns: repeat(2, 1fr);
  311. gap: 8rpx;
  312. .hot-item {
  313. // padding: 32rpx 16rpx;
  314. // border-radius: 10rpx;
  315. }
  316. }
  317. .home-grid2 {
  318. margin-bottom: 32rpx;
  319. background: #fff;
  320. padding: 12px 0;
  321. border-radius: 8px;
  322. }
  323. .home-g-bgc {
  324. background: #f7f7f7;
  325. padding: 24rpx;
  326. }
  327. .address-text {
  328. white-space: nowrap;
  329. /* 禁止换行 */
  330. overflow: hidden;
  331. /* 隐藏溢出内容 */
  332. text-overflow: ellipsis;
  333. /* 超出部分显示省略号 */
  334. }
  335. </style>