searchResult.jsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { React, useState, useRef } from 'react'
  2. // .就是当前路径
  3. import CustomNav from '@/components/CustomNav'
  4. import Taro from '@tarojs/taro'
  5. import { View } from '@tarojs/components';
  6. import { getResourceList } from '@/services/home'
  7. import { getNoteList } from '@/services/note'
  8. import MasonryLayout from '@/components/MasonryLayout';
  9. import NoData from '@/components/NoData'
  10. import List from '@/components/List';
  11. import withLayout from '@/layouts'
  12. import './searchResult.less'
  13. import Card from '../index/components/Card'
  14. import iconsearch from '../../assets/icons/housemantj/search.png'
  15. import RecommendNote from '../index/tabs/RecommendNote/index'
  16. const listStyle = { height: '100%' }
  17. export default withLayout((props) => {
  18. const { router, person, location } = props
  19. const { q, targetTypeValue } = props.router.params
  20. const [listData, setListData] = useState({ list: [], rfTimes: 0 })
  21. // 横向tab
  22. // targetType: targetTypeValue
  23. const [queryParams, setQueryParams] = useState({ q: q, location, pageNum: 1, pageSize: 10, })
  24. const rfTimes = useRef(0)
  25. const listRef = useRef()
  26. const handleDataChange = (value, e) => {
  27. if (e.paramsChanged) {
  28. rfTimes.current += 1
  29. //如果context有的话代表他滚动了 那么切换tab页就置顶
  30. if (listRef.current?.context) {
  31. listRef.current.context.scrollTo({ top: 0 })
  32. }
  33. }
  34. setListData({ list: value, rfTimes: rfTimes.current })
  35. }
  36. const onSearch = () => {
  37. // 用绝对路径
  38. Taro.navigateTo({ url: '/pages/search/search' });
  39. }
  40. return (
  41. <view className='page-index'>
  42. <view className='index-navbar'>
  43. <CustomNav title='搜索' />
  44. </view>
  45. <view className='index-container' style={{ display: 'flex', flexDirection: 'column' }}>
  46. <view className='search'>
  47. <input className='searchInput' placeholder={`搜索${targetTypeValue}`} value={q} disabled onClick={onSearch} />
  48. <image className='searchicon' src={iconsearch} />
  49. <view className='lineSearch'></view>
  50. </view>
  51. <View style={{ flex: 1, overflow: 'hidden' }}>
  52. {
  53. targetTypeValue == '地点' ?
  54. <List
  55. ref={listRef}
  56. style={listStyle}
  57. request={getResourceList}
  58. params={queryParams}
  59. refresherEnabled={false}
  60. onDataChange={handleDataChange}
  61. noData={<NoData />}
  62. >
  63. <view style={{ padding: '30rpx 15rpx' }}>
  64. <MasonryLayout
  65. itemKey='resourceNo'
  66. listData={listData}
  67. render={(item) => <Card key={item.resourceNo} item={item} />}
  68. />
  69. </view>
  70. </List>
  71. : <RecommendNote queryParamsSearch={queryParams} />
  72. }
  73. </View>
  74. </view>
  75. </view>
  76. )
  77. })