Recommend.jsx 2.8KB

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