人数判断

topic_bank
hjm 6 years ago
parent c47a11bd37
commit 2bc77bad5d

@ -110,6 +110,19 @@ class NewWorkForm extends Component{
{/* min={has_commit ? init_max_num : (min_num == undefined ? 2 : min_num + 1) } */} {/* min={has_commit ? init_max_num : (min_num == undefined ? 2 : min_num + 1) } */}
// 已有提交作品,人数范围只能扩大 // 已有提交作品,人数范围只能扩大
const { has_commit, max_num, init_max_num, min_num, init_min_num } = this.state; const { has_commit, max_num, init_max_num, min_num, init_min_num } = this.state;
if (!min_num) {
this.props.showNotification('最小人数不能为空');
return;
} else if (min_num < 1) {
this.props.showNotification('最小人数不能小于1');
return;
} else if (!max_num) {
this.props.showNotification('最大人数不能为空');
return;
} else if (max_num < min_num) {
this.props.showNotification('最大人数不能小于最小人数');
return;
}
if (has_commit) { if (has_commit) {
if (max_num < init_max_num || min_num > init_min_num) { if (max_num < init_max_num || min_num > init_min_num) {
this.props.showNotification(`已有提交作品,人数范围只能扩大(原设置为:${init_min_num} - ${init_max_num})`) this.props.showNotification(`已有提交作品,人数范围只能扩大(原设置为:${init_min_num} - ${init_max_num})`)
@ -237,9 +250,9 @@ class NewWorkForm extends Component{
} }
max_num_change = (val) => { max_num_change = (val) => {
if (val < 2) { if (val < 2) {
this.setState({ // this.setState({
max_num: 2, // max_num: 2,
}) // })
return; return;
} }
const { min_num } = this.state; const { min_num } = this.state;
@ -248,12 +261,31 @@ class NewWorkForm extends Component{
min_num: val <= min_num ? val - 1 : min_num min_num: val <= min_num ? val - 1 : min_num
}) })
} }
personNumValidator = (rule, value, callback) => {
const { min_num, max_num } = this.state;
const form = this.props.form;
if (!min_num) {
callback('最小人数不能为空');
} else if (min_num < 1) {
callback('最小人数不能小于1');
} else if (!max_num) {
callback('最大人数不能为空');
} else if (max_num < min_num) {
callback('最大人数不能小于最小人数');
} else {
callback();
}
}
min_num_change = (val) => { min_num_change = (val) => {
this.setState({ min_num: val }) this.setState({ min_num: val })
} }
base_on_project_change = () => { base_on_project_change = () => {
this.setState({ base_on_project: !this.state.base_on_project }) this.setState({ base_on_project: !this.state.base_on_project })
} }
componentDidMount() {
window.$('.groupSetting .ant-form-item-label > label').addClass('ant-form-item-required')
}
render(){ render(){
let {typeId,coursesId,pageType}=this.props.match.params; let {typeId,coursesId,pageType}=this.props.match.params;
const { getFieldDecorator } = this.props.form; const { getFieldDecorator } = this.props.form;
@ -411,11 +443,13 @@ class NewWorkForm extends Component{
{ isGroup && { isGroup &&
<Form.Item <Form.Item
label="分组设置" label="分组设置"
className="AboutInputForm" className="AboutInputForm groupSetting"
> >
{getFieldDecorator('personNum', { {getFieldDecorator('personNum', {
rules: [{ rules: [{
required: false // required: true,
// message: '人数不能为空'
// validator: this.personNumValidator
// required: true, message: '请输入最小人数和最大人数' // required: true, message: '请输入最小人数和最大人数'
}], }],
})( })(
@ -447,6 +481,7 @@ class NewWorkForm extends Component{
</p> </p>
</div> </div>
)} )}
</Form.Item> </Form.Item>
} }
<div className="edu-back-white"> <div className="edu-back-white">

Loading…
Cancel
Save