let app = getApp() Page({ data: { preList:["A","B","C", "D", "E", "F"], from:0, size:10, item: {}, next: false, loading:false, groupId:0, list: [], }, onLoad: function(options) { let groupId = + options.groupId||0 this.setData({groupId}) this.loadData( ) }, loadData( cb ){ let {size,from, groupId, list } = this.data this.setData({loading:true}) app.formPost('Exam.GetErrorAnswerList', {groupId,from,size}).then(res => { if (res.code ==200) { if( from == 0){ list = []; } this.setData({ from: res.data.from, list: list.concat(res.data.list), }); } this.setData({loading:false}) cb&&cb() }) }, radioChange( e ){ let index = e.currentTarget.dataset.index; let list = this.data.list list[index].select = +e.detail.value this.setData( {list} ); this.delAnswer( list[index]) }, checkboxChange( e ){ let index = e.currentTarget.dataset.index; let list = this.data.list list[index].select = +e.detail.value.sort().join("") let result = ""+list[index].result if (list[index].select == result ){ list[index]._select = true this.delAnswer(list[index] ) }else{ for( let i in e.detail.value){ if(result.indexOf( e.detail.value[i] )==-1 ){ list[index]._select = true } } } this.setData( {list} ); }, emptyAnswer(e){ let list = this.data.list.map( item =>{ item._select = false; item.select = 0 return item }) this.setData({list}) }, onPullDownRefresh() { if (!this.loading) { this.setData({list:[], from:0}) this.loadData( this.stopPullDownRefresh ) } }, onReachBottom() { if (!this.loading && this.data.from > -1) { this.loadData( ) } }, stopPullDownRefresh(){ wx.stopPullDownRefresh() }, delAnswer( info ){ let {id, parentId, select,result} = info; let list = this.data.list let skip = false let mselect = {}; if( parentId > 0 ){ for( let i in list){ if( list[i].parentId == parentId ){ if(list[i].select != list[i].result){ skip = true } mselect[list[i].answerId] = list[i].select; } } }else{ if( select!= result) skip = true; } app.formPost('Exam.DelErrorAnswer', {id,skip,mselect}).then(res => { }) } })