index.vue 11 KB

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