searchResult.jsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { React, useState, useRef } from 'react'
  2. // .就是当前路径
  3. import iconsearch from '../../assets/icons/housemantj/search.png'
  4. import CustomNav from '@/components/CustomNav'
  5. import Taro from '@tarojs/taro'
  6. import { View } from '@tarojs/components';
  7. import Card from '../index/components/Card'
  8. import { getResourceList } from '@/services/home'
  9. import NoData from '@/components/NoData'
  10. import List from '@/components/List';
  11. import withLayout from '@/layouts'
  12. import './searchResult.less'
  13. export default withLayout((props) => {
  14. const { router, person, location } = props
  15. const { q } = props.router.params
  16. // 横向tab
  17. const [activeTab, setActiveTab] = useState(0)
  18. const [queryParams, setQueryParams] = useState({ q: q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
  19. // 获取资源表信息
  20. const [alllist, setAllList] = useState([])
  21. const tabs = [
  22. {
  23. title: '全部',
  24. },
  25. {
  26. title: '美食',
  27. },
  28. {
  29. title: '景点',
  30. },
  31. ]
  32. const listRef = useRef()
  33. const handleTabChange = (e) => {
  34. const { index } = e.detail
  35. setActiveTab(index)
  36. if (index == 0) {
  37. setQueryParams({ q: q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
  38. }
  39. else if (index == 1) {
  40. setQueryParams({ q: q, targetType: 'shop', location: location, pageNum: 1, pageSize: 10, typeId: '' })
  41. }
  42. else {
  43. setQueryParams({ q: q, targetType: 'tourist', location: location, pageNum: 1, pageSize: 10, typeId: '' })
  44. }
  45. //如果context有的话代表他滚动了 那么切换tab页就置顶
  46. if (listRef.current?.context) {
  47. listRef.current.context.scrollTo({ top: 0 })
  48. }
  49. }
  50. const onSearch = () => {
  51. // 用绝对路径
  52. Taro.navigateTo({ url: '/pages/search/search' });
  53. }
  54. return (
  55. <view className='page-index'>
  56. <view className='index-navbar'>
  57. <CustomNav title='搜索' />
  58. </view>
  59. <view className='index-container' style={{ display: 'flex', flexDirection: 'column' }}>
  60. <view className='search'>
  61. <input className='searchInput' placeholder='搜索景点/店铺' disabled onClick={onSearch} />
  62. <image className='searchicon' src={iconsearch} />
  63. <view className='lineSearch'></view>
  64. </view>
  65. <view className='index-tabs'>
  66. <mp-tabs
  67. tabClass='tabs-Unselected'
  68. swiperClass='tabs-swiper'
  69. activeClass='tabs-Selected'
  70. tabs={tabs}
  71. current={activeTab}
  72. onChange={handleTabChange}
  73. activeTab={activeTab}
  74. >
  75. </mp-tabs>
  76. </view>
  77. <View style={{ flex: 'auto', overflow: 'hidden', position: 'relative' }}>
  78. <List
  79. style={{ height: '100%' }}
  80. request={getResourceList}
  81. params={queryParams}
  82. onDataChange={setAllList}
  83. refresherEnabled={false}
  84. >
  85. {
  86. alllist.length == 0 ?
  87. <NoData /> :
  88. <view className='waterfall'>
  89. {
  90. alllist.map((item) => <Card key={item.resourceNo} item={item} />)
  91. }
  92. </view>
  93. }
  94. </List>
  95. </View>
  96. </view>
  97. </view>
  98. )
  99. })