Recommend.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import Taro, { useDidShow } from '@tarojs/taro'
  2. import { React, useState, useEffect, useRef } from 'react'
  3. import { View } from '@tarojs/components';
  4. import iconsearch from '@/assets/icons/housemantj/search.png'
  5. import locationimg from '@/assets/icons/housemantj/location.png'
  6. import Tip from '@/components/tip'
  7. import List from '@/components/List';
  8. import NoData from '@/components/NoData'
  9. import SpinBox from '@/components/Spin/SpinBox';
  10. import { getIndexType, getResourceList } from '@/services/home'
  11. import Card from '../components/Card'
  12. import './less/Recommend.less'
  13. export default (props) => {
  14. const { router, person, location } = props
  15. const [activeTab, setActiveTab] = useState(0)
  16. const [typeList, setTypeList] = useState([])
  17. const listRef = useRef()
  18. const [queryParams, setQueryParams] = useState({ location: location, pageNum: 1, pageSize: 10, typeId: '' })
  19. // 获取资源表信息
  20. const [alllist, setAllList] = useState([])
  21. //分类标签
  22. const tabs = [{ title: '附近' }].concat(typeList.map(x => ({ ...x, title: x.typeName })))
  23. //切换上面的标签
  24. const handleTabChange = (e) => {
  25. const { index } = e.detail
  26. setActiveTab(index)
  27. const tab = tabs[index].typeId
  28. setQueryParams({
  29. ...queryParams,
  30. typeId: tab
  31. })
  32. if (index == 0) {
  33. setQueryParams({ location: location, pageNum: 1, pageSize: 10, typeId: '' })
  34. }
  35. //如果context有的话代表他滚动了 那么切换tab页就置顶
  36. if (listRef.current?.context) {
  37. listRef.current.context.scrollTo({ top: 0 })
  38. }
  39. }
  40. useEffect(() => {
  41. //查询分类标签表
  42. getIndexType({ pageSize: 20 }).then((res) => {
  43. setTypeList(res.records || [])
  44. })
  45. }, [])
  46. const onSearch = () => {
  47. // 用绝对路径
  48. Taro.navigateTo({ url: '/pages/search/search' });
  49. }
  50. // 联动收藏
  51. const likeLook = () => {
  52. getResourceList().then(e => {
  53. setAllList(e.records)
  54. })
  55. }
  56. useDidShow(() => {
  57. likeLook()
  58. })
  59. return (
  60. // <view style={{ height: '100%', overflow: 'hidden',display:'flex',flexDirection:'column' }}>
  61. <view style={{ height: '100%', overflow: 'hidden' }}>
  62. <view className='search' onClick={onSearch} >
  63. <input className='searchInput' disabled />
  64. <image className='searchicon' src={iconsearch} />
  65. <view className='searchword'>搜索</view>
  66. </view>
  67. <Tip />
  68. <view className='index-tabs'>
  69. <view className='position'>
  70. <image className='location' src={locationimg} />
  71. <view className='city'>南京</view>
  72. <view className='line' />
  73. </view>
  74. <scroll-view scrollX>
  75. <mp-tabs
  76. tabClass='tabs-Unselected'
  77. swiperClass='tabs-swiper'
  78. activeClass='tabs-Selected'
  79. tabs={tabs}
  80. current={activeTab}
  81. onChange={handleTabChange}
  82. activeTab={activeTab}
  83. >
  84. </mp-tabs>
  85. </scroll-view>
  86. </view>
  87. {/* <View style={{ flex:'auto' }}> */}
  88. <List
  89. ref={listRef}
  90. style={{ height: 'calc(100% - 145px)' }}
  91. // style={{ flex: 'auto', height: '100%' }}
  92. request={getResourceList}
  93. params={queryParams}
  94. onDataChange={setAllList}
  95. >
  96. {/* <MasonryLayout
  97. className='waterfall'
  98. list={alllist}
  99. render={item => <Card item={item} />}
  100. /> */}
  101. {
  102. alllist.length == 0 ?
  103. <NoData /> :
  104. <view className='waterfall'>
  105. {
  106. alllist.map((item) => <Card key={item.resourceNo} item={item} />)
  107. }
  108. </view>
  109. }
  110. </List>
  111. {/* </View> */}
  112. </view>
  113. )
  114. }