index.jsx 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { useState, useEffect } from 'react'
  2. import { useModel } from '@/store'
  3. import Taro from '@tarojs/taro'
  4. import WuYeGongGaoItem from '@/components/WuYeGongGaoItem/index'
  5. import ScrollPageRefresh from '@/components/ScrollPageRefresh/index'
  6. import request, { apis } from '@/utils/request'
  7. import nav2detail from '@/utils/nav2detail'
  8. import '@/assets/css/reset.less'
  9. import '@/assets/css/iconfont.less'
  10. import './index.less'
  11. export default function WuYeGongGao () {
  12. const { user } = useModel('user')
  13. const [PageList, setPageList] = useState([])
  14. const [BannerList, setBannerList] = useState([])
  15. const [IsEmpty, setIsEmpty] = useState(false)
  16. useEffect(() => {
  17. GetBanner()
  18. }, [])
  19. const GetBanner = (done = () => { }) => { // 获取轮播图
  20. request({ ...apis.getBanner, params: { showPosition: `property`, showType: 'banner', pageNum: 1, pageSize: 1 } }).then((res) => {
  21. setBannerList([...(res || [])])
  22. done()
  23. }).catch(() => {
  24. done()
  25. })
  26. }
  27. const Refresh = (e) => { // 下拉刷新
  28. if (e.length > 0) {
  29. setIsEmpty(false)
  30. setPageList(e)
  31. } else {
  32. setIsEmpty(true)
  33. }
  34. }
  35. const Push = (e) => { // 上拉加载
  36. setPageList(PageList.concat(e))
  37. }
  38. return (
  39. <view className='WuYeGongGao'>
  40. <ScrollPageRefresh
  41. IsEmpty={IsEmpty}
  42. ApiName={`getGongGaoList`}
  43. RequestUrlData={{ orgId: user.orgId }}
  44. Refresh={Refresh}
  45. Push={Push}
  46. KeepChildren={
  47. <view>
  48. {/* 大图 */}
  49. <view className='BigImg'>
  50. {
  51. BannerList.length > 0 &&
  52. <image mode='aspectFill' src={BannerList[0].image} className='centerLabel' onClick={() => nav2detail({ type: BannerList[0].contentType, id: BannerList[0].targetId })}></image>
  53. }
  54. </view>
  55. </view>
  56. }
  57. >
  58. {/* 列表 */}
  59. <view className='List'>
  60. {
  61. PageList.map((item, index) => (
  62. <view key={`WuYeGongGaoItem-${index}`}>
  63. <WuYeGongGaoItem Data={item}></WuYeGongGaoItem>
  64. </view>
  65. ))
  66. }
  67. </view>
  68. </ScrollPageRefresh>
  69. </view>
  70. )
  71. }