paper.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. let app = getApp()
  2. Page({
  3. data: {
  4. list: [],
  5. paperId:0,
  6. title:'',
  7. preList:["A","B","C", "D","E","F"],
  8. info:{},
  9. id:0,
  10. userInfo:{},
  11. result: {}
  12. },
  13. onLoad: function(options) {
  14. let paperId = +options.paperId||1
  15. let title = options.title||'试卷'
  16. this.setData({paperId, title})
  17. },
  18. onShow: function () {
  19. app.checkLogin( userInfo =>{
  20. this.setData({userInfo, from:0})
  21. this.indexLoad()
  22. })
  23. },
  24. indexLoad(){
  25. let paperId = this.data.paperId;
  26. app.formPost("exam.GetWxGroupPaperInfo", {paperId}).then(res => {
  27. if (res.code ==200) {
  28. let list = res.data.map( item =>{
  29. if( item.select > 0) item._select = true;
  30. return item
  31. })
  32. this.setData({list });
  33. }
  34. })
  35. },
  36. radioChange( e ){
  37. let index = e.currentTarget.dataset.index;
  38. let list = this.data.list
  39. list[index].select = +e.detail.value
  40. this.submitAnswer(list[index], list[index].select== list[index].result?1:0 )
  41. this.setData( {list} );
  42. },
  43. emptyAnswer(e){
  44. let list = this.data.list.map( item =>{
  45. item._select = false;
  46. item.select = 0
  47. return item
  48. })
  49. this.setData({list})
  50. },
  51. checkboxChange( e ){
  52. let index = e.currentTarget.dataset.index;
  53. let list = this.data.list
  54. list[index].select = +e.detail.value.sort().join("")
  55. let result = ""+list[index].result
  56. if (list[index].select == result ){
  57. list[index]._select = true
  58. this.submitAnswer(list[index], 1 )
  59. }else{
  60. for( let i in e.detail.value){
  61. if(result.indexOf( e.detail.value[i] )==-1 ){
  62. list[index]._select = true
  63. this.submitAnswer(list[index], 0 )
  64. }
  65. }
  66. }
  67. this.setData( {list} );
  68. },
  69. submitAnswer( answer, correct ){
  70. let {paperId} = this.data
  71. let {answerId, groupId, select} = answer
  72. let param = {paperId, groupId, answerId, correct, select}
  73. app.formPost('Exam.SubmitWxGroupPaperAnswer', param).then(res => {
  74. console.log( res )
  75. })
  76. }
  77. })