From e36d04fc335547bc293078a77924c94a31e99cdc Mon Sep 17 00:00:00 2001 From: Mr Ke <kelq@hugeinfo.com.cn> Date: Fri, 15 May 2020 16:51:54 +0800 Subject: [PATCH] 发布问卷做问卷总分值100的最大限制 --- SunshineIns/src/page/Newly.jsx | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/SunshineIns/src/page/Newly.jsx b/SunshineIns/src/page/Newly.jsx index 74d15da..a41ee53 100644 --- a/SunshineIns/src/page/Newly.jsx +++ b/SunshineIns/src/page/Newly.jsx @@ -143,7 +143,6 @@ loading: true }); Fetch.questionFindById(id).then(res => { - console.log('res', res); res.questionDtos = res.questionDtos && res.questionDtos.length ? res.questionDtos.map((item) => ({ ...item, remark: true @@ -165,12 +164,29 @@ if (!extraData.questionnairBusinessType) { return message.error('请选择业务类型'); } + let sum = questionDtos.reduce((p, n) => { + if (n.type == 'radio') { + return p.concat(Math.max.apply(null, n.scores)) + } else { + return p.concat(n.scores) + } + }, []).reduce(function (prev, curr, idx, arr) { + return Number(prev) + Number(curr); + }); + console.log('总分值', sum); + if (sum > 100) { + return message.error('分值超过最大值,请重新设定分值'); + } + questionDtos = questionDtos.map(({ type, title, required, remarkText, options, scores, warnFlag }) => ({ type, title, required, remarkText, options, scores, warnFlag })); + this.setState({ btnLoading: true }) + console.log('questionDtos', questionDtos); + Fetch.saveQuestionTemp({ ...initData, title: extraData.questionnairTitle, @@ -184,6 +200,7 @@ }) if (res.code == 0) { message.success('问卷提交成功'); + this.props.history.push('/questionnaire/newlyList'); } }) } @@ -197,13 +214,13 @@ const { data, loading, resetKey, initData, btnLoading } = this.state; const { id } = this.props.match.params; return ( - <div className="app-page"> + <div className="app-page" > <div style={{ margin: '10px 0 0 10px' }}> <Breadcrumb> <Breadcrumb.Item> - <a onClick={()=>{ + <a onClick={() => { this.props.history.goBack(); }}>问卷管理</a> </Breadcrumb.Item> @@ -214,9 +231,9 @@ </div> { loading ? - <div style={{ height: 200, width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}> + <div style={{ height: 200, width: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }} > <Spin spinning={loading} /> - </div> : + </div > : initData && <Questionnair submitQuestionTemp={this.submitQuestionTemp} btnLoading={btnLoading} initData={initData} editors={initData.questionDtos || []} /> } </div> -- Gitblit v1.8.0