testing.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var util = require("../../utils/util.js")
  2. const app = getApp()
  3. Page({
  4. data: {
  5. testLists: [],
  6. answers: [],
  7. answersBoxs: [],
  8. testFinish: '',
  9. core_id: ''
  10. },
  11. onLoad: function(options) {
  12. if (options.testFinish == '未完成') {
  13. this.setData({
  14. testFinish: '未完成'
  15. })
  16. }
  17. this.setData({
  18. navH: app.globalData.navHeight,
  19. core_id: options.core_id
  20. })
  21. this.init(options.core_id);
  22. },
  23. init(testid) {
  24. const that = this
  25. util.postData('/college/queryTests', {
  26. openid: app.globalData.openid,
  27. core_id: testid
  28. })
  29. .then(res => {
  30. this.setData({
  31. testLists: res,
  32. })
  33. })
  34. .catch(err => {
  35. console.log(err);
  36. })
  37. },
  38. // 选择题选择
  39. _selectItem: function(e) {
  40. let index = e.currentTarget.dataset.index;
  41. let subid = e.currentTarget.dataset.subid;
  42. this.editQuestion(index, subid);
  43. let selId = e.currentTarget.dataset.selid;
  44. let answersBoxs = this.data.answersBoxs;
  45. let i = answersBoxs.indexOf(selId)
  46. if (i < 0) {
  47. answersBoxs.push(selId)
  48. }
  49. this.setData({
  50. answersBoxs: answersBoxs
  51. })
  52. },
  53. // 选择
  54. editQuestion: function(index, subid) {
  55. let testLists = this.data.testLists;
  56. this.data.testLists[index].collegeTestResults.forEach((item, itemInd) => {
  57. item.id == subid ? item.is_select = 1 : item.is_select = 0;
  58. let attr = `testLists[${index}].collegeTestResults[${itemInd}]`;
  59. this.setData({
  60. [attr]: item
  61. })
  62. })
  63. },
  64. // 提交信息
  65. _clickBtn: function() {
  66. if (this.data.answersBoxs.length < this.data.testLists.length) {
  67. wx.showToast({
  68. title: '请完整回答',
  69. icon: 'none',
  70. duration: 2000
  71. })
  72. return
  73. }
  74. let answers = [];
  75. this.data.testLists.forEach(item => {
  76. item.collegeTestResults.forEach(jjj => {
  77. if (jjj.userAnswer != null) {
  78. wx.showToast({
  79. title: '已做过测试',
  80. icon: 'none',
  81. duration: 2000
  82. })
  83. return
  84. }
  85. if (jjj.is_select == 1) {
  86. answers.push(jjj.seq)
  87. }
  88. })
  89. })
  90. const that = this
  91. util.postData('/college/addTestDetail', {
  92. openid: app.globalData.openid,
  93. core_id: that.data.core_id,
  94. answers: answers.toString()
  95. })
  96. .then(res => {
  97. wx.navigateTo({
  98. url: '/pages/testing/score/score?res=' + JSON.stringify(res) +'&core_id='+that.data.core_id
  99. })
  100. // wx.showToast({
  101. // title: '答对' + res.count + '题' + '总分' + res.score + '分',
  102. // icon: 'none',
  103. // duration: 4000
  104. // })
  105. })
  106. .catch(err => {
  107. console.log(err);
  108. })
  109. },
  110. //返回首页
  111. backHome: function() {
  112. util.goHome();
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function() {}
  118. })