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