index.vue 11 KB

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