answerAfterclasses.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. totalScore: 0,
  9. id: '', //考试主键id(可取list接口中id)
  10. paperId: '', //试卷id(可取list接口中paperId)
  11. answersId: '', // 提交答案
  12. sessionKey: '',
  13. },
  14. /*
  15. * 单选事件
  16. */
  17. radioChange: function (e) {
  18. let json = {};
  19. json.currentAnswer = e.detail.value;
  20. json.id = e.currentTarget.dataset.idx;
  21. json.questType = e.currentTarget.dataset.questtypes;
  22. this.data.chooseValue[this.data.index] = json;
  23. this.data.questionList[this.data.index].checked = e.detail.value;
  24. this.setData({
  25. questionList: this.data.questionList
  26. })
  27. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  28. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  29. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  30. },
  31. radioChange: function (e) {
  32. let json = {};
  33. json.currentAnswer = e.detail.value;
  34. json.id = e.currentTarget.dataset.idx;
  35. json.questType = e.currentTarget.dataset.questtypes;
  36. this.data.chooseValue[this.data.index] = json;
  37. const items = this.data.questionList[this.data.index].QuestChoice
  38. for (let i = 0, len = items.length; i < len; ++i) {
  39. items[i].checked = items[i].value === e.detail.value
  40. }
  41. this.setData({
  42. questionList: this.data.questionList
  43. })
  44. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  45. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  46. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  47. },
  48. /*
  49. * 多选事件
  50. */
  51. checkboxChange: function (e) {
  52. let json = {};
  53. let aa = e.detail.value.join("||")
  54. json.currentAnswer = aa;
  55. json.questType = e.currentTarget.dataset.questtypes;
  56. json.id = e.currentTarget.dataset.idx;
  57. this.data.chooseValue[this.data.index] = json;
  58. const items = this.data.questionList[this.data.index].QuestChoice
  59. const values = e.detail.value
  60. for (let i = 0, lenI = items.length; i < lenI; ++i) {
  61. items[i].checked = false
  62. for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
  63. if (items[i].value === values[j]) {
  64. items[i].checked = true
  65. break
  66. }
  67. }
  68. }
  69. this.setData({
  70. questionList: this.data.questionList
  71. })
  72. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  73. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  74. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  75. },
  76. /*
  77. * 解答事件
  78. */
  79. bindTextAreaBlur(e) {
  80. let json = {};
  81. json.currentAnswer = e.detail.value;
  82. json.id = e.currentTarget.dataset.idx;
  83. json.questType = e.currentTarget.dataset.questtypes;
  84. this.data.chooseValue[this.data.index] = json;
  85. this.data.questionList[this.data.index].currentAnswer = e.detail.value;
  86. this.setData({
  87. questionList: this.data.questionList
  88. })
  89. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  90. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  91. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue);
  92. },
  93. /*
  94. * 下一题/提交 按钮
  95. */
  96. nextSubmit: function () {
  97. // console.log("0000")
  98. // 判断是不是最后一题
  99. if (this.data.index < this.data.questionList.length - 1) {
  100. console.log(this.data.chooseValue,"0000000000000000")
  101. // 渲染下一题
  102. this.setData({
  103. index: this.data.index + 1
  104. })
  105. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  106. } else {
  107. console.log(this.data.chooseValue,"1111111111")
  108. if (wx.getStorageSync('chooseValue' + this.data.answersId)) {
  109. this.setData({
  110. chooseValue: wx.getStorageSync('chooseValue' + this.data.answersId)
  111. })
  112. }
  113. this.submitAll(this.data.chooseValue);
  114. }
  115. },
  116. upSubmit() {
  117. console.log(this.data.chooseValue,"我点击上一题了")
  118. this.setData({
  119. index: this.data.index - 1
  120. })
  121. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), this.data.index);
  122. },
  123. async onLoad(options) {
  124. console.log("我是答题页","00000000000")
  125. const sessionKey = await tools.checkSessionAndLogin();
  126. wx.setStorageSync('answersId', options.answersId);
  127. this.setData({
  128. sessionKey: sessionKey,
  129. paperId: options.paperId,
  130. answersId: options.answersId,
  131. id: options.id,
  132. })
  133. if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) {
  134. const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId'));
  135. const titleINDEX = wx.getStorageSync('titleINDEX' + wx.getStorageSync('answersId'));
  136. const chooseValue = wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId'));
  137. this.setData({
  138. questionList: questionList,
  139. answersId: wx.getStorageSync('answersId'),
  140. chooseValue: chooseValue,
  141. index: titleINDEX
  142. })
  143. } else {
  144. this.allShi(options.id, options.paperId, sessionKey);
  145. }
  146. },
  147. allShi(id, paperId, sessionKey) {
  148. wx.request({
  149. url: app.globalData.publicUrl + '/wx/paper/detail',
  150. method: "post",
  151. data: {
  152. sessionKey: sessionKey,
  153. id: id,
  154. paperId: paperId
  155. },
  156. success: (res) => {
  157. let jsonArr = JSON.parse(res.data.paperContent).map(item => {
  158. let json = {};
  159. json.QuestType = item.QuestType;
  160. json.id = item.Id;
  161. json.QuestAnswer = item.QuestAnswer;
  162. json.QuestStem = item.QuestStem;
  163. if (item.QuestChoice) {
  164. let arr = item.QuestChoice.split('||');
  165. json.QuestChoice = arr;
  166. }
  167. if (item.QuestType == '1') {
  168. let arr = item.QuestChoice.split('||');
  169. let arrJson = arr.map(item => {
  170. let json1 = {};
  171. json1.name = item;
  172. json1.value = item;
  173. json1.checked = false;
  174. return json1
  175. });
  176. json.QuestChoice = arrJson;
  177. }
  178. if (item.QuestType == '0') {
  179. let arr = item.QuestChoice.split('||');
  180. let arrJson = arr.map(item => {
  181. let json1 = {};
  182. json1.name = item;
  183. json1.value = item;
  184. json1.checked = false;
  185. return json1
  186. });
  187. json.QuestChoice = arrJson;
  188. }
  189. if (item.QuestType == '2') {
  190. let arr = item.QuestChoice.split('||');
  191. let arrJson = arr.map(item => {
  192. let json1 = {};
  193. json1.name = item;
  194. json1.value = item;
  195. json1.checked = false;
  196. return json1
  197. });
  198. json.QuestChoice = arrJson;
  199. }
  200. return json;
  201. })
  202. this.setData({
  203. questionList: jsonArr
  204. })
  205. wx.setStorageSync('titleINDEX' + wx.getStorageSync('answersId'), 0);
  206. wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), []),
  207. wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList);
  208. },
  209. fail:()=>{
  210. wx.hideLoading();
  211. }
  212. })
  213. },
  214. submitAll(currentAnswerTemp) {
  215. console.log(currentAnswerTemp,"我是带过来的答案")
  216. if (currentAnswerTemp.length == 0) {
  217. let arr = this.data.questionList.map(item => {
  218. let json = {};
  219. json.currentAnswer = '';
  220. json.questType = item.QuestType;
  221. json.id = item.id;
  222. return json
  223. });
  224. wx.request({
  225. url: app.globalData.publicUrl + '/wx/paper/commit',
  226. method: "post",
  227. data: {
  228. sessionKey: this.data.sessionKey,
  229. currentAnswerTemp: arr,
  230. answersId: wx.getStorageSync('answersId')
  231. },
  232. success: (res) => {
  233. wx.hideLoading();
  234. if (res.data.code == 0) {
  235. wx.showModal({
  236. showCancel: false,
  237. content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  238. success() {
  239. wx.navigateBack({
  240. delta: 1
  241. })
  242. }
  243. })
  244. } else {
  245. wx.showModal({
  246. showCancel: false,
  247. content: res.data.msg,
  248. success() {
  249. wx.navigateBack({
  250. delta: 1
  251. })
  252. }
  253. })
  254. }
  255. }
  256. })
  257. } else {
  258. wx.request({
  259. url: app.globalData.publicUrl + '/wx/paper/commit',
  260. method: "post",
  261. data: {
  262. sessionKey: this.data.sessionKey,
  263. currentAnswerTemp: currentAnswerTemp,
  264. answersId: wx.getStorageSync('answersId')
  265. },
  266. success: (res) => {
  267. wx.hideLoading();
  268. if (res.data.code == 0) {
  269. wx.showModal({
  270. showCancel: false,
  271. content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  272. success() {
  273. wx.navigateBack({
  274. delta: 1
  275. })
  276. }
  277. })
  278. } else {
  279. wx.showModal({
  280. showCancel: false,
  281. content: res.data.msg,
  282. success() {
  283. wx.navigateBack({
  284. delta: 1
  285. })
  286. }
  287. })
  288. }
  289. }
  290. })
  291. }
  292. // wx.request({
  293. // url: app.globalData.publicUrl + '/wx/paper/commit',
  294. // method: "post",
  295. // data: {
  296. // sessionKey: this.data.sessionKey,
  297. // currentAnswerTemp: currentAnswerTemp,
  298. // answersId: wx.getStorageSync('answersId')
  299. // },
  300. // success: (res) => {
  301. // if (res.data.code == 0) {
  302. // wx.showModal({
  303. // showCancel: false,
  304. // content: '恭喜您,提交答案成功,请耐心等待老师判卷',
  305. // success() {
  306. // wx.navigateBack({
  307. // delta: 1
  308. // })
  309. // }
  310. // })
  311. // }
  312. // else {
  313. // wx.showModal({
  314. // showCancel: false,
  315. // content: res.data.msg,
  316. // success() {
  317. // wx.navigateBack({
  318. // delta: 1
  319. // })
  320. // }
  321. // })
  322. // }
  323. // }
  324. // })
  325. }
  326. })