Recommend.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Taro, { useRouter } from '@tarojs/taro'
  2. import { React, useState, useEffect, useRef } from 'react'
  3. import iconsearch from '@/assets/icons/housemantj/search.png'
  4. import locationimg from '@/assets/icons/housemantj/location.png'
  5. import Tip from '@/components/tip'
  6. import { getIndexType, getResourceList } from '@/services/home'
  7. import Card from '../components/Card'
  8. import { getLocation } from '@/utils/location'
  9. import './less/Recommend.less'
  10. export default (props) => {
  11. const { router, person, location } = props
  12. const [activeTab, setActiveTab] = useState(0)
  13. const { params } = useRouter()
  14. const { tabJump } = params || {}
  15. const [typeList, setTypeList] = useState([])
  16. const [queryParams, setQueryParams] = useState({ location: location, pageNum: 1, pageSize: 10, typeId: '' })
  17. // 获取资源表信息
  18. const [alllist, setAllList] = useState([])
  19. //分类标签
  20. const tabs = [{ title: '附近' }].concat(typeList.map(x => ({ ...x, title: x.typeName })))
  21. //切换上面的标签
  22. const handleTabChange = (e) => {
  23. const { index } = e.detail
  24. setActiveTab(index)
  25. const tab = tabs[index].typeId
  26. setQueryParams({
  27. ...queryParams,
  28. typeId: tab
  29. })
  30. if (index == 0) {
  31. setQueryParams({ location: location, pageNum: 1, pageSize: 10, typeId: '' })
  32. }
  33. }
  34. useEffect(() => {
  35. //查询分类标签表
  36. getIndexType({ pageSize: 20 }).then((res) => {
  37. setTypeList(res.records || [])
  38. })
  39. }, [])
  40. useEffect(() => {
  41. getResourceList(queryParams).then((res) => {
  42. setAllList(res.records || [])
  43. })
  44. }, [queryParams])
  45. const onSearch = () => {
  46. // 用绝对路径
  47. Taro.navigateTo({ url: '/pages/search/search' });
  48. }
  49. return (
  50. <view style={{ height: '100%', overflow: 'auto' }}>
  51. <view className='search' onClick={onSearch}>
  52. <input className='searchInput' disabled />
  53. <image className='searchicon' src={iconsearch} />
  54. <view className='searchword'>搜索</view>
  55. </view>
  56. <Tip />
  57. <view className='index-tabs'>
  58. <view className='position'>
  59. <image className='location' src={locationimg} />
  60. <view className='city'>南京</view>
  61. <view className='line' />
  62. </view>
  63. <scroll-view scroll-x='true' scroll-view='true' bindscrolltoupper='upper' bindscrolltolower='lower' bindscroll='scroll'>
  64. <mp-tabs
  65. tabClass='tabs-Unselected'
  66. swiperClass='tabs-swiper'
  67. activeClass='tabs-Selected'
  68. tabs={tabs}
  69. current={activeTab}
  70. onChange={handleTabChange}
  71. activeTab={activeTab}
  72. >
  73. </mp-tabs>
  74. </scroll-view>
  75. </view>
  76. <scroll-view scroll-y='true' scroll-view='true' bindscrolltolower='lower' bindscrolltoupper='upper' bindscroll='scroll'
  77. >
  78. <view className='waterfall'>
  79. {
  80. alllist.map((item) => <Card key={item.resourceNo} item={item} />)
  81. }
  82. </view>
  83. <view className='botton'>已经到底了~</view>
  84. </scroll-view>
  85. </view>
  86. )
  87. }