questionResult.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Api from "../../model/api";
  2. import Config from "../../model/config";
  3. Page({
  4. data: {
  5. exams: [],
  6. // score: '',
  7. },
  8. async onLoad(options) {
  9. let {id, stuId, courseId} = options;
  10. let params = {
  11. questionnaireId: id,
  12. studentId: stuId,
  13. }
  14. if (courseId && courseId !== 'null') {
  15. params.courseId = courseId;
  16. }
  17. let res = await Api.getQuestionResult(params, true);
  18. // let score = res.data.fraction || 0;
  19. // let testQuestionsList = res.data.testQuestionsList;
  20. // let exams = [
  21. // ...(testQuestionsList.singleChoice || []),
  22. // ...(testQuestionsList.multipleChoice || []),
  23. // ...(testQuestionsList.qaq || []),
  24. // ];
  25. let questions = res.data;
  26. questions.forEach(question => {
  27. question.isQAQ = question.allChoose.length === 0;
  28. if (question.otherAnswerType && !question.isQAQ) {
  29. //如果不是问答题,在选项里拼 其他 选项
  30. question.allChoose.push('其他')
  31. }
  32. question.allOptions = question.allChoose.map((item, idx) => {
  33. return {
  34. opt: Config.OPT_TIP[idx],
  35. answer: item
  36. }
  37. });
  38. if (question.isQAQ) {
  39. question.myAnswer = question.yourAnswer;
  40. } else {
  41. let answerStr = question.trueIndex.map(item => {
  42. return `${Config.OPT_TIP[item]}.${question.allChoose[item]}`
  43. }).join('、');
  44. if (question.otherAnswerType && question.yourAnswer) {
  45. //如果选择的选项中包含其他
  46. let otherOption = question.allOptions[question.allOptions.length - 1];
  47. answerStr += `、${otherOption.opt}.${otherOption.answer}(${question.yourAnswer})`
  48. }
  49. question.myAnswer = answerStr;
  50. }
  51. })
  52. this.setData({
  53. questions,
  54. // score
  55. })
  56. }
  57. });