index.jsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import Taro, { useDidShow } from '@tarojs/taro'
  2. import { React, useState, useEffect, useRef, useMemo } 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 MasonryLayout from '@/components/MasonryLayout';
  8. import { getIndexType, getResourceList } from '@/services/home'
  9. import { random } from '@/utils'
  10. import { getNoteList } from '@/services/note'
  11. import NoteCard from '../../components/NoteCard'
  12. const listStyle = { height: '100%' }
  13. export default (props) => {
  14. const { router, person, location, queryParamsSearch } = props
  15. const listClass = useMemo(() => random('f'), [])
  16. const [activeTab, setActiveTab] = useState(0)
  17. const listRef = useRef()
  18. const [queryParams, setQueryParams] = useState({ location, pageNum: 1, pageSize: 10, })
  19. const rfTimes = useRef(0)
  20. // 获取资源表信息
  21. const [listData, setListData] = useState({ list: [], rfTimes: 0 })
  22. //分类标签
  23. const tabs = [{ title: '地点' }, { title: '笔记' }]
  24. const details = (index, tab) => {
  25. // if (index === 1) {
  26. // getNoteList({ location: location }).then(res => {
  27. // setListData({ list: res.records })
  28. // })
  29. // }
  30. }
  31. //切换上面的标签
  32. const handleTabChange = (e) => {
  33. const { index } = e.detail
  34. setActiveTab(index)
  35. setQueryParams({ ...queryParams })
  36. details(index, tabs[index].typeId || '')
  37. }
  38. const handleDataChange = (value, e) => {
  39. if (e.paramsChanged) {
  40. rfTimes.current += 1
  41. //如果context有的话代表他滚动了 那么切换tab页就置顶
  42. if (listRef.current?.context) {
  43. listRef.current.context.scrollTo({ top: 0 })
  44. }
  45. }
  46. setListData({ list: value, rfTimes: rfTimes.current })
  47. }
  48. const onSearch = () => {
  49. // 用绝对路径
  50. Taro.navigateTo({ url: '/pages/search/search' });
  51. }
  52. return (
  53. <view style={{ height: '100%', overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>
  54. <List
  55. ref={listRef}
  56. style={listStyle}
  57. request={getNoteList}
  58. params={queryParamsSearch || queryParams}
  59. refresherEnabled={false}
  60. onDataChange={handleDataChange}
  61. >
  62. <view style={{ padding: '30rpx 15rpx' }}>
  63. <MasonryLayout
  64. itemKey='noteId'
  65. listData={listData}
  66. render={(item) => <NoteCard key={item.noteId} item={item} />}
  67. />
  68. </view>
  69. </List>
  70. </view>
  71. )
  72. }