index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import React, { useEffect, useRef, useState } from "react";
  2. import "./index.less";
  3. import { Empty, Picker, Popup, Search } from 'react-vant';
  4. import api from "~/api";
  5. import { Link } from "react-router-dom";
  6. import { Toast } from 'react-vant';
  7. export const ExamRoadVideo: React.FC = (props: any) => {
  8. const [keyWord, setKeyWord] = useState('');
  9. const [city, setCity] = useState({
  10. city: "",
  11. cityId: ""
  12. })
  13. const cityRef = useRef<{
  14. city: string;
  15. cityId: string;
  16. }>()
  17. cityRef.current = city
  18. const [province, setProvince] = useState({
  19. province: "",
  20. provinceId: ""
  21. })
  22. const provinceRef = useRef<{
  23. province: string;
  24. provinceId: string;
  25. }>()
  26. provinceRef.current = province
  27. const [county, setCounty] = useState({
  28. county: "",
  29. countyId: ""
  30. })
  31. const [provinceVisible, setProvinceVisible] = useState(false)
  32. const [cityVisible, setCityVisible] = useState(false)
  33. const [countyVisible, setCountyVisible] = useState(false)
  34. const [provinceList, setProvinceList] = useState<{
  35. province: string,
  36. provinceId: string
  37. }[]>([])
  38. const [cityList, setCityList] = useState<{
  39. city: string,
  40. cityId: string
  41. }[]>([])
  42. const [countyList, setCountyList] = useState<{
  43. county: string,
  44. countyId: string
  45. }[]>([])
  46. const getExamListByName = (name?: string) => {
  47. () => {
  48. setProvince({
  49. province: "",
  50. provinceId: ""
  51. })
  52. setCounty({
  53. county: "",
  54. countyId: ""
  55. })
  56. setCity({
  57. city: "",
  58. cityId: ""
  59. })
  60. api.studentExamInfoList({
  61. name: name
  62. }).then(res => {
  63. console.log(res)
  64. setExamList(res.data.rows)
  65. })
  66. }
  67. }
  68. const getCityByProvinceId = (provinceId: string) => {
  69. api.studentExamInfoCity(Number(provinceId)).then(res => {
  70. setCityList(res.data.data)
  71. })
  72. }
  73. const getCountyByCityId = (cityId: string) => {
  74. api.studentExamInfoCounty(Number(cityId)).then(res => {
  75. setCountyList(res.data.data)
  76. })
  77. }
  78. const [examList, setExamList] = useState<{
  79. "id": number,
  80. "name": string,
  81. "image": string,
  82. "provinceId": string,
  83. "province": string,
  84. "cityId": string,
  85. "city": string,
  86. "countyId": string,
  87. "county": string,
  88. "price": number,
  89. "videoCount": number,
  90. "expirationTime": null,
  91. "isVip": 0,
  92. "sign": null
  93. }[]>([])
  94. useEffect(() => {
  95. api.studentExamInfoList({
  96. ...province,
  97. ...city,
  98. ...county
  99. }).then(res => {
  100. setExamList(res.data.rows)
  101. })
  102. }, [province, city, county])
  103. useEffect(() => {
  104. api.studentExamInfoList({}).then(res => {
  105. setExamList(res.data.rows)
  106. })
  107. api.studentExamInfoGetProvice().then(res => {
  108. setProvinceList(res.data.data)
  109. //定位
  110. api.studentExamInfoIp().then(result => {
  111. if (res.data.data.every((item: {
  112. province: string
  113. provinceId: string
  114. }) => {
  115. item.province === result.data.data.province
  116. })) {
  117. setCity({
  118. city: result.data.data.cityName,
  119. cityId: result.data.data.city
  120. });
  121. setProvince({
  122. provinceId: result.data.data.province,
  123. province: result.data.data.provinceName
  124. })
  125. }
  126. else {
  127. setCity({
  128. city: "",
  129. cityId: ""
  130. });
  131. setProvince({
  132. provinceId: "",
  133. province: ""
  134. })
  135. }
  136. console.log(result.data)
  137. })
  138. })
  139. }, [])
  140. return (
  141. <div className="ExamRoadVideo">
  142. <div className="header">
  143. <div className="rect">
  144. <div className="search">
  145. {/* <SearchOutline className="icon1" color="#8A9099" fontSize={18} /> */}
  146. <Search onChange={val => {
  147. setKeyWord(val)
  148. }} onSearch={(val) => {
  149. getExamListByName(val)
  150. }} value={keyWord} shape="round" background="transparent" placeholder="请输入搜索关键词"></Search>
  151. {/* <input placeholder="输入系列课标题" className="bar" type="search"></input> */}
  152. </div>
  153. <div
  154. className="select"
  155. >
  156. <input
  157. value={province.province}
  158. readOnly
  159. onClick={() => { setProvinceVisible(true) }}
  160. placeholder="省份"
  161. className="header-province"
  162. type="text"
  163. />
  164. <input
  165. readOnly
  166. value={city.city}
  167. onClick={() => {
  168. province.provinceId ? setCityVisible(true) : Toast.fail({
  169. message: "请先选择省份"
  170. })
  171. }}
  172. placeholder="地市"
  173. className="header-city"
  174. type="text"
  175. />
  176. <input
  177. readOnly
  178. onClick={() => {
  179. city.cityId ? setCountyVisible(true) : Toast.fail({
  180. message: "请先选择城市"
  181. })
  182. }}
  183. value={county.county}
  184. placeholder="区"
  185. className="header-area"
  186. type="text"
  187. />
  188. </div>
  189. <Popup position="bottom" visible={provinceVisible}>
  190. <Picker columnsFieldNames={{
  191. text: 'province',
  192. value: 'provinceId'
  193. }} onCancel={() => setProvinceVisible(false)} onConfirm={(val: string, item: {
  194. province: string,
  195. provinceId: string
  196. }) => { setProvince(item || { province: '', provinceId: '' }); setProvinceVisible(false); getCityByProvinceId(item?.provinceId); }} columns={provinceList}></Picker>
  197. </Popup>
  198. <Popup position="bottom" visible={cityVisible}>
  199. <Picker columnsFieldNames={{
  200. text: 'city',
  201. value: 'cityId'
  202. }} columns={cityList} onConfirm={(val: string, item: {
  203. city: string,
  204. cityId: string
  205. }) => {
  206. setCity(item || { city: '', cityId: '' }); setCityVisible(false);
  207. getCountyByCityId(item.cityId || '0000');
  208. }} onCancel={() => { setCityVisible(false); }}></Picker>
  209. </Popup>
  210. <Popup position="bottom" visible={countyVisible}>
  211. <Picker onCancel={() => {
  212. setCountyVisible(false)
  213. }} onConfirm={(value: string, item: {
  214. county: string;
  215. countyId: string;
  216. }) => {
  217. setCounty(item || { county: '', countyId: '' })
  218. setCountyVisible(false)
  219. }} columns={countyList} columnsFieldNames={{
  220. text: "county",
  221. value: "countyId"
  222. }}></Picker>
  223. </Popup>
  224. </div>
  225. </div>
  226. <div className="content">
  227. <div className="list">
  228. {/* <van-empty
  229. v-if="examRoomList.length == 0"
  230. className="custom-image"
  231. image="https://img.yzcdn.cn/vant/custom-empty-image.png"
  232. description="该城市无视频"
  233. /> */}
  234. {
  235. examList.length !== 0 ?
  236. examList.map(item => {
  237. return (<Link key={item.id} to={'/courseCatalog?id=' + item.id + '&price=' + (Number(item.price) / 100)}><div
  238. key={item.id}
  239. className="list-item"
  240. >
  241. <img src={item.image} className="list-item-image">
  242. </img>
  243. <div
  244. className="list-item-textbody"
  245. >
  246. <div className="list-item-text1">{item.name}</div>
  247. <div className="list-item-text2">共{item.videoCount}节</div>
  248. </div>
  249. <div className="list-item-border"></div>
  250. </div> </Link>)
  251. }) : <Empty
  252. className="custom-image"
  253. image="https://img.yzcdn.cn/vant/custom-empty-image.png"
  254. description="无视频"
  255. />
  256. }
  257. </div>
  258. </div>
  259. </div>
  260. );
  261. };