import React, { useState, useEffect } from 'react'
import WuYeJiaoFeiItem from '@/components/WuYeJiaoFeiItem/index'
import ScrollPageRefresh from '@/components/ScrollPageRefresh/index'
import request, { apis } from '@/utils/request'
import '@/assets/css/reset.less'
import '@/assets/css/iconfont.less'
import './index.less'

export default function WuYeJiaoFei () {

  const [PageList, setPageList] = useState([])
  const [BannerList, setBannerList] = useState([])

  useEffect(() => {
    GetBanner()
  }, [])

  const GetBanner = (done = () => { }) => { // 获取轮播图
    request({ ...apis.getBanner, params: { contentType: `news`, pageNum: 1, pageSize: 1 } }).then((res) => {
      setBannerList([...(res || [])])
      done()
    }).catch(() => {
      done()
    })
  }

  const Refresh = (e) => { // 下拉刷新
    setPageList(e)
  }

  const Push = (e) => { // 上拉加载
    setPageList(PageList.concat(e))
  }

  return (
    <view className='WuYeJiaoFei'>
      <ScrollPageRefresh ApiName={`getJiaoFeiList`} ListName={`list`} RequestUrlData={{ type: 0 }} Refresh={Refresh} Push={Push}>

        {/* 大图 */}
        <view className='BigImg'>
          {
            BannerList.length > 0 &&
            <image mode='aspectFill' src={BannerList[0].image} className='centerLabel' onClick={() => { Taro.navigateTo({ url: `/pages/HuoDong/ZiXunDetail/index?id=${BannerList[0].targetId}` }) }}></image>
          }
        </view>

        {/* 缴费列表 */}
        <view className='List'>
          {
            PageList.map((item, index) => (
              <view key={`WuYeJiaoFeiItem-${index}`}>
                <WuYeJiaoFeiItem Data={item}></WuYeJiaoFeiItem>
              </view>
            ))
          }
        </view>

      </ScrollPageRefresh>
    </view>
  )
}
