index.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { View, Image, Input, Picker, Text } from "@tarojs/components"
  2. import { useModel } from "@/store"
  3. import withLayout from '@/layouts'
  4. import { useState, useEffect } from "react"
  5. import CustomNav from "@/components/CustomNav"
  6. import searchs from '@/assets/homesImgaes/searchs.png'//搜索图片
  7. import { getMachineryType, getMachinery } from "@/services/homes"
  8. import CarTypeList from "./CarTypeList"
  9. import './style.less'
  10. export default withLayout((props) => {
  11. const [activeTab, setActiveTab] = useState(0)
  12. const { sserLocation } = useModel('userData')
  13. const [tabs, setTabs] = useState([])
  14. const [csrsListType, steCsrsListType] = useState([])
  15. const [activeNames, setActiveNames] = useState([])//全部分类
  16. const [classId, setClassId] = useState([])//分类ID
  17. const [tabIndex, steTabIndex] = useState(0)
  18. const handleSearch = (e) => {
  19. }
  20. // const ClassificationComparison = () => {
  21. // for (let item1 of tabs) {
  22. // let _index = activeNames.findIndex(c => c.name == item1.title)
  23. // if (_index > -1) {
  24. // item1.count = activeNames[_index].typeId;
  25. // console.log('saleTypes=tempSales //这', activeNames[_index].typeId);
  26. // // classId.push({ id: item1.count })
  27. // }
  28. // }
  29. // }
  30. useEffect(() => {
  31. if (tabIndex !== 0) {
  32. // ClassificationComparison()
  33. activeNames.map((item) => {
  34. classId.push({ id: item.typeId })
  35. })
  36. getMachinery(sserLocation, { typeId: classId[tabIndex - 1].id }).then((e) => {
  37. console.log('农机分类', e);
  38. steCsrsListType(e.records)
  39. })
  40. } else {
  41. // ClassificationComparison()
  42. getMachinery(sserLocation).then((e) => {
  43. steCsrsListType(e.records)
  44. })
  45. }
  46. }, [sserLocation, tabIndex])
  47. useEffect(() => {
  48. getMachineryType().then((e) => {
  49. const tabList = e.records
  50. setActiveNames(tabList)
  51. let tabss = tabList.map(x => ({ title: x.name, }))
  52. const newTabs = [{ title: '全部' }, ...tabss]
  53. setTabs(newTabs)
  54. })
  55. }, [])
  56. const handleTabChange = (e) => {
  57. console.log('e', e.detail);
  58. steTabIndex(e?.detail?.index)
  59. }
  60. return (
  61. <View className='page-index'>
  62. <View className='index-navbar'>
  63. <CustomNav title='更多' />
  64. </View>
  65. <scroll-view scrollY style='height: 100%;' >
  66. <View className='heads-content-searchClass-abcc'>
  67. <Input type='text' className='heads-content-searchClass-abcc-searchInput' onBlur={handleSearch} placeholder='搜索关键字查询订单' />
  68. <Image src={searchs} className='heads-content-searchClass-abcc-searchInput-searchImg' />
  69. </View>
  70. <mp-tabs
  71. tabClass='tabs-Unselected'
  72. swiperClass='tabs-swiper'
  73. activeClass='tabs-Selected'
  74. current={activeTab}
  75. activeTab={activeTab}
  76. tabs={tabs}
  77. onChange={handleTabChange}
  78. ></mp-tabs>
  79. {/* 内容区域 */}
  80. <View className='cententText'>
  81. <CarTypeList csrsListType={csrsListType} />
  82. </View>
  83. </scroll-view>
  84. </View>
  85. )
  86. })