searchResult.jsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { React, useState, useEffect, } 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 Card from '../index/components/Card'
  7. import { getResourceList } from '@/services/home'
  8. import List from '@/components/List';
  9. import './searchResult.less'
  10. import withLayout from '@/layouts'
  11. export default withLayout((props) => {
  12. const { router, person, location } = props
  13. const { q } = props.router.params
  14. // 横向tab
  15. const [activeTab, setActiveTab] = useState(0)
  16. const [queryParams, setQueryParams] = useState({ q: q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
  17. // 获取资源表信息
  18. const [alllist, setAllList] = useState([])
  19. const tabs = [
  20. {
  21. title: '全部',
  22. },
  23. {
  24. title: '美食',
  25. },
  26. {
  27. title: '景点',
  28. },
  29. ]
  30. const handleTabChange = (e) => {
  31. const { index } = e.detail
  32. setActiveTab(index)
  33. if (index == 0) {
  34. setQueryParams({ q: q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
  35. }
  36. else if (index == 1) {
  37. setQueryParams({ q: q, targetType: 'shop', location: location, pageNum: 1, pageSize: 10, typeId: '' })
  38. }
  39. else {
  40. setQueryParams({ q: q, targetType: 'tourist', location: location, pageNum: 1, pageSize: 10, typeId: '' })
  41. }
  42. }
  43. const onSearch = () => {
  44. // 用绝对路径
  45. Taro.navigateTo({ url: '/pages/search/search' });
  46. }
  47. return (
  48. <view className='page-index'>
  49. <view className='index-navbar'>
  50. <CustomNav title='搜索' />
  51. </view>
  52. <view className='index-container'>
  53. <view className='search'>
  54. <input className='searchInput' placeholder='请输入景区/城市搜索' disabled onClick={onSearch} />
  55. <image className='searchicon' src={iconsearch} />
  56. <view className='lineSearch'></view>
  57. </view><view className='index-tabs'>
  58. <mp-tabs
  59. tabClass='tabs-Unselected'
  60. swiperClass='tabs-swiper'
  61. activeClass='tabs-Selected'
  62. tabs={tabs}
  63. current={activeTab}
  64. onChange={handleTabChange}
  65. activeTab={activeTab}
  66. >
  67. </mp-tabs>
  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. </view>
  83. )
  84. })