From 353e821ff6086028f252bb6e6378df71bcb33ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Fri, 30 Aug 2019 20:56:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/courses/poll/PollNew.js | 77 +++++++++++-------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/public/react/src/modules/courses/poll/PollNew.js b/public/react/src/modules/courses/poll/PollNew.js index a7e648ab0..56669007c 100644 --- a/public/react/src/modules/courses/poll/PollNew.js +++ b/public/react/src/modules/courses/poll/PollNew.js @@ -975,7 +975,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); @@ -1040,7 +1040,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex,object.question.answers.length); //插入多选题 // if (object.question.max_choices > arrc.length) { // // console.log("选择题的最大可选项不能大于选项数") @@ -1110,7 +1110,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); } @@ -1173,11 +1173,11 @@ class PollNew extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 1, arrc, null, 0, 0); + this.edittotheserver(object, 1, arrc, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("他原来的删除掉了") - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id,0); newarrpoll.push(question); } newarr[indexo].question.new = "new" @@ -1252,11 +1252,11 @@ class PollNew extends Component { // } if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices,object.question.answers.length); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id,object.question.answers.length); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1298,11 +1298,11 @@ class PollNew extends Component { if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 3, null, null, 0, 0); + this.edittotheserver(object, 3, null, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1470,7 +1470,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex,0); newarrpoll.splice(thiss.state.Insertposition, 0, question); } else if (object.question.question_type === 2) { //插入多选题 @@ -1533,7 +1533,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex,object.question.answers.length); //插入多选题 // if (object.question.max_choices > arrc.length) { @@ -1581,7 +1581,7 @@ class PollNew extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); } @@ -1642,11 +1642,11 @@ class PollNew extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 1, arrc, null, 0, 0); + this.edittotheserver(object, 1, arrc, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1707,11 +1707,11 @@ class PollNew extends Component { //插入多选题 if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices,object.question.answers.length); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id,object.question.answers.length); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1752,11 +1752,11 @@ class PollNew extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 3, null, null, 0, 0); + this.edittotheserver(object, 3, null, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1792,7 +1792,8 @@ class PollNew extends Component { ////新增到服务器中 - createquestionsandanswers = (object, number, option, other, max_choices, min_choices, insert_id) => { + createquestionsandanswers = (object, number, option, other, max_choices, min_choices, insert_id,length) => { + var thiss = this; var poll_id = this.state.pollid; var urlly = `/polls/${poll_id}/poll_questions.json` @@ -1805,13 +1806,16 @@ class PollNew extends Component { max_choicess = max_choices; min_choicess = min_choices; } - + console.log("createquestionsandanswers"); + console.log(max_choicess); + console.log(min_choicess); + console.log(length); axios.post(urlly, { question_title: object.question.question_title, question_type: number, is_necessary: object.question.is_necessary, - max_choices: max_choicess===undefined?null:max_choicess===null?null:max_choicess===0?null:max_choicess, - min_choices: min_choicess===undefined?null:min_choicess===null?null:min_choicess===0?null:min_choicess, + max_choices: max_choicess===undefined?length:max_choicess===null?length:max_choicess===0?length:max_choicess, + min_choices: min_choicess===undefined?2:min_choicess===null?2:min_choicess===0?2:min_choicess, question_answers: option, question_other_answer: null, insert_id: insert_id @@ -1842,17 +1846,30 @@ class PollNew extends Component { } ///编辑修改到服务器当中 - edittotheserver = (object, number, option, other, max_choices, min_choices) => { + edittotheserver = (object, number, option, other, max_choices, min_choices,length) => { // console.log("调用了edittotheserver") var url = `/poll_questions/${object.question.id}.json` var thiss = this; + var max_choicess = null; + var min_choicess = null; + if (max_choices === 0 && min_choices === 0) { + max_choicess = null; + min_choicess = null; + } else { + max_choicess = max_choices; + min_choicess = min_choices; + } + console.log("createquestionsandanswers"); + console.log(max_choicess); + console.log(min_choicess); + console.log(length); axios.put(url, { // debug: true, question_title: object.question.question_title, question_type: number, is_necessary: object.question.is_necessary, - max_choices: max_choices, - min_choices: min_choices, + max_choices: max_choicess===undefined?length:max_choicess===null?length:max_choicess===0?length:max_choicess, + min_choices: min_choicess===undefined?2:min_choicess===null?2:min_choicess===0?2:min_choicess, question_answers: option, question_other_answer: null, }).then((result) => { @@ -2164,11 +2181,11 @@ class PollNew extends Component { //最小值 HandleGradationGroupChangee = (value, index, max, length) => { - console.log("最小值"); - console.log(value); - console.log(index); - console.log(max); - console.log(length); + // console.log("最小值"); + // console.log(value); + // console.log(index); + // console.log(max); + // console.log(length); // debugger var minbool = false;