function GetWorkOrderSurveyResult() { $('#divtemplate').empty(); showmaskbg(true); worequest("GetWorkOrderSurveyResult", surveyid, function (data) { $('#divtemplate').empty(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_WOS_ERROR", 'Error')); } else { surveydata = data.SurveyData; vm.reload(data); createTemplate(data.SurveyData); } showmaskbg(false); }, function (err) { showmaskbg(false); }); } function createTemplate(survey) { var template = survey.Question.Questions; var tempcontent = $('<div></div>'); var content = $('<div style="padding:0px;"></div>'); var divpage = $('<div class="page"></div>'); content.append(divpage); tempcontent.append(content); var questioncontent = createQuestionContent(template); content.append(questioncontent); $('#divtemplate').append(tempcontent); } function createQuestionContent(template) { var content = $('<div style="margin-bottom:30px;"></div>'); if (template.Questions && template.Questions.length > 0) { for (var i = 0; i < template.Questions.length; i++) { var q = template.Questions[i]; var div_question = $('<div class="question"></div>'); content.append(div_question); var div_title = $('<div style="flex-grow:1;"></div>'); if (i != 0) { div_title.css('margin-top', 20); } var span_name = $('<span></span>').text(q.Title); var span_title = $('<span class="question-tips"></span>').text(q.TitleTips); div_title.append(span_name).append(span_title) div_question.append(div_title); createAnswerContent(content, q); } } return content; } function createAnswerContent(p, q) { if (surveydata && surveydata.Result) { for (var i = 0; i < surveydata.Result.length; i++) { var a = surveydata.Result[i]; if (a.QuestionId.toLowerCase() == q.Id.toLowerCase()) { if (q.QuestionType == 2) { if (q.MultipleSelect) { if (a.Values && a.Values.length > 0) { for (var j = 0; j < a.Values.length; j++) { var item = $('<div class="answer"></div>'); var label = $('<label style="margin-left:5px;"></lable>').text("" + (j + 1) + ". " + a.Values[j].Value); item.append(label); p.append(item).append("<div style='clear:both;'></div>"); } } } else { if (a.Values && a.Values.length > 0) { var item = $('<div class="answer" ></div>'); var label = $('<label style="margin-left:5px;"></lable>').text(a.Values[0].Value); item.append(label); p.append(item).append("<div style='clear:both;'></div>"); } } } else { if (a.Values && a.Values.length > 0) { var item = $('<div class="answer" ></div>'); var div = $('<div style="margin-left:5px;"></div>').html(replaceHtmlText(a.Values[0].Value)); item.append(div); p.append(item).append("<div style='clear:both;'></div>"); } } return; } } } p.append($('<div class="noneanswer"></div>').text(GetTextByKey('P_WOS_NONE', '(None)'))); }