index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view>
  3. <!-- 首页顶部定位区域 -->
  4. <view class="home-banner" :class="{ 'home-banner-with-bg': showAddressBg }">
  5. <view class="home-banner-left" @click="cityClick">
  6. <img src="@/static/uview/common/map-pin-fill@1x.png" alt="" class="map-pin-fill">
  7. <text class="address-text">{{ data.address.name }}</text>
  8. </view>
  9. </view>
  10. <view class="home-main">
  11. <view class="custom-swiper" v-if="list3.length > 0">
  12. <up-swiper :list="list3" indicator indicatorMode="line" circular :height="'554rpx'"></up-swiper>
  13. </view>
  14. </view>
  15. <view class="home-Wrapper">
  16. <view class="home-grid">
  17. <Client />
  18. </view>
  19. <view class="home-swiper" v-if="userType == 1">
  20. <view v-if="ValueZone.length > 0">
  21. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular></up-swiper>
  22. </view>
  23. <view>
  24. <up-notice-bar :text="text1" class="notice-bar"></up-notice-bar>
  25. </view>
  26. </view>
  27. <view class="home-ranking" :class="{ 'no-margin': userType === 2 }">
  28. <ServIces :leftList="leftList" :rightList="rightList" :ValueZoneSwiper="ValueZoneSwiper" v-if="userType == 1">
  29. </ServIces>
  30. <RankingList v-if="userType === 2" />
  31. </view>
  32. <up-loadmore style="margin-top: 40rpx" :status="loadmoreInfo.status" :loadmoreText="loadmoreInfo.loadingText"
  33. :loadingText="loadmoreInfo.loadmoreText" :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore"
  34. v-if="userType == 1" />
  35. </view>
  36. <custom-tab-bar page="home" class="customTabBar" />
  37. <view class="safe-area-bottom"></view>
  38. </view>
  39. </template>
  40. <script setup>
  41. import { ref, reactive, onMounted } from 'vue'
  42. import { onShow, onReachBottom, onUnload, onPageScroll } from '@dcloudio/uni-app'
  43. import RankingList from '@/pages/common/rankingList/index.vue'
  44. import ServIces from '@/components/Services/services.vue'
  45. import { Client } from '@/components/Client/new_file.vue'
  46. import { volunteerinfolist, systemConfig } from '@/api/volunteerDetailsApi/details.js'
  47. import { slideshow, settingHomeAddress } from '@/api/home.js'
  48. import { chooseLocationInit, locateTheCurrentAddress } from '@/utils/adress'
  49. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  50. import { regionAddresstree } from '@/api/home.js'
  51. import { getToken } from '@/utils/auth'
  52. import store from '@/store'
  53. const rightList = ref([])
  54. const leftList = ref([])
  55. const list3 = ref(['']) // Initialize with at least one empty item
  56. const ValueZone = ref(['']) // Initialize with at least one empty item
  57. const hotList = ref([])
  58. const ValueZoneSwiper = ref([''])
  59. const userType = uni.getStorageSync('userType') || 1; //读取本地存储
  60. const text1 = ref('');
  61. const globalData = ref({
  62. statusBarHeight: 47,
  63. navBarHeight: 91,
  64. })
  65. const data = reactive({
  66. address: store.state.user.addressInfo,
  67. queryValue: '',
  68. })
  69. console.log('--------index--------',data.address);
  70. // 分页
  71. const pages = ref({
  72. current: 1,
  73. pageSize: 10,
  74. total: 0,
  75. serviceCategory: '',
  76. // appStatus:"2",
  77. })
  78. const cityClick = async () => {
  79. const { latitude, longitude } = data.address
  80. const address = await chooseLocationInit(
  81. { latitude, longitude },
  82. addresstree.value
  83. )
  84. console.log('TCL: cityClick -> address', address)
  85. data.address = { ...data.address, ...address }
  86. store.dispatch('handlerAddress',data.address)
  87. settingAddress();
  88. console.log('address', address)
  89. }
  90. const loadmoreInfo = ref({
  91. status: 'loadmore',
  92. loadingText: '努力加载中...',
  93. loadmoreText: '点击加载更多~',
  94. nomoreText: '已经到底啦~',
  95. })
  96. // 加载更多
  97. async function handleLoadmore(e) {
  98. if (
  99. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  100. ) {
  101. pages.value.current += 1
  102. loadmoreInfo.value.status = 'loading'
  103. await getList()
  104. } else {
  105. loadmoreInfo.value.status = 'nomore'
  106. }
  107. }
  108. // 加载滚动文字
  109. const getNotice = async () => {
  110. const res = await systemConfig()
  111. text1.value = res.data
  112. }
  113. const getList = async () => {
  114. try {
  115. loadmoreInfo.value.status = 'loading'
  116. const { address } = data
  117. const { cityCode, latitude, longitude } = address
  118. const params = {
  119. pageNum: pages.value.current,
  120. pageSize: pages.value.pageSize,
  121. serviceCategory: pages.value.serviceCategory || '',
  122. businessManagementId: 0,
  123. provinceName: cityCode.data[0], // 省
  124. provinceCode: cityCode.code[0],
  125. cityName: cityCode.data[1], // 市
  126. cityCode: cityCode.code[1],
  127. districtName: cityCode.data[2],
  128. districtCode: cityCode.code[2],
  129. latitude,
  130. longitude,
  131. }
  132. console.log('volunteerinfolist ==>',params);
  133. const res = await volunteerinfolist(params)
  134. if (!res || !res.rows) {
  135. return
  136. }
  137. console.log(
  138. '判断是否已经到了最后一页',
  139. pages.value.current >= Math.ceil(res.total / pages.value.pageSize)
  140. )
  141. // 如果是第一页,先清空
  142. if (pages.value.current === 1) {
  143. leftList.value = [{ type: 'slideshow' }]
  144. rightList.value = []
  145. }
  146. // 每次都追加新数据
  147. res.rows.forEach((item, index) => {
  148. index % 2 !== 0 ? rightList.value.push(item) : leftList.value.push(item)
  149. })
  150. console.log('home', leftList.value, rightList.value);
  151. pages.value.total = res.total
  152. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  153. loadmoreInfo.value.status = 'nomore'
  154. } else {
  155. loadmoreInfo.value.status = 'loadmore'
  156. }
  157. } catch (error) {
  158. leftList.value = []
  159. rightList.value = []
  160. loadmoreInfo.value.status = 'loadmore'
  161. pages.value.total = 0
  162. console.error('Error fetching data:', error)
  163. }
  164. }
  165. onReachBottom(() => {
  166. if (
  167. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  168. ) {
  169. pages.value.current = pages.value.current + 1
  170. loadmoreInfo.value.status = 'nomore'
  171. getList()
  172. }
  173. })
  174. const getBanners = async () => {
  175. try {
  176. const res = await slideshow(21)
  177. if (res.code === 200 && res.data.picture) {
  178. list3.value = res.data.picture.split(',')
  179. }
  180. const value_res = await slideshow(20)
  181. if (value_res.code === 200 && value_res.data.picture) {
  182. ValueZone.value = value_res.data.picture.split(',')
  183. }
  184. const hot_res = await slideshow(11)
  185. if (hot_res.code === 200 && hot_res.data.picture) {
  186. hotList.value = hot_res.data.picture.split(',')
  187. }
  188. const hot_node = await slideshow(22)
  189. if (hot_node.code === 200 && hot_node.data.picture) {
  190. ValueZoneSwiper.value = hot_node.data.picture.split(',')
  191. }
  192. } catch (error) {
  193. console.log('error', error)
  194. }
  195. }
  196. const settingAddress = async () => {
  197. try {
  198. console.log('data', data)
  199. const { address } = data
  200. const { cityCode, latitude, longitude } = address
  201. const parmas = {
  202. provinceName: cityCode.data[0], // 省
  203. provinceCode: cityCode.code[0],
  204. provinceInd: cityCode.index[0],
  205. cityName: cityCode.data[1], // 市
  206. cityCode: cityCode.code[1],
  207. cityInd: cityCode.index[1],
  208. districtName: cityCode.data[2],
  209. districtCode: cityCode.code[2],
  210. districtInd: cityCode.index[2],
  211. address: address.name,
  212. latitude,
  213. longitude,
  214. }
  215. console.log("TCL: settingAddress -> parmas", parmas);
  216. const res = await settingHomeAddress(parmas)
  217. leftList.value = [];
  218. rightList.value = [];
  219. userType === 1 && getList()
  220. } catch (error) {
  221. console.log('设置地址失败', error)
  222. }
  223. }
  224. onShow(() => {
  225. getBanners()
  226. // 在 App.vue 中初始化
  227. uni.getSystemInfo({
  228. success: (res) => {
  229. const statusBarHeight = res.statusBarHeight
  230. const navBarHeight =
  231. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  232. globalData.value = { statusBarHeight, navBarHeight }
  233. },
  234. })
  235. console.log('=========>!userType',!userType);
  236. })
  237. const addresstree = ref([])
  238. const showAddressBg = ref(false)
  239. // Handle page scroll event
  240. onPageScroll(e => {
  241. // Show background when scrolled past threshold (middle of carousel, around 200px)
  242. showAddressBg.value = e.scrollTop > 180
  243. })
  244. onMounted(async () => {
  245. getNotice()
  246. const token = getToken();
  247. // console.log("TCL: token", token || 'null')
  248. if (token) {
  249. const res_dara = await regionAddresstree()
  250. addresstree.value = res_dara.data
  251. locateTheCurrentAddress(res_dara.data)
  252. .then((res) => {
  253. console.log('locateTheCurrentAddress', res)
  254. data.address = res
  255. settingAddress()
  256. })
  257. .catch((error) => {
  258. console.log('获取地址失败!', error)
  259. getList()
  260. })
  261. } else {
  262. getList();
  263. }
  264. })
  265. onUnload(() => { })
  266. </script>
  267. <style scoped lang="scss">
  268. // 首页顶部区域-轮播图
  269. .home-banner {
  270. position: fixed;
  271. z-index: 130;
  272. // top: v-bind('globalData.statusBarHeight + 10 + "px"');
  273. left: 0;
  274. height: 90px;
  275. width: 100%;
  276. padding: 10rpx 0;
  277. transition: background-color 0.3s ease;
  278. display: flex;
  279. flex-direction: column;
  280. justify-content: center;
  281. &.home-banner-with-bg {
  282. // background-color: rgba(255, 255, 255, 0.9);
  283. // box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  284. background: #FAFBF0;
  285. height: 90px;
  286. display: flex;
  287. flex-direction: column;
  288. justify-content: center;
  289. }
  290. .home-banner-left {
  291. display: flex;
  292. align-items: center;
  293. padding-left: 10rpx;
  294. box-sizing: border-box;
  295. margin-top: 80rpx;
  296. .map-pin-fill {
  297. width: 34rpx;
  298. height: 34rpx;
  299. }
  300. .address-text {
  301. width: 178rpx;
  302. height: 42rpx;
  303. font-family: PingFang SC;
  304. font-size: 28rpx;
  305. font-weight: normal;
  306. line-height: 40rpx;
  307. letter-spacing: normal;
  308. color: #000000;
  309. max-width: 120rpx;
  310. white-space: nowrap;
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. }
  314. }
  315. }
  316. // 分类下轮播图
  317. .home-swiper {
  318. margin-top: 40rpx;
  319. margin-right: 23rpx;
  320. margin-left: 23rpx;
  321. width: 704rpx;
  322. height: 180rpx;
  323. border-radius: 16rpx;
  324. background: linear-gradient(180deg, #FEF9ED 0%, #FFF9F3 100%);
  325. .notice-bar{
  326. margin-top: 10rpx;
  327. }
  328. }
  329. // 瀑布流
  330. .home-ranking {
  331. margin-top: 160rpx;
  332. margin-left: 11rpx;
  333. margin-right: 17rpx;
  334. margin-bottom: 120rpx;
  335. &.no-margin {
  336. margin-top: 0;
  337. }
  338. }
  339. // 轮播图下的圆角样式
  340. .home-Wrapper{
  341. position: absolute;
  342. top: 542rpx;
  343. width: 100%;
  344. border-radius: 20rpx 20rpx 0rpx 0rpx;
  345. overflow: hidden;
  346. background: #FFFFFF;
  347. }
  348. /* 底部安全区域 */
  349. .safe-area-bottom {
  350. height: 150rpx;
  351. width: 100%;
  352. }
  353. </style>