index.vue 9.5 KB

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