import Event from"../../common/chat/eventTypes";import util from"../../common/utils/utils";import store from"../../store/index";Component({data:{quizList:[],scrollTop:0},properties:{skin:{type:String,value:"black",observer(t){"black"!==t&&"white"!==t&&this.setData({skin:"black"})}}},lifetimes:{created(){this.notJoinLists=[],this.clock=null,this.chat=null,this.chatEvent=this.getChatEvent()},attached(){store.get({"main.chat":t=>{this.chat=t,t&&(this.handleSocketEvent(),this.chat.getQuestionHistoryMessage(),this.initQuizListQueue())}})},detached(){clearInterval(this.clock),this.handleSocketEvent(!1)}},methods:{handleSendMsg(t){const i=t.detail.chatTitle;this.chat.sendQuiz(i)},handleSocketEvent(t=!0){const i=this.chat,s=this.chatEvent;i&&Object.keys(s).forEach((e=>{i[t?"on":"off"](e,s[e])}))},getChatEvent(){const t=this;return{[Event.UPDATE_QUESTION_HISTROY](i,s){t.gotHistory||(t.gotHistory=!0,t.notJoinLists=[...s,...t.notJoinLists])},[Event.S_QUESTION](i,s){t.notJoinLists.push(s)},[Event.T_ANSWER](i,s){t.notJoinLists.push(s)},[Event.SYSTEM_MESSAGE](i,s){t.notJoinLists.push(s)}}},initQuizListQueue(){this.clock=setInterval((()=>{this.notJoinLists.length&&(this.setData({quizList:[...this.data.quizList,...this.notJoinLists]}),this.notJoinLists=[],wx.nextTick((()=>{this.scrollToBottom()})))}),300)},scrollToBottom(){util.getDomRect("#quizList",this).then((({height:t})=>{this.setData({scrollTop:t})}))}}});