Commit 42e6c3ba by FE

school api

parent 5ab9369e
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import classnames from 'classnames';
import { http } from '@/utils';
import { Formik, Form, Field } from 'formik';
import { HeaderBar } from "@/common";
import Captcha from '@/common/Captcha'
......@@ -22,9 +23,33 @@ class StudentRoot extends PureComponent {
disabled: false,
isSchool: 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) => {
if (!err) {
this.setState({
......@@ -39,10 +64,20 @@ class StudentRoot extends PureComponent {
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() {
// console.log(this.props);
console.log(this.state, 1);
const { country } = this.props;
const { validate, captchaInstance, disabled, isSchool, isCollege } = this.state;
const { validate, captchaInstance, isSchool, isCollege, schoolList, collegeList } = this.state;
return (
<>
<HeaderBar title={'助学计划'} arrow={true}/>
......@@ -140,8 +175,10 @@ class StudentRoot extends PureComponent {
key: 'isSchool',
val: isSchool
}}
options={schoolList}
onChange={props.setFieldValue}
selectSwitch={this.selectSwitch}
changeToCollege={this.changeToCollege}
/>
</div>
<div className="student-form__item">
......@@ -153,8 +190,10 @@ class StudentRoot extends PureComponent {
key: 'isCollege',
val: isCollege
}}
options={collegeList}
onChange={props.setFieldValue}
selectSwitch={this.selectSwitch}
changeToCollege={this.changeToCollege}
/>
</div>
<div className="student-form__item">
......@@ -182,13 +221,15 @@ class StudentRoot extends PureComponent {
}
const StudentSelect = (props) => {
console.log(props);
const {
options = [1,2,3,4],
options = [],
data: { key = '' , val = false },
name,
value,
onChange,
selectSwitch
selectSwitch,
changeToCollege
} = props;
return (
<div className="student-select">
......@@ -214,6 +255,10 @@ const StudentSelect = (props) => {
onClick={() => {
selectSwitch(key, false);
onChange(name, item);
if(name === 'school') {
onChange('college', '');
}
changeToCollege(item);
}}
>{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