import React, { useEffect, useRef, useState } from "react"; import "./index.less"; import { Empty, Picker, Popup, Search } from 'react-vant'; import api from "~/api"; import { Link } from "react-router-dom"; import { Toast } from 'react-vant'; export const ExamRoadVideo: React.FC = (props: any) => { const [keyWord, setKeyWord] = useState(''); const [city, setCity] = useState({ city: "", cityId: "" }) const cityRef = useRef<{ city: string; cityId: string; }>() cityRef.current = city const [province, setProvince] = useState({ province: "", provinceId: "" }) const provinceRef = useRef<{ province: string; provinceId: string; }>() provinceRef.current = province const [county, setCounty] = useState({ county: "", countyId: "" }) const [provinceVisible, setProvinceVisible] = useState(false) const [cityVisible, setCityVisible] = useState(false) const [countyVisible, setCountyVisible] = useState(false) const [provinceList, setProvinceList] = useState<{ province: string, provinceId: string }[]>([]) const [cityList, setCityList] = useState<{ city: string, cityId: string }[]>([]) const [countyList, setCountyList] = useState<{ county: string, countyId: string }[]>([]) const getExamListByName = (name?: string) => { () => { setProvince({ province: "", provinceId: "" }) setCounty({ county: "", countyId: "" }) setCity({ city: "", cityId: "" }) api.studentExamInfoList({ name: name }).then(res => { console.log(res) setExamList(res.data.rows) }) } } const getCityByProvinceId = (provinceId: string) => { api.studentExamInfoCity(Number(provinceId)).then(res => { setCityList(res.data.data) }) } const getCountyByCityId = (cityId: string) => { api.studentExamInfoCounty(Number(cityId)).then(res => { setCountyList(res.data.data) }) } const [examList, setExamList] = useState<{ "id": number, "name": string, "image": string, "provinceId": string, "province": string, "cityId": string, "city": string, "countyId": string, "county": string, "price": number, "videoCount": number, "expirationTime": null, "isVip": 0, "sign": null }[]>([]) useEffect(() => { api.studentExamInfoList({ ...province, ...city, ...county }).then(res => { setExamList(res.data.rows) }) }, [province, city, county]) useEffect(() => { api.studentExamInfoList({}).then(res => { setExamList(res.data.rows) }) api.studentExamInfoGetProvice().then(res => { setProvinceList(res.data.data) //定位 api.studentExamInfoIp().then(result => { if (res.data.data.every((item: { province: string provinceId: string }) => { item.province === result.data.data.province })) { setCity({ city: result.data.data.cityName, cityId: result.data.data.city }); setProvince({ provinceId: result.data.data.province, province: result.data.data.provinceName }) } else { setCity({ city: "", cityId: "" }); setProvince({ provinceId: "", province: "" }) } console.log(result.data) }) }) }, []) return (