index.jsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { useState, useEffect } from 'react'
  2. import { ScrollView, Input } from '@tarojs/components'
  3. import withLayout from '@/layout'
  4. import { fetch } from '@/utils/request'
  5. import '@/assets/css/iconfont.css'
  6. import { API_LIVE_LIST, API_VIDEO_LIST } from '@/constants/api'
  7. import './index.scss'
  8. import VideoListItem from './components/VideoListItem/index'
  9. export default withLayout((props) => {
  10. const { city } = props
  11. const [CurrnetMenuId, setCurrnetMenuId] = useState('all')
  12. const [MenuList] = useState([
  13. { name: '全部', id: 'all' },
  14. { name: '预告', id: 'notice' },
  15. { name: '直播中', id: 'live' },
  16. { name: '新房推荐', id: 'new' },
  17. { name: '视频', id: 'video' }
  18. ])
  19. const [PageList, setPageList] = useState([])
  20. // 全部或者新房的列表
  21. const [activityList, setActivityList] = useState([])
  22. // 预告与直播的列表
  23. const [liveList, setLiveList] = useState([])
  24. // 视频的列表
  25. const [videoList, setVideoList] = useState([])
  26. useEffect(() => {
  27. if (city?.id) {
  28. GetLiveList()
  29. }
  30. }, [city?.id, CurrnetMenuId])
  31. const GetLiveList = (params) => {
  32. if (['all'].indexOf(CurrnetMenuId) > -1) {
  33. // 全部
  34. fetch({ url: API_LIVE_LIST, payload: { ...params, cityId: city.id, pageSize: 999 }, spin: true }).then((res) => {
  35. setPageList(res.records || [])
  36. })
  37. } else if (['new'].indexOf(CurrnetMenuId) > -1) {
  38. // 新房
  39. fetch({ url: API_LIVE_LIST, payload: { ...params, cityId: city.id, newHouse: true, pageSize: 999 }, spin: true }).then((res) => {
  40. setPageList(res.records || [])
  41. })
  42. } else if (['notice', 'live'].indexOf(CurrnetMenuId) > -1) {
  43. // 预告与直播是虽然是同一个接口, 但是返回值字段不一样
  44. const process = 'notice' === CurrnetMenuId ? 1 : 2;
  45. fetch({ url: API_LIVE_LIST, payload: { ...params, cityId: city.id, process, pageSize: 999 }, spin: true}).then((res) => {
  46. setPageList(res.records || [])
  47. })
  48. } else {
  49. // 视频另外一个接口
  50. fetch({ url: API_VIDEO_LIST, payload: { ...params, cityId: city.id, pageSize: 999 }, spin: true }).then((res) => {
  51. setPageList(res.records || [])
  52. })
  53. }
  54. }
  55. const CutMenu = (id) => {
  56. return () => {
  57. if (id !== CurrnetMenuId) {
  58. setCurrnetMenuId(id)
  59. }
  60. }
  61. }
  62. return (
  63. <view className='Page Video flex-v'>
  64. <view className='Search'>
  65. <view>
  66. <text className='iconfont icon-sousuo'></text>
  67. <Input placeholder='请输入直播标题'></Input>
  68. </view>
  69. </view>
  70. <view className='Menu'>
  71. <view className='flex-h'>
  72. {
  73. MenuList.map((item, index) => (
  74. <view key={`MenuItem-${index}`} className={CurrnetMenuId === item.id ? 'active' : ''}>
  75. <text onClick={CutMenu(item.id)}>{item.name}</text>
  76. </view>
  77. ))
  78. }
  79. </view>
  80. </view>
  81. <view className='flex-item'>
  82. <view>
  83. <ScrollView scroll-y>
  84. <view className='PageContent'>
  85. {
  86. PageList.map((item, index) => (
  87. <view className='ListItem' key={`List-${index}`}>
  88. <view>
  89. <view>
  90. <VideoListItem Data={item}></VideoListItem>
  91. </view>
  92. </view>
  93. </view>
  94. ))
  95. }
  96. {/* bottom */}
  97. <view className='PageBottom'>
  98. <text>已经到底了~</text>
  99. </view>
  100. </view>
  101. </ScrollView>
  102. </view>
  103. </view>
  104. </view>
  105. )
  106. })