import { View, Image, Input, Picker, Text } from "@tarojs/components" import { useModel } from "@/store" import withLayout from '@/layouts' import { useState, useEffect } from "react" import CustomNav from "@/components/CustomNav" import searchs from '@/assets/homesImgaes/searchs.png'//搜索图片 import { getMachineryType, getMachinery } from "@/services/homes" import CarTypeList from "./CarTypeList" import './style.less' export default withLayout((props) => { const [activeTab, setActiveTab] = useState(0) const { sserLocation } = useModel('userData') const [tabs, setTabs] = useState([]) const [csrsListType, steCsrsListType] = useState([]) const [activeNames, setActiveNames] = useState([])//全部分类 const [classId, setClassId] = useState([])//分类ID const [tabIndex, steTabIndex] = useState(0) const handleSearch = (e) => { } // const ClassificationComparison = () => { // for (let item1 of tabs) { // let _index = activeNames.findIndex(c => c.name == item1.title) // if (_index > -1) { // item1.count = activeNames[_index].typeId; // console.log('saleTypes=tempSales //这', activeNames[_index].typeId); // // classId.push({ id: item1.count }) // } // } // } useEffect(() => { if (tabIndex !== 0) { // ClassificationComparison() activeNames.map((item) => { classId.push({ id: item.typeId }) }) getMachinery(sserLocation, { typeId: classId[tabIndex - 1].id }).then((e) => { console.log('农机分类', e); steCsrsListType(e.records) }) } else { // ClassificationComparison() getMachinery(sserLocation).then((e) => { steCsrsListType(e.records) }) } }, [sserLocation, tabIndex]) useEffect(() => { getMachineryType().then((e) => { const tabList = e.records setActiveNames(tabList) let tabss = tabList.map(x => ({ title: x.name, })) const newTabs = [{ title: '全部' }, ...tabss] setTabs(newTabs) }) }, []) const handleTabChange = (e) => { console.log('e', e.detail); steTabIndex(e?.detail?.index) } return ( {/* 内容区域 */} ) })