index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if( list[index].select== list[index].result ) this.delAnswer(list[index].answerId )
  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].answerId )
  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.loadData( this.stopPullDownRefresh )
  70. }
  71. },
  72. onReachBottom() {
  73. if (!this.loading && this.data.from > -1) {
  74. this.loadData( )
  75. }
  76. },
  77. stopPullDownRefresh(){
  78. wx.stopPullDownRefresh()
  79. },
  80. delAnswer( answerId ){
  81. app.formPost('Exam.DelErrorAnswer', {answerId}).then(res => {
  82. })
  83. }
  84. })