index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view>
  3. <!-- 首页顶部定位区域 -->
  4. <view class="home-banner">
  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. </view>
  62. </template>
  63. <script setup>
  64. import { ref, reactive, onMounted } from 'vue'
  65. import { provide } from 'vue'
  66. import { onLoad, onShow, onReachBottom, onUnload } from '@dcloudio/uni-app'
  67. import RankingList from '@/pages/common/rankingList/index.vue'
  68. import ServIces from '@/components/Services/services.vue'
  69. import { Client } from '@/components/Client/new_file.vue'
  70. import { volunteerinfolist } from '@/api/volunteerDetailsApi/details.js'
  71. import { slideshow, settingHomeAddress } from '@/api/home.js'
  72. import { useDict } from '@/utils/dict.js'
  73. import { chooseLocationInit, locateTheCurrentAddress } from '@/utils/adress'
  74. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  75. import { regionAddresstree } from '@/api/home.js'
  76. import { getToken } from '@/utils/auth'
  77. const rightList = ref([])
  78. const leftList = ref([])
  79. const list3 = ref(['']) // Initialize with at least one empty item
  80. const ValueZone = ref(['']) // Initialize with at least one empty item
  81. const hotList = ref([])
  82. const ValueZoneSwiper = ref([''])
  83. const userType = uni.getStorageSync('userType'); //读取本地存储
  84. const globalData = ref({
  85. statusBarHeight: 47,
  86. navBarHeight: 91,
  87. })
  88. const data = reactive({
  89. address: {
  90. name: '重庆市',
  91. latitude: 29.333000000000002,
  92. longitude: 105.94909000000001,
  93. cityCode: {
  94. code: [500000, 500100, 500118],
  95. data: ['重庆市', '重庆市', '永川区'],
  96. index: [21, 0, 17],
  97. },
  98. },
  99. queryValue: '',
  100. })
  101. // 分页
  102. const pages = ref({
  103. current: 1,
  104. pageSize: 10,
  105. total: 0,
  106. serviceCategory: '',
  107. // appStatus:"2",
  108. })
  109. const cityClick = async () => {
  110. const { latitude, longitude } = data.address
  111. const address = await chooseLocationInit(
  112. { latitude, longitude },
  113. addresstree.value
  114. )
  115. console.log('TCL: cityClick -> address', address)
  116. data.address = { ...data.address, ...address }
  117. settingAddress()
  118. console.log('address', address)
  119. }
  120. const loadmoreInfo = ref({
  121. status: 'loadmore',
  122. loadingText: '努力加载中...',
  123. loadmoreText: '点击加载更多~',
  124. nomoreText: '已经到底啦~',
  125. })
  126. // 加载更多
  127. async function handleLoadmore(e) {
  128. if (
  129. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  130. ) {
  131. pages.value.current += 1
  132. loadmoreInfo.value.status = 'loading'
  133. await getList()
  134. } else {
  135. loadmoreInfo.value.status = 'nomore'
  136. }
  137. }
  138. const getList = async () => {
  139. try {
  140. loadmoreInfo.value.status = 'loading'
  141. const params = {
  142. pageNum: pages.value.current,
  143. pageSize: pages.value.pageSize,
  144. serviceCategory: pages.value.serviceCategory || '',
  145. businessManagementId: 0,
  146. // appStatus:pages.value.appStatus,
  147. }
  148. const res = await volunteerinfolist(params)
  149. if (!res || !res.rows) {
  150. return
  151. }
  152. console.log(
  153. '判断是否已经到了最后一页',
  154. pages.value.current >= Math.ceil(res.total / pages.value.pageSize)
  155. )
  156. // 如果是第一页,先清空
  157. if (pages.value.current === 1) {
  158. leftList.value = []
  159. rightList.value = []
  160. }
  161. // 每次都追加新数据
  162. res.rows.forEach((item, index) => {
  163. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item)
  164. })
  165. console.log('home', leftList.value, rightList.value);
  166. pages.value.total = res.total
  167. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  168. loadmoreInfo.value.status = 'nomore'
  169. } else {
  170. loadmoreInfo.value.status = 'loadmore'
  171. }
  172. } catch (error) {
  173. leftList.value = []
  174. rightList.value = []
  175. loadmoreInfo.value.status = 'loadmore'
  176. pages.value.total = 0
  177. console.error('Error fetching data:', error)
  178. }
  179. }
  180. onReachBottom(() => {
  181. if (
  182. pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)
  183. ) {
  184. pages.value.current = pages.value.current + 1
  185. loadmoreInfo.value.status = 'nomore'
  186. getList()
  187. }
  188. })
  189. const getBanners = async () => {
  190. try {
  191. const res = await slideshow(21)
  192. if (res.code === 200 && res.data.picture) {
  193. list3.value = res.data.picture.split(',')
  194. }
  195. const value_res = await slideshow(20)
  196. if (value_res.code === 200 && value_res.data.picture) {
  197. ValueZone.value = value_res.data.picture.split(',')
  198. }
  199. const hot_res = await slideshow(11)
  200. if (hot_res.code === 200 && hot_res.data.picture) {
  201. hotList.value = hot_res.data.picture.split(',')
  202. }
  203. const hot_node = await slideshow(22)
  204. if (hot_node.code === 200 && hot_node.data.picture) {
  205. ValueZoneSwiper.value = hot_node.data.picture.split(',')
  206. }
  207. } catch (error) {
  208. console.log('error', error)
  209. }
  210. }
  211. const settingAddress = async () => {
  212. try {
  213. console.log('data', data)
  214. const { address } = data
  215. const { cityCode, latitude, longitude } = address
  216. const parmas = {
  217. provinceName: cityCode.data[0], // 省
  218. provinceCode: cityCode.code[0],
  219. provinceInd: cityCode.index[0],
  220. cityName: cityCode.data[1], // 市
  221. cityCode: cityCode.code[1],
  222. cityInd: cityCode.index[1],
  223. districtName: cityCode.data[2],
  224. districtCode: cityCode.code[2],
  225. districtInd: cityCode.index[2],
  226. address: address.name,
  227. latitude,
  228. longitude,
  229. }
  230. console.log("TCL: settingAddress -> parmas", parmas);
  231. const res = await settingHomeAddress(parmas)
  232. userType === 1 && getList()
  233. } catch (error) {
  234. console.log('设置地址失败', error)
  235. }
  236. }
  237. onShow(() => {
  238. getBanners()
  239. // 在 App.vue 中初始化
  240. uni.getSystemInfo({
  241. success: (res) => {
  242. const statusBarHeight = res.statusBarHeight
  243. const navBarHeight =
  244. res.platform === 'android' ? 48 : 44 + res.statusBarHeight
  245. globalData.value = { statusBarHeight, navBarHeight }
  246. },
  247. })
  248. })
  249. const addresstree = ref([])
  250. onMounted(async () => {
  251. const token = getToken();
  252. console.log("TCL: token", token || 'null')
  253. if (token) {
  254. const res_dara = await regionAddresstree()
  255. addresstree.value = res_dara.data
  256. locateTheCurrentAddress(res_dara.data)
  257. .then((res) => {
  258. console.log('locateTheCurrentAddress', res)
  259. data.address = res
  260. settingAddress()
  261. })
  262. .catch((error) => {
  263. console.log('获取地址失败!', error)
  264. getList()
  265. })
  266. } else {
  267. //设置默认角色
  268. uni.setStorageSync('userType', 1);
  269. getList();
  270. }
  271. })
  272. onUnload(() => { })
  273. </script>
  274. <style scoped lang="scss">
  275. // 首页顶部区域-轮播图
  276. .home-banner {
  277. position: absolute;
  278. z-index: 130;
  279. // top: 110rpx;
  280. .home-banner-left {
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. .map-pin-fill {
  285. width: 34rpx;
  286. height: 34rpx;
  287. }
  288. .address-text {
  289. width: 178rpx;
  290. height: 42rpx;
  291. font-family: PingFang SC;
  292. font-size: 28rpx;
  293. font-weight: normal;
  294. line-height: 40rpx;
  295. letter-spacing: normal;
  296. color: #000000;
  297. max-width: 120rpx;
  298. white-space: nowrap;
  299. overflow: hidden;
  300. text-overflow: ellipsis;
  301. }
  302. }
  303. }
  304. // 分类下轮播图
  305. .home-swiper {
  306. margin-top: 40rpx;
  307. margin-right: 23rpx;
  308. margin-left: 23rpx;
  309. width: 704rpx;
  310. height: 180rpx;
  311. border-radius: 16rpx;
  312. background: linear-gradient(180deg, #FEF9ED 0%, #FFF9F3 100%);
  313. }
  314. // 瀑布流
  315. .home-ranking {
  316. margin-top: 80rpx;
  317. margin-left: 25rpx;
  318. margin-right: 25rpx;
  319. }
  320. </style>