Commit 42e6c3ba by FE

school api

parent 5ab9369e
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import classnames from 'classnames'; import classnames from 'classnames';
import { http } from '@/utils';
import { Formik, Form, Field } from 'formik'; import { Formik, Form, Field } from 'formik';
import { HeaderBar } from "@/common"; import { HeaderBar } from "@/common";
import Captcha from '@/common/Captcha' import Captcha from '@/common/Captcha'
...@@ -22,9 +23,33 @@ class StudentRoot extends PureComponent { ...@@ -22,9 +23,33 @@ class StudentRoot extends PureComponent {
disabled: false, disabled: false,
isSchool: false, isSchool: false,
isCollege: false, isCollege: false,
list: [],
schoolList: [],
collegeList: [],
}; };
} }
componentDidMount() {
this.fetchSchoolInfo();
}
fetchSchoolInfo = () => {
http.get(`${API['home']}/sys/school/list `).then(res => {
console.log(res);
const { code, data } = res.data;
if(code === 200) {
const schoolList = [];
data.forEach(item => {
schoolList.push(item.school);
});
this.setState({
list: data,
schoolList
});
}
});
}
onVerify = (err, data) => { onVerify = (err, data) => {
if (!err) { if (!err) {
this.setState({ this.setState({
...@@ -39,10 +64,20 @@ class StudentRoot extends PureComponent { ...@@ -39,10 +64,20 @@ class StudentRoot extends PureComponent {
this.setState(param); this.setState(param);
} }
changeToCollege = (school = '') => {
const { list } = this.state;
const data = list.filter(item => item['school'] === school);
if(data.length > 0) {
this.setState({
collegeList: data[0]['colleges']
});
}
}
render() { render() {
// console.log(this.props); console.log(this.state, 1);
const { country } = this.props; const { country } = this.props;
const { validate, captchaInstance, disabled, isSchool, isCollege } = this.state; const { validate, captchaInstance, isSchool, isCollege, schoolList, collegeList } = this.state;
return ( return (
<> <>
<HeaderBar title={'助学计划'} arrow={true}/> <HeaderBar title={'助学计划'} arrow={true}/>
...@@ -140,8 +175,10 @@ class StudentRoot extends PureComponent { ...@@ -140,8 +175,10 @@ class StudentRoot extends PureComponent {
key: 'isSchool', key: 'isSchool',
val: isSchool val: isSchool
}} }}
options={schoolList}
onChange={props.setFieldValue} onChange={props.setFieldValue}
selectSwitch={this.selectSwitch} selectSwitch={this.selectSwitch}
changeToCollege={this.changeToCollege}
/> />
</div> </div>
<div className="student-form__item"> <div className="student-form__item">
...@@ -153,8 +190,10 @@ class StudentRoot extends PureComponent { ...@@ -153,8 +190,10 @@ class StudentRoot extends PureComponent {
key: 'isCollege', key: 'isCollege',
val: isCollege val: isCollege
}} }}
options={collegeList}
onChange={props.setFieldValue} onChange={props.setFieldValue}
selectSwitch={this.selectSwitch} selectSwitch={this.selectSwitch}
changeToCollege={this.changeToCollege}
/> />
</div> </div>
<div className="student-form__item"> <div className="student-form__item">
...@@ -182,13 +221,15 @@ class StudentRoot extends PureComponent { ...@@ -182,13 +221,15 @@ class StudentRoot extends PureComponent {
} }
const StudentSelect = (props) => { const StudentSelect = (props) => {
console.log(props);
const { const {
options = [1,2,3,4], options = [],
data: { key = '' , val = false }, data: { key = '' , val = false },
name, name,
value, value,
onChange, onChange,
selectSwitch selectSwitch,
changeToCollege
} = props; } = props;
return ( return (
<div className="student-select"> <div className="student-select">
...@@ -214,6 +255,10 @@ const StudentSelect = (props) => { ...@@ -214,6 +255,10 @@ const StudentSelect = (props) => {
onClick={() => { onClick={() => {
selectSwitch(key, false); selectSwitch(key, false);
onChange(name, item); onChange(name, item);
if(name === 'school') {
onChange('college', '');
}
changeToCollege(item);
}} }}
>{item}</li> >{item}</li>
)) ))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment