index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. let app = getApp()
  2. Page({
  3. data: {
  4. preList:["A","B","C", "D", "E", "F"],
  5. from:0,
  6. size:10,
  7. item: {},
  8. next: false,
  9. loading:false,
  10. groupId:0,
  11. list: [],
  12. },
  13. onLoad: function(options) {
  14. let groupId = + options.groupId||0
  15. this.setData({groupId})
  16. this.loadData( )
  17. },
  18. loadData( cb ){
  19. let {size,from, groupId, list } = this.data
  20. this.setData({loading:true})
  21. app.formPost('Exam.GetErrorAnswerList', {groupId,from,size}).then(res => {
  22. if (res.code ==200) {
  23. if( from == 0){
  24. list = [];
  25. }
  26. this.setData({
  27. from: res.data.from,
  28. list: list.concat(res.data.list),
  29. });
  30. }
  31. this.setData({loading:false})
  32. cb&&cb()
  33. })
  34. },
  35. radioChange( e ){
  36. let index = e.currentTarget.dataset.index;
  37. let list = this.data.list
  38. list[index].select = +e.detail.value
  39. this.setData( {list} );
  40. this.delAnswer( list[index])
  41. },
  42. checkboxChange( e ){
  43. let index = e.currentTarget.dataset.index;
  44. let list = this.data.list
  45. list[index].select = +e.detail.value.sort().join("")
  46. let result = ""+list[index].result
  47. if (list[index].select == result ){
  48. list[index]._select = true
  49. this.delAnswer(list[index] )
  50. }else{
  51. for( let i in e.detail.value){
  52. if(result.indexOf( e.detail.value[i] )==-1 ){
  53. list[index]._select = true
  54. }
  55. }
  56. }
  57. this.setData( {list} );
  58. },
  59. emptyAnswer(e){
  60. let list = this.data.list.map( item =>{
  61. item._select = false;
  62. item.select = 0
  63. return item
  64. })
  65. this.setData({list})
  66. },
  67. onPullDownRefresh() {
  68. if (!this.loading) {
  69. this.setData({list:[], from:0})
  70. this.loadData( this.stopPullDownRefresh )
  71. }
  72. },
  73. onReachBottom() {
  74. if (!this.loading && this.data.from > -1) {
  75. this.loadData( )
  76. }
  77. },
  78. stopPullDownRefresh(){
  79. wx.stopPullDownRefresh()
  80. },
  81. delAnswer( info ){
  82. let {id, parentId, select,result} = info;
  83. let list = this.data.list
  84. let skip = false
  85. let mselect = {};
  86. if( parentId > 0 ){
  87. for( let i in list){
  88. if( list[i].parentId == parentId ){
  89. if(list[i].select != list[i].result){
  90. skip = true
  91. }
  92. mselect[list[i].answerId] = list[i].select;
  93. }
  94. }
  95. }else{
  96. if( select!= result) skip = true;
  97. }
  98. app.formPost('Exam.DelErrorAnswer', {id,skip,mselect}).then(res => {
  99. })
  100. }
  101. })