index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Taro, { useDidShow, useState, useRouter} from '@tarojs/taro'
  2. import { View, Text } from '@tarojs/components'
  3. import { AtTabs, AtTabsPane } from 'taro-ui'
  4. import { getGoods } from '@/service/cloud'
  5. import Good from '@/components/Good'
  6. import './index.scss'
  7. function Index() {
  8. const [current, setCurrent] = useState(0)
  9. const [cats, setCats] = useState()
  10. const [goods, setGoods] = useState()
  11. const router = useRouter()
  12. useDidShow(async() => {
  13. const params = router.params
  14. Taro.setNavigationBarTitle({
  15. title: params.lang
  16. })
  17. const cats = JSON.parse(params.cat)
  18. setCats(cats)
  19. reload(+params.index, cats[params.index])
  20. })
  21. const params: any = {
  22. page: 1,
  23. pageSize: 10,
  24. }
  25. const reload = async(index, cat) => {
  26. setCurrent(index)
  27. params.type = cat.title
  28. const { data, status } = await getGoods(params)
  29. if (status === 0) {
  30. setGoods(data)
  31. }
  32. }
  33. return (
  34. <View className='container'>
  35. <AtTabs
  36. current={current}
  37. scroll
  38. tabList={cats}
  39. onClick={(val) => reload(val, cats[val])}>
  40. {cats && cats.map((item, index) => (
  41. <AtTabsPane key={item.id} current={current} index={index}>
  42. {goods && goods.map(good => (
  43. <Good
  44. key={good.id}
  45. data={good} />
  46. ))}
  47. {
  48. goods && goods.length === 0 &&
  49. <View className='no-record'>
  50. <View className='bg'>
  51. <Text>该分类下还没资源哦</Text>
  52. </View>
  53. </View>
  54. }
  55. </AtTabsPane>
  56. ))}
  57. </AtTabs>
  58. </View>
  59. )
  60. }
  61. Index.config = {
  62. navigationBarTitleText: ''
  63. }
  64. export default Index