import { View, Image } from "@tarojs/components"
import Taro from "@tarojs/taro"
import { useEffect, useState } from "react"
import withLayout from '@/layouts'
import { getNewsList } from "@/services/news"
import formatTimes from "@/utils/codeSegment"
import ListPlaceholder from "@/components/ListPlaceholder"

import './InformationCss/style.less'




export default withLayout((props) => {
  const [newList, setNewList] = useState([])

  const goInfoMationInfo = (res) => {
    Taro.navigateTo({ url: `/pages/InformationInfo/index?id=${res}` })

  }
  useEffect(() => {
    getNewsList().then((res) => {
      setNewList(res.records)
    })
  }, [])

  return (

    <scroll-view scrollY style='height: 100%;' >
      <View >
        {
          newList?.length > 0 ? newList?.map((item, index) => {
            return (
              <View key={index} className='help-center-cell' onClick={() => goInfoMationInfo(item?.newsId)} >
                <Image src={item?.thumb} />
                <View className='help-center-cell-bottom' >
                  <View className='help-center-cell-bottom-title'  >{item?.title}</View>
                  <View className='help-center-cell-bottom-content' >{formatTimes(item?.createDate, 'yyyy-mm-dd')}</View>
                </View>
              </View>
            )
          }) : <ListPlaceholder title='暂无农业资讯' />
        }


      </View>

    </scroll-view>
  )
})
