index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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="#000" size="25"></up-icon>
  6. <text class="address-text">{{ data.address.name }}</text>
  7. </view>
  8. </view>
  9. <view class="home-box" :style="`margin-top: ${globalData.navBarHeight}px `">
  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. <up-loadmore style="margin-top: 40rpx" :status="loadmoreInfo.status" :loadmoreText="loadmoreInfo.loadingText"
  16. :loadingText="loadmoreInfo.loadmoreText" :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore"
  17. v-if="userType == 1" />
  18. </view>
  19. <view class="Wrapper">
  20. <view class="home-g-bgc">
  21. <Client />
  22. </view>
  23. <view class="hot-swiper" v-if="ValueZone.length > 0">
  24. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular></up-swiper>
  25. </view>
  26. <view class="home-ranking">
  27. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  28. <RankingList v-if="userType === 2" />
  29. </view>
  30. </view>
  31. <custom-tab-bar page="home" class="customTabBar" />
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref, reactive, onMounted } from 'vue'
  36. import { provide } from 'vue'
  37. import { onLoad, onShow, onReachBottom, onUnload } from '@dcloudio/uni-app'
  38. import RankingList from '@/pages/common/rankingList/index.vue'
  39. import ServIces from '@/components/Services/services.vue'
  40. import { Client } from '@/components/Client/new_file.vue'
  41. import { volunteerinfolist } from '@/api/volunteerDetailsApi/details.js'
  42. import { slideshow, settingHomeAddress } from '@/api/home.js'
  43. import { useDict } from '@/utils/dict.js'
  44. import { chooseLocationInit, locateTheCurrentAddress } from '@/utils/adress'
  45. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  46. import { regionAddresstree } from '@/api/home.js'
  47. import { getToken } from '@/utils/auth'
  48. const rightList = ref([])
  49. const leftList = ref([])
  50. const list3 = ref(['']) // Initialize with at least one empty item
  51. const ValueZone = ref(['']) // Initialize with at least one empty item
  52. const hotList = ref([])
  53. const userType = uni.getStorageSync('userType') //读取本地存储
  54. const text1 = ref(
  55. '热烈祝贺:于5月20日上午9:00点钟召开"金邻助家"平台项目的首次发布会!'
  56. )
  57. const globalData = ref({
  58. statusBarHeight: 47,
  59. navBarHeight: 91,
  60. })
  61. const data = reactive({
  62. address: {
  63. name: '重庆市',
  64. latitude: 29.333000000000002,
  65. longitude: 105.94909000000001,
  66. cityCode: {
  67. code: [500000, 500100, 500118],
  68. data: ['重庆市', '重庆市', '永川区'],
  69. index: [21, 0, 17],
  70. },
  71. },
  72. queryValue: '',
  73. })
  74. // 分页
  75. const pages = ref({
  76. current: 1,
  77. pageSize: 10,
  78. total: 0,
  79. serviceCategory: '',
  80. // appStatus:"2",
  81. })
  82. const cityClick = async () => {
  83. const { latitude, longitude } = data.address
  84. const address = await chooseLocationInit(
  85. { latitude, longitude },
  86. addresstree.value
  87. )
  88. console.log('TCL: cityClick -> address', address)
  89. data.address = { ...data.address, ...address }
  90. settingAddress()
  91. console.log('address', address)
  92. }
  93. const loadmoreInfo = ref({
  94. status: 'loadmore',
  95. loadingText: '努力加载中...',
  96. loadmoreText: '点击加载更多~',
  97. nomoreText: '已经到底啦~',
  98. })
  99. // 加载更多
  100. async function handleLoadmore(e) {
  101. if (
  102. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  103. ) {
  104. pages.value.current += 1
  105. loadmoreInfo.value.status = 'loading'
  106. await getList()
  107. } else {
  108. loadmoreInfo.value.status = 'nomore'
  109. }
  110. }
  111. const getList = async () => {
  112. try {
  113. loadmoreInfo.value.status = 'loading'
  114. const params = {
  115. pageNum: pages.value.current,
  116. pageSize: pages.value.pageSize,
  117. serviceCategory: pages.value.serviceCategory || '',
  118. businessManagementId: 0,
  119. // appStatus:pages.value.appStatus,
  120. }
  121. const res = await volunteerinfolist(params)
  122. if (!res || !res.rows) {
  123. return
  124. }
  125. console.log(
  126. '判断是否已经到了最后一页',
  127. pages.value.current >= Math.ceil(res.total / pages.value.pageSize)
  128. )
  129. // 如果是第一页,先清空
  130. if (pages.value.current === 1) {
  131. leftList.value = []
  132. rightList.value = []
  133. }
  134. // 每次都追加新数据
  135. res.rows.forEach((item, index) => {
  136. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item)
  137. })
  138. pages.value.total = res.total
  139. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  140. loadmoreInfo.value.status = 'nomore'
  141. } else {
  142. loadmoreInfo.value.status = 'loadmore'
  143. }
  144. } catch (error) {
  145. leftList.value = []
  146. rightList.value = []
  147. loadmoreInfo.value.status = 'loadmore'
  148. pages.value.total = 0
  149. console.error('Error fetching data:', error)
  150. }
  151. }
  152. onReachBottom(() => {
  153. if (
  154. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  155. ) {
  156. pages.value.current = pages.value.current + 1
  157. loadmoreInfo.value.status = 'nomore'
  158. getList()
  159. }
  160. })
  161. const getBanners = async () => {
  162. try {
  163. const res = await slideshow(21)
  164. if (res.code === 200 && res.data.picture) {
  165. list3.value = res.data.picture.split(',')
  166. }
  167. const value_res = await slideshow(20)
  168. if (value_res.code === 200 && value_res.data.picture) {
  169. ValueZone.value = value_res.data.picture.split(',')
  170. }
  171. const hot_res = await slideshow(11)
  172. if (hot_res.code === 200 && hot_res.data.picture) {
  173. hotList.value = hot_res.data.picture.split(',')
  174. }
  175. } catch (error) {
  176. console.log('error', error)
  177. }
  178. }
  179. const settingAddress = async () => {
  180. try {
  181. console.log('data', data)
  182. const { address } = data
  183. const { cityCode, latitude, longitude } = address
  184. const parmas = {
  185. provinceName: cityCode.data[0], // 省
  186. provinceCode: cityCode.code[0],
  187. provinceInd: cityCode.index[0],
  188. cityName: cityCode.data[1], // 市
  189. cityCode: cityCode.code[1],
  190. cityInd: cityCode.index[1],
  191. districtName: cityCode.data[2],
  192. districtCode: cityCode.code[2],
  193. districtInd: cityCode.index[2],
  194. address: address.name,
  195. latitude,
  196. longitude,
  197. }
  198. const res = await settingHomeAddress(parmas)
  199. console.log('res', res)
  200. userType === 1 && getList()
  201. } catch (error) {
  202. console.log('设置地址失败', error)
  203. }
  204. }
  205. onShow(() => {
  206. getBanners()
  207. // 在 App.vue 中初始化
  208. uni.getSystemInfo({
  209. success: (res) => {
  210. const statusBarHeight = res.statusBarHeight
  211. console.log('res', res)
  212. const navBarHeight =
  213. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  214. globalData.value = { statusBarHeight, navBarHeight }
  215. },
  216. })
  217. })
  218. const addresstree = ref([])
  219. onMounted(async () => {
  220. const token = getToken()
  221. if (token) {
  222. const res_dara = await regionAddresstree()
  223. addresstree.value = res_dara.data
  224. locateTheCurrentAddress(res_dara.data)
  225. .then((res) => {
  226. console.log('locateTheCurrentAddress', res)
  227. data.address = res
  228. settingAddress()
  229. })
  230. .catch((error) => {
  231. console.log('获取地址失败!', error)
  232. getList()
  233. })
  234. } else {
  235. //设置默认角色
  236. uni.setStorageSync('userType', 1)
  237. getList()
  238. }
  239. })
  240. onUnload(() => { })
  241. </script>
  242. <style scoped lang="scss">
  243. .customTabBar {
  244. position: fixed;
  245. left: 0;
  246. right: 0;
  247. bottom: 0;
  248. z-index: 9999;
  249. }
  250. .home-banner {
  251. display: flex;
  252. align-items: flex-end;
  253. justify-content: space-between;
  254. padding: 20rpx 16rpx;
  255. color: #fff;
  256. // position: fixed;
  257. // top: 0px;
  258. // left: 0px;
  259. // right: 0;
  260. z-index: 99;
  261. // bottom: 150rpx;
  262. }
  263. .home-box {
  264. padding-bottom: 150rpx;
  265. }
  266. .home-banner-left {
  267. display: flex;
  268. align-items: center;
  269. width: 30%;
  270. z-index: 110;
  271. }
  272. .Wrapper {
  273. background: rgba(255, 255, 255, 1);
  274. // background: red;
  275. position: absolute;
  276. top: 309px;
  277. left: 0;
  278. right: 0;
  279. bottom: 0;
  280. border-radius: 20rpx 20rpx 0rpx 0rpx;
  281. z-index: 130;
  282. }
  283. .home-main {
  284. padding: 12px 16px 0;
  285. z-index: 99;
  286. }
  287. .home-ranking {
  288. padding: 24rpx 16px;
  289. }
  290. .hot-box-title {
  291. margin-top: 24rpx;
  292. padding: 0 32rpx;
  293. }
  294. .hot-swiper {
  295. // padding: 24rpx 32rpx 0;
  296. width: 704rpx;
  297. height: 180rpx;
  298. border-radius: 16rpx;
  299. background: linear-gradient(180deg, #FEF9ED 0%, #FFF9F3 100%);
  300. margin-top: 40rpx;
  301. margin-right: 23rpx;
  302. margin-left: 23rpx;
  303. }
  304. .hot-box {
  305. padding: 24rpx 32rpx;
  306. display: grid;
  307. grid-template-columns: repeat(2, 1fr);
  308. gap: 8rpx;
  309. .hot-item {
  310. // padding: 32rpx 16rpx;
  311. // border-radius: 10rpx;
  312. }
  313. }
  314. .home-grid {
  315. margin-top: 220rpx;
  316. }
  317. .home-g-bgc {
  318. background: rgba(255, 255, 255, 1);
  319. padding: -2rpx;
  320. }
  321. .custom-swiper {
  322. width: 750rpx;
  323. height: 554rpx;
  324. // position: fixed;
  325. position: absolute;
  326. top: 0px;
  327. left: 0px;
  328. right: 0;
  329. z-index: 99;
  330. // background: red; // 移除测试色
  331. }
  332. .address-text {
  333. white-space: nowrap;
  334. /* 禁止换行 */
  335. overflow: hidden;
  336. /* 隐藏溢出内容 */
  337. text-overflow: ellipsis;
  338. /* 超出部分显示省略号 */
  339. color: #000;
  340. }
  341. </style>