123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { useState, useEffect } from 'react'
  2. import { useSelector } from 'react-redux'
  3. import Taro from '@tarojs/taro'
  4. import { ScrollView } from '@tarojs/components'
  5. import withLayout from '@/layout'
  6. import ProjectListItem from '@/components/ProjectListItem/index'
  7. // import ShareToCircle from '@/components/ShareToCircle/index'
  8. import { fetch } from '@/utils/request'
  9. import { API_BANNER_LIST, API_INDEX_PROJECTS } from '@/constants/api'
  10. import useParams from '@/utils/hooks/useParams'
  11. import useShare from '@/utils/hooks/useShare'
  12. import Location from './components/Location/index'
  13. import Banner from './components/Banner/index'
  14. import Menu from './components/Menu/index'
  15. import HotRecommend from './components/HotRecommend/index'
  16. import LiveSale from './components/LiveSale/index'
  17. import ColumnTitle from './components/ColumnTitle/index'
  18. import useIndexShareContent from './useIndexShareContent'
  19. import './index.scss'
  20. export default withLayout((props) => {
  21. const { city, router, person, trackData, page } = props
  22. // 本页面分享或者海报参数
  23. const paramsRef = useParams({person, from: `${page.type}_share`})
  24. const { miniApp } = useSelector(s => s.user.userInfo)
  25. const [BannerList, setBannerList] = useState([])
  26. const [ProjectList, setProjectList] = useState([])
  27. const [ShowHotRecommend, setShowHotRecommend] = useState(false)
  28. const [ShowLive, setShowLive] = useState(false)
  29. const shareContent = useIndexShareContent(miniApp, paramsRef, router)
  30. // 分享
  31. useShare(shareContent, trackData)
  32. useEffect(() => {
  33. if (city?.id) {
  34. GetBanner()
  35. GetProjectList()
  36. }
  37. }, [city?.id])
  38. const GetBanner = () => { // 获取banner
  39. fetch({ url: `${API_BANNER_LIST}/banner`, method: 'get', payload: { cityId: city.id, showPosition: 'index' } }).then((res) => {
  40. setBannerList(res || [])
  41. })
  42. }
  43. const GetProjectList = () => { // 获取项目列表
  44. fetch({ url: API_INDEX_PROJECTS, method: 'get', payload: { cityId: city.id, pageNum: 1, pageSize: 10 } }).then((res) => {
  45. setProjectList(res.records || [])
  46. })
  47. }
  48. const HotRecommendChange = (e) => {
  49. setShowHotRecommend(e)
  50. }
  51. const LiveChange = (e) => {
  52. setShowLive(e)
  53. }
  54. return (
  55. <view className='Page Index'>
  56. {/* <ShareToCircle visible></ShareToCircle> */}
  57. <ScrollView scroll-y>
  58. <view className='PageContent'>
  59. {/* 定位 */}
  60. <view className='Location'>
  61. <Location></Location>
  62. </view>
  63. {/* banner */}
  64. <view className='Banner'>
  65. <view>
  66. <view>
  67. <Banner List={BannerList}></Banner>
  68. </view>
  69. </view>
  70. </view>
  71. {/* 菜单 */}
  72. <view className='Menu'>
  73. <Menu></Menu>
  74. </view>
  75. {/* 热门推荐 */}
  76. <view className='HotRecommend' style={{display: ShowHotRecommend ? 'block' : 'none'}}>
  77. <ColumnTitle Name='热门推荐' Icon='icon-shoucang'></ColumnTitle>
  78. <HotRecommend change={HotRecommendChange}></HotRecommend>
  79. </view>
  80. {/* 直播购房 */}
  81. <view className='LiveSale' style={{display: ShowLive ? 'block' : 'none'}}>
  82. <ColumnTitle Name='直播购房' Icon='icon-yinpin' ShowMore ToMore={() => { Taro.switchTab({ url: `/pages/video/index` }) }}></ColumnTitle>
  83. <LiveSale change={LiveChange}></LiveSale>
  84. </view>
  85. {/* 全部项目 */}
  86. <view className='AllProject'>
  87. <ColumnTitle Name='全部项目' Icon='icon-aixin' ShowMore ToMore={() => { Taro.navigateTo({ url: `/pages/index/buildingList/index` }) }}></ColumnTitle>
  88. <view className='ProjectList'>
  89. {
  90. ProjectList.map((item, index) => (
  91. <ProjectListItem Data={item} key={`ProjectListItem-${index}`}></ProjectListItem>
  92. ))
  93. }
  94. </view>
  95. </view>
  96. {/* bottom */}
  97. <view className='PageBottom'>
  98. <text>已经到底了~</text>
  99. </view>
  100. </view>
  101. </ScrollView>
  102. </view>
  103. )
  104. })