index.jsx 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { useState, useEffect,useRef } from 'react'
  2. import Taro from '@tarojs/taro'
  3. import CustomNav from '@/components/CustomNav'
  4. import logo from '@/assets/icons/comm/logo_small.png'
  5. import withLayout from '@/layouts'
  6. import tabList from './tabbar'
  7. import Guide from './tabs/Guide'
  8. import Mine from './tabs/Mine'
  9. import Recommend from './tabs/Recommend'
  10. import './index.less'
  11. import { getLocation } from '@/utils/location'
  12. import { getIndexType, getResourceList } from '@/services/home'
  13. export default withLayout((props) => {
  14. const { router, person } = props
  15. const { params, path } = router
  16. const { tab } = params || {}
  17. const [currentTab, setCurrentTab] = useState(0)
  18. const locRef = useRef()
  19. const handleTabChange = (e) => {
  20. const { index } = e.detail
  21. setCurrentTab(index)
  22. }
  23. const [queryParams, setQueryParams] = useState({ location: '', pageNum: 1, pageSize: 10, typeId: '' })
  24. useEffect(() => {
  25. getLocation().then((res) => {
  26. locRef.current = `${res.longitude},${res.latitude}`
  27. setQueryParams({
  28. ...queryParams,
  29. location: locRef.current
  30. })
  31. })
  32. }, [])
  33. useEffect(() => {
  34. if (tab) {
  35. setCurrentTab(tab - 0)
  36. }
  37. }, [tab])
  38. return (
  39. <view className='page-index'>
  40. <view className='index-navbar'>
  41. <CustomNav logo={logo} title='十公里' />
  42. </view>
  43. <view className='index-container'>
  44. {currentTab === 0 && <Recommend loc={locRef} qp={queryParams}/>}
  45. {currentTab === 1 && <Guide person={person} router={router} />}
  46. {/* {currentTab === 2 && <Strategy />} */}
  47. {currentTab === 2 && <Mine person={person} />}
  48. </view>
  49. <view className='index-tabbar'>
  50. <mp-tabbar extClass='custom-tabbar' current={currentTab} list={tabList} onChange={handleTabChange}></mp-tabbar>
  51. </view>
  52. </view>
  53. )
  54. })