index.jsx 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useState, useEffect } from 'react'
  2. import { useSelector } from 'react-redux'
  3. import Taro from '@tarojs/taro'
  4. import { queryActivityList } from '@/services/activity'
  5. import '@/assets/css/iconfont.css'
  6. import './index.scss'
  7. export default function HotRecommend (props) {
  8. const { change = () => { } } = props
  9. const city = useSelector(state => state.city)
  10. const [MenuList] = useState([{ name: '热门活动', id: 'dymic' }, { name: '热门团房', id: 'house' }])
  11. const [CurrentId, setCurrentId] = useState('dymic')
  12. const [list, setList] = useState([])
  13. const [CurrentContentInfo, setCurrentContentInfo] = useState({})
  14. useEffect(() => {
  15. if (city.curCity.name) {
  16. GetRecommendActivity()
  17. }
  18. }, [city])
  19. const GetRecommendActivity = () => {
  20. queryActivityList({ home: 1, cityId: city.curCity.id }).then((res) => {
  21. const resArr = res.records || []
  22. setList(resArr)
  23. change(!!resArr.length)
  24. })
  25. }
  26. useEffect(() => {
  27. if (list.length > 0) {
  28. setCurrentContentInfo(CurrentId === 'dymic' ? list[0] : list[1])
  29. }
  30. }, [CurrentId, list])
  31. const CutMenu = (id) => {
  32. return () => {
  33. setCurrentId(id)
  34. }
  35. }
  36. const ToMore = () => {
  37. Taro.navigateTo({ url: `/pages/index/activityList/index?type=${CurrentId}` })
  38. }
  39. const toDetail = () => {
  40. if (CurrentContentInfo.dynamicId) {
  41. Taro.navigateTo({ url: `/pages/index/activityDetail/index?id=${CurrentContentInfo.dynamicId}` })
  42. }
  43. }
  44. return (
  45. <view className='components HotRecommend'>
  46. <view>
  47. <view className='Menu flex-h'>
  48. {
  49. MenuList.map((item, index) => (
  50. <view onClick={CutMenu(item.id)} className={CurrentId === item.id ? 'active flex-item' : 'flex-item'} key={`Menu-${index}`}>{item.name}</view>
  51. ))
  52. }
  53. </view>
  54. <view className='Content' onClick={toDetail}>
  55. <view className='flex-h'>
  56. <text className='flex-item'>{CurrentContentInfo.title || '暂无活动'}</text>
  57. <text onClick={ToMore}>{CurrentId === 'dymic' ? '更多活动' : '更多团房'}</text>
  58. </view>
  59. <text>{CurrentContentInfo.halfTitle}</text>
  60. </view>
  61. </view>
  62. </view>
  63. )
  64. }