require("Base/BasePanel") MailMainPanel = Inherit(BasePanel) local this=MailMainPanel local allMail local openPanel local allGetMail local allDrop = {} --初始化组件(用于子类重写) function MailMainPanel:InitComponent() allGetMail={} this.closeBtn = Util.GetGameObject(self.gameObject, "bg/closeBtn") this.mialNum = Util.GetGameObject(self.gameObject, "bg/mialNum"):GetComponent("Text") this.DeleMialText = Util.GetGameObject(self.gameObject, "bg/DeleMialText"):GetComponent("Text") this.mailPre=Util.GetGameObject(self.gameObject, "mailPre") this.GetAllMailBtn=Util.GetGameObject(self.gameObject, "GetAllMailBtn") this.DelReadMailBtn=Util.GetGameObject(self.gameObject, "DelReadMailBtn") this.ScrollBar=Util.GetGameObject(self.gameObject, "Scrollbar"):GetComponent("Scrollbar") this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.gameObject.transform, this.mailPre, this.ScrollBar, Vector2.New(940, 1160), 1, 1, Vector2.New(19.32,15)) this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(10,-30) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 end --绑定事件(用于子类重写) function MailMainPanel:BindEvent() Util.AddClick(this.closeBtn, function() self:ClosePanel() end) Util.AddClick(this.GetAllMailBtn, function() allGetMail={} for i = 1, #allMail do if allMail[i].state<3 and allMail[i].mailItem ~= "" then table.insert(allGetMail,allMail[i].mailId) end end if allGetMail and #allGetMail>0 then this.GetMailData3() else PopupTipPanel.ShowTip(Language[11145]) end end) Util.AddClick(this.DelReadMailBtn, function() local DelMails={} for i = 1, #allMail do if allMail[i].state >= 1 and allMail[i].mailItem=="" then--已读取 未领取 无附件 table.insert(DelMails,allMail[i].mailId) elseif allMail[i].state >= 3 then--已领取 table.insert(DelMails,allMail[i].mailId) end end if DelMails and #DelMails>0 then this.DelMailData(DelMails) else PopupTipPanel.ShowTip(Language[11146]) end end) end function this.DelMailData(DelMails) if DelMails and #DelMails > 0 then NetManager.DelMailData(DelMails,function () for i = 1, #DelMails do MailManager.DelSingleMial(DelMails[i]) end this.UpdateMailData() end) end end function this.GetMailData(index) if index > 0 then NetManager.GetSingleMailRewardData({allGetMail[index]},function (_drop) MailManager.UpdataMialIsReadState(allGetMail[index],3) UIManager.OpenPanel(UIName.RewardItemPopup,_drop,1,function() if UIManager.IsOpen(UIName.PatFacePanel) then--如果弹星级成长礼 就会打断所有邮件的领取 this.UpdateMailData() else this.GetMailData(index-1) end end) end) else this.UpdateMailData() end end function this.GetMailData3() NetManager.GetSingleMailRewardData(allGetMail,function (_drop) for index = 1, #allGetMail do MailManager.UpdataMialIsReadState(allGetMail[index],3) end UIManager.OpenPanel(UIName.RewardItemPopup,_drop,1) this.UpdateMailData() end) end --添加事件监听(用于子类重写) function MailMainPanel:AddListener() end --移除事件监听(用于子类重写) function MailMainPanel:RemoveListener() end --界面打开时调用(用于子类重写) function MailMainPanel:OnOpen(...) local data={...} openPanel=data[1] end function MailMainPanel:OnShow() Log("MailMainPanel:OnShow") allMail={} NetManager.GetAllMailData(function () this.OnShowMailListData(MailManager.mialDataList) end) end function this.CallBackOnShow() allMail={} NetManager.GetAllMailData(function () this.OnShowMailListData(MailManager.mialDataList) end) end local maildataCount=0--数据数量 --设置英雄列表数据 function this.OnShowMailListData(_allMail) allMail= _allMail this:SortAllMail(allMail) maildataCount=#allMail this.mialNum.text=Language[11147]..maildataCount this.ScrollView:SetData(allMail, function (index, go) this.SingleMialDataShow(go, allMail[index]) end) end function this.SingleMialDataShow(_go,_mailData) local mailImage = Util.GetGameObject(_go.transform, "mailImage") local openMailImage = Util.GetGameObject(_go.transform, "openMailImage") local getOk = Util.GetGameObject(_go.transform, "goBtn/getOk") local goBtn = Util.GetGameObject(_go.transform, "goBtn") if _mailData.state==nil then _mailData.state=0 end if _mailData.mailItem=="" then--无附件 goBtn:SetActive(false) else goBtn:SetActive(true) end if _mailData.state==0 then--未读 mailImage :SetActive(true) openMailImage :SetActive(false) getOk :SetActive(false) elseif _mailData.state==1 then--已读取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(false) elseif _mailData.state==2 then--未领取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(false) elseif _mailData.state==3 then--已领取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(true) end Util.GetGameObject(_go.transform, "infoText"):GetComponent("Text").text = Language[11148].._mailData.head Util.GetGameObject(_go.transform, "sendText"):GetComponent("Text").text = GetTimeStrBySeconds(_mailData.sendTime)--Language[11149].._mailData.sendName local mialBtn = Util.GetGameObject(_go.transform, "Imagebg") Util.AddOnceClick(mialBtn, function() if _mailData.state==0 then--未读 NetManager.ReadSingleMailData(_mailData.mailId,function () MailManager.UpdataMialIsReadState(_mailData.mailId,1) Log(Language[11150].._mailData.mailId) this.UpdateMailData() end) end UIManager.OpenPanel(UIName.MainSingleInfoPanel,_mailData,this) end) Util.GetGameObject(_go.transform, "mialRedPoint"):SetActive( _mailData.state==0) end function this.UpdateMailData() this.OnShowMailListData(MailManager.mialDataList) end --界面关闭时调用(用于子类重写) function MailMainPanel:OnClose() if openPanel then openPanel.RefreshRedPoint() end end --界面销毁时调用(用于子类重写) function MailMainPanel:OnDestroy() this.ScrollView = nil end function MailMainPanel:SortAllMail(allMail) table.sort(allMail, function(a,b) --return a.state < b.state if a.state == b.state then return a.sendTime > b.sendTime else return a.state < b.state end end) end return MailMainPanel