提交 fe3bc0de authored 作者: 周盛's avatar 周盛

4185 筛选条件选中问题 班级支持多选

上级 9fe3943a
...@@ -21,6 +21,7 @@ export default class Filter extends React.Component{ ...@@ -21,6 +21,7 @@ export default class Filter extends React.Component{
this.state ={ this.state ={
inputValue:'', inputValue:'',
formValues: { formValues: {
clazzIds: [],
}, },
options: { options: {
gradeList:[], gradeList:[],
...@@ -78,24 +79,36 @@ export default class Filter extends React.Component{ ...@@ -78,24 +79,36 @@ export default class Filter extends React.Component{
} }
formChange = (key,value) => { formChange = (key,value) => {
const { formValues } = this.state; let { formValues } = this.state;
formValues[key] = value; // 判断是否第二次取消
if(key === 'clazzIds') {
if(formValues[key].indexOf(value) !== -1){
formValues[key] = formValues[key].filter(i=> i!==value);
}
else{
formValues[key].push(value);
}
}
else{
if(formValues[key] === value) delete formValues[key];
else formValues[key]= value;
}
if(key === 'gradeId') { if(key === 'gradeId') {
delete formValues.institutionId; delete formValues.institutionId;
delete formValues.majorId; delete formValues.majorId
delete formValues.clazzId; formValues.clazzIds=[];
} }
if(key === 'institutionId') { if(key === 'institutionId') {
this.fetchMajorList({institutionId:value}); this.fetchMajorList({institutionId:value});
delete formValues.majorId; delete formValues.majorId
delete formValues.clazzId; formValues.clazzIds = [];
} }
if(key === 'majorId') { if(key === 'majorId') {
this.fetchClazzList({institutionId: formValues.institutionId, majorId: value,gradeId: formValues.gradeId}); this.fetchClazzList({institutionId: formValues.institutionId, majorId: value,gradeId: formValues.gradeId});
delete formValues.clazzId; formValues.clazzIds = [];
} }
this.setState({ this.setState({
...@@ -123,10 +136,20 @@ export default class Filter extends React.Component{ ...@@ -123,10 +136,20 @@ export default class Filter extends React.Component{
generateItem = (keyName,dataList) => { generateItem = (keyName,dataList) => {
const { formValues } = this.state; const { formValues } = this.state;
// 判断类名
const isSelect =(value) => {
if(keyName === 'clazzIds') {
if(formValues[keyName].indexOf(value) !== -1) return true;
}
else if(formValues[keyName] === value){
return true;
}
return false;
}
return ( return (
<div className='optionsBox'> <div className='optionsBox'>
{dataList.map(i=> ( {dataList.map(i=> (
<div className={formValues[keyName] === i.value ? 'cusLabelFocus' : 'cusLabel'} <div className={isSelect(i.value)? 'cusLabelFocus' : 'cusLabel'}
key={i.value} key={i.value}
onTouchStart={() => this.formChange(keyName,i.value)} >{i.key}</div>)) onTouchStart={() => this.formChange(keyName,i.value)} >{i.key}</div>))
} }
...@@ -136,13 +159,16 @@ export default class Filter extends React.Component{ ...@@ -136,13 +159,16 @@ export default class Filter extends React.Component{
search = () =>{ search = () =>{
const { formValues } = this.state; const { formValues } = this.state;
this.props.getPage(formValues); const clazzIds = formValues.clazzIds.join(',');
this.props.getPage({...formValues,clazzIds});
this.props.Toggle && this.props.Toggle(); this.props.Toggle && this.props.Toggle();
} }
reset =() => { reset =() => {
this.setState({ this.setState({
formValues: {} formValues: {
clazzIds: [],
}
}) })
} }
render(){ render(){
...@@ -169,8 +195,8 @@ export default class Filter extends React.Component{ ...@@ -169,8 +195,8 @@ export default class Filter extends React.Component{
{this.generateItem('institutionId',institutionList)}</>) : null} {this.generateItem('institutionId',institutionList)}</>) : null}
{ institutionId ? (<><p style={{color: '#666666'}}>专业选择</p> { institutionId ? (<><p style={{color: '#666666'}}>专业选择</p>
{this.generateItem('majorId',majorList)}</>) : null} {this.generateItem('majorId',majorList)}</>) : null}
{ majorId ? <><p style={{color: '#666666'}}>班级选择</p> { majorId? <><p style={{color: '#666666'}}>班级选择</p>
{this.generateItem('clazzId',clazzList)}</> : null } {this.generateItem('clazzIds',clazzList)}</> : null }
</WingBlank> </WingBlank>
</div> </div>
<div className='buttonBox'> <div className='buttonBox'>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论