answerAfterclass.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. index: 0, // 题目序列
  6. chooseValue: [], // 选择的答案序列
  7. questionList: [
  8. // {
  9. // id: 10,
  10. // "QuestStem": "以下属于传统协同办公应用开发的典型问题的是?",
  11. // 'QuestChoice': [{
  12. // name: 'a',
  13. // value: 'aaaaaaa',
  14. // checked: false
  15. // },
  16. // {
  17. // name: 'aa',
  18. // value: 'sdsdsd',
  19. // checked: false
  20. // },
  21. // {
  22. // name: 'a3',
  23. // value: 'ewewewe',
  24. // checked: false
  25. // },
  26. // ],
  27. // "QuestType": 1,
  28. // "checked": false
  29. // },
  30. // {
  31. // id: 12,
  32. // "QuestStem": "企业微信建立开放办公应用生态的主要策略是000?",
  33. // "QuestChoice": ['A', 'B'],
  34. // "QuestType": 2,
  35. // "scores": 10,
  36. // "checked": false
  37. // },
  38. // {
  39. // id: 123,
  40. // "QuestStem": "企业微信建立开放办公应用生态的主要策略是?",
  41. // "QuestType": 3,
  42. // "scores": 10,
  43. // "checked": false
  44. // },
  45. ],
  46. totalScore: 0,
  47. id: '', //考试主键id(可取list接口中id)
  48. paperId: '', //试卷id(可取list接口中paperId)
  49. answersId: '', // 提交答案
  50. sessionKey: '',
  51. },
  52. /*
  53. * 单选事件
  54. */
  55. radioChange: function (e) {
  56. let json = {};
  57. json.currentAnswer = e.detail.value;
  58. json.id = e.currentTarget.dataset.idx;
  59. json.questType = e.currentTarget.dataset.questtypes;
  60. this.data.chooseValue[this.data.index] = json;
  61. const items = this.data.questionList[this.data.index].QuestChoice
  62. for (let i = 0, len = items.length; i < len; ++i) {
  63. items[i].checked = items[i].value === e.detail.value
  64. }
  65. this.setData({
  66. questionList: this.data.questionList
  67. })
  68. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  69. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  70. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  71. },
  72. /*
  73. * 多选事件
  74. */
  75. checkboxChange: function (e) {
  76. let json = {};
  77. let aa = e.detail.value.join("||")
  78. json.currentAnswer = aa;
  79. json.questType = e.currentTarget.dataset.questtypes;
  80. json.id = e.currentTarget.dataset.idx;
  81. this.data.chooseValue[this.data.index] = json;
  82. const items = this.data.questionList[this.data.index].QuestChoice
  83. const values = e.detail.value
  84. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  85. items[i].checked = false
  86. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  87. if (items[i].value === values[j]) {
  88. items[i].checked = true
  89. break
  90. }
  91. }
  92. }
  93. this.setData({
  94. questionList: this.data.questionList
  95. })
  96. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  97. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  98. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  99. },
  100. /*
  101. * 解答事件
  102. */
  103. bindTextAreaBlur(e) {
  104. let json = {};
  105. json.currentAnswer = e.detail.value;
  106. json.id = e.currentTarget.dataset.idx;
  107. json.questType = e.currentTarget.dataset.questtypes;
  108. this.data.chooseValue[this.data.index] = json;
  109. this.data.questionList[this.data.index].currentAnswer = e.detail.value;
  110. this.setData({
  111. questionList: this.data.questionList
  112. })
  113. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  114. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  115. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  116. },
  117. /*
  118. * 下一题/提交 按钮
  119. */
  120. nextSubmit: function () {
  121. // 判断是不是最后一题
  122. if (this.data.index < this.data.questionList.length - 1) {
  123. // 渲染下一题
  124. this.setData({
  125. index: this.data.index + 1
  126. })
  127. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  128. } else {
  129. if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
  130. this.setData({
  131. chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
  132. })
  133. }
  134. this.submitAll(this.data.chooseValue);
  135. }
  136. },
  137. upSubmit() {
  138. this.setData({
  139. index: this.data.index - 1
  140. })
  141. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  142. },
  143. async onLoad(options) {
  144. const sessionKey = await tools.checkSessionAndLogin();
  145. wx.setStorageSync('answersId', options.answersId);
  146. this.setData({
  147. sessionKey: sessionKey,
  148. paperId: options.paperId,
  149. answersId: options.answersId,
  150. id: options.id,
  151. })
  152. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  153. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  154. const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
  155. const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
  156. this.setData({
  157. questionList: questionList,
  158. answersId: wx.getStorageSync('answersId'),
  159. chooseValue: chooseValue,
  160. index: titleINDEX
  161. })
  162. } else {
  163. this.allShi(options.id, options.paperId, sessionKey);
  164. }
  165. },
  166. allShi(id, paperId, sessionKey) {
  167. wx.request({
  168. url: app.globalData.publicUrl + '/wx/paper/detail',
  169. method: "post",
  170. data: {
  171. sessionKey: sessionKey,
  172. id: id,
  173. paperId: paperId
  174. },
  175. success: (res) => {
  176. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  177. let json = {};
  178. json.QuestType = item.QuestType;
  179. json.id = item.Id;
  180. json.QuestAnswer = item.QuestAnswer;
  181. json.QuestStem = item.QuestStem;
  182. if (item.QuestChoice) {
  183. let arr = item.QuestChoice.split('||');
  184. json.QuestChoice = arr;
  185. }
  186. if (item.QuestType == '1') {
  187. let arr = item.QuestChoice.split('||');
  188. let arrJson = arr.map(item => {
  189. let json1 = {};
  190. json1.name = item;
  191. json1.value = item;
  192. json1.checked = false;
  193. return json1
  194. });
  195. json.QuestChoice = arrJson;
  196. }
  197. if (item.QuestType == '0') {
  198. let arr = item.QuestChoice.split('||');
  199. let arrJson = arr.map(item => {
  200. let json1 = {};
  201. json1.name = item;
  202. json1.value = item;
  203. json1.checked = false;
  204. return json1
  205. });
  206. json.QuestChoice = arrJson;
  207. }
  208. if (item.QuestType == '2') {
  209. let arr = item.QuestChoice.split('||');
  210. let arrJson = arr.map(item => {
  211. let json1 = {};
  212. json1.name = item;
  213. json1.value = item;
  214. json1.checked = false;
  215. return json1
  216. });
  217. json.QuestChoice = arrJson;
  218. }
  219. return json;
  220. })
  221. this.setData({
  222. questionList: jsonArr
  223. })
  224. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), 0);
  225. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), []),
  226. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  227. }
  228. })
  229. },
  230. submitAll(currentAnswerTemp) {
  231. wx.showLoading({
  232. mask: true,
  233. title: '加载中',
  234. })
  235. wx.request({
  236. url: app.globalData.publicUrl + '/wx/paper/commit',
  237. method: "post",
  238. data: {
  239. sessionKey: this.data.sessionKey,
  240. currentAnswerTemp: currentAnswerTemp,
  241. answersId: wx.getStorageSync('answersId')
  242. },
  243. success: (res) => {
  244. wx.hideLoading();
  245. if (res.data.code == 0) {
  246. wx.showModal({
  247. showCancel: false,
  248. content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  249. success() {
  250. wx.navigateBack({
  251. delta: 1
  252. })
  253. }
  254. })
  255. }
  256. // else {
  257. // wx.showModal({
  258. // showCancel: false,
  259. // content: res.data.msg,
  260. // success() {
  261. // wx.navigateBack({
  262. // delta: 1
  263. // })
  264. // }
  265. // })
  266. // }
  267. }
  268. })
  269. }
  270. })