import { useState, useEffect } from 'react'
import withLayout from '@/layout'
import { fetch } from '@/utils/request'
import { API_ITEMS_DETAIL } from '@/constants/api'
import { ScrollView } from '@tarojs/components'
import { formatDate } from '@/utils/chatDate'
import '@/assets/css/iconfont.css'
import './index.scss'

export default withLayout((props) => {
  const { router } = props
  const { id } = router.params
  const [PageList, setPageList] = useState([])
  
  useEffect(() => {
    // 获取楼盘信息
    fetch({ url: `${API_ITEMS_DETAIL}/${id}`, spin: true }).then((res) => {
      setPageList(res?.trendList || [])
    })
  }, [id, router.path])

  return (
    <view className='Page buildingDynamic'>
      <ScrollView scroll-y>
        <view className='Content'>

          {/* <view className='Top'>
            <text className='iconfont icon-shengming'></text>
            <text>楼盘资讯</text>
            <text className='active' onClick={() => {Taro.navigateTo({url: '/pages/index/disclaimer/index'})}}>免责声明》</text>
          </view> */}

          <view className='List'>
            {
              PageList.map((item, index) => (
                <view key={`ListItem-${index}`}>
                  <text className='Time'>{formatDate(item.trendTime, 'yyyy-M-dd')}</text>
                  <view className='ItemContent'>
                    <text className='Title'>{item.trendTitle}</text>
                    <text className='desc'>{item.trendContent}</text>
                    <view className='Line'></view>
                  </view>
                </view>
              ))
            }
          </view>

          {/* bottom */}
          <view className='PageBottom'>
            <text>已经到底了~</text>
          </view>

        </view>
      </ScrollView>
    </view>
  )
})
