index.jsx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { useState, useEffect } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import { ScrollView, Image } from '@tarojs/components'
  4. import { useSelector } from 'react-redux'
  5. import { fetch } from '@/utils/request'
  6. import { getImgURL } from '@/utils/image'
  7. import { API_LIVE_LIST } from '@/constants/api'
  8. import '@/assets/css/iconfont.css'
  9. import './index.scss'
  10. export default function LiveSale (props) {
  11. const { change = () => {} } = props
  12. const city = useSelector(state => state.city)
  13. const [MenuList] = useState([{ name: '全部', id: 1 }, { name: '预告', id: 2 }, { name: '直播中', id: 3 }, { name: '新房推荐', id: 4 }])
  14. const [CurrentId, setCurrentId] = useState(1)
  15. const [PageList, setPageList] = useState([])
  16. useEffect(() => {
  17. if(city.curCity.name) {
  18. GetLiveList()
  19. }
  20. }, [city])
  21. const GetLiveList = () => {
  22. fetch({url: API_LIVE_LIST, method: 'get', payload: {cityId: city.curCity.id, pageNum: 1, pageSize: 20}}).then((res) => {
  23. setPageList(res.records || [])
  24. change(!!(res.records || []).length)
  25. })
  26. }
  27. const CutMenu = (id) => {
  28. return () => {
  29. setCurrentId(id)
  30. }
  31. }
  32. const toDetail = (item) => {
  33. return () => {
  34. if(item.type === 'live') {
  35. Taro.navigateTo({ url: `/pages/video/liveDetail/index?id=${item.id}&type=${item.type}` })
  36. } else {
  37. Taro.navigateTo({ url: `/pages/video/videoDetail/index?id=${item.id}` })
  38. }
  39. }
  40. }
  41. return (
  42. <view className='components LiveSale'>
  43. <view>
  44. <view className='Menu'>
  45. {
  46. MenuList.map((item, index) => (
  47. <view onClick={CutMenu(item.id)} className={CurrentId === item.id ? 'active' : ''} key={`Menu-${index}`}>{item.name}</view>
  48. ))
  49. }
  50. </view>
  51. <view className='Content'>
  52. <ScrollView scroll-x show-scrollbar={false}>
  53. {
  54. PageList.map((item, index) => (
  55. <view className='ListItem' key={`List-${index}`} style={{display: CurrentId === 1 || (CurrentId === 2 && item.kind === 'notice') || (CurrentId === 3 && item.kind === 'live') || (CurrentId === 4 && item.kind !== 'notice') ? 'inline-block' : 'none'}}>
  56. <Image mode='aspectFill' className='centerLabel' onClick={toDetail(item)} src={`${getImgURL(item.images)}`} />
  57. </view>
  58. ))
  59. }
  60. </ScrollView>
  61. </view>
  62. </view>
  63. </view>
  64. )
  65. }