index.vue 10.0 KB

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