| using UnityEngine; | 
| public class MailInfoWin : UIBase | 
| { | 
|     [SerializeField] TextEx txtDate; | 
|     [SerializeField] TextEx txtTitle; | 
|     [SerializeField] Transform transNoAward; | 
|     [SerializeField] RichText txtNoAwardInfo; | 
|     [SerializeField] Transform transAward; | 
|     [SerializeField] RichText txtAwardInfo; | 
|     [SerializeField] ScrollerController scrAwardItem; | 
|     [SerializeField] TextEx txtExpiryDate; | 
|     [SerializeField] ButtonEx btnHave; | 
|     [SerializeField] ButtonEx btnDelete; | 
|     MailData nowMailData; | 
|     bool isHasAward = false; | 
|     MailManager model { get { return MailManager.Instance; } } | 
|   | 
|     protected override void InitComponent() | 
|     { | 
|         base.InitComponent(); | 
|         btnHave.SetListener(OnClickHaveButton); | 
|         btnDelete.SetListener(OnClickDeleteButton); | 
|     } | 
|   | 
|     protected override void OnPreOpen() | 
|     { | 
|         scrAwardItem.OnRefreshCell += OnRefreshLowRewardCell; | 
|         model.OnUpdateMailListEvent += OnUpdateMailListEvent; | 
|         model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent; | 
|     } | 
|   | 
|     protected override void OnOpen() | 
|     { | 
|         UpdateDataInfo(); | 
|         Display(); | 
|         CreateScrAward(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         scrAwardItem.OnRefreshCell -= OnRefreshLowRewardCell; | 
|         model.OnUpdateMailListEvent -= OnUpdateMailListEvent; | 
|         model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent; | 
|     } | 
|   | 
|     private void OnClickHaveButton() | 
|     { | 
|         if (model.nowUuid == null || model.nowUuid == string.Empty) | 
|         { | 
|             Debug.Log("当前查看的邮件没有UUID"); | 
|             return; | 
|         } | 
|         model.ClaimMail(model.nowUuid); | 
|     } | 
|     private void OnClickDeleteButton() | 
|     { | 
|         if (model.nowUuid == null || model.nowUuid == string.Empty) | 
|         { | 
|             Debug.Log("当前查看的邮件没有UUID"); | 
|             return; | 
|         } | 
|         model.DeleteMail(model.nowUuid); | 
|         UIManager.Instance.CloseWindow<MailInfoWin>(); | 
|         //邮件删除成功 | 
|         SysNotifyMgr.Instance.ShowTip("Mail01"); | 
|     } | 
|   | 
|     private void OnUpdateMailStateChangeEvent() | 
|     { | 
|         UpdateDataInfo(); | 
|         Display(); | 
|         CreateScrAward(); | 
|     } | 
|   | 
|     private void OnUpdateMailListEvent() | 
|     { | 
|         UpdateDataInfo(); | 
|         Display(); | 
|         CreateScrAward(); | 
|     } | 
|   | 
|     private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell) | 
|     { | 
|         var _cell = cell.GetComponent<MailInfoAwardItemCell>(); | 
|         _cell?.Display(cell.index, cell); | 
|     } | 
|   | 
|     private void CreateScrAward() | 
|     { | 
|         scrAwardItem.Refresh(); | 
|         if (isHasAward) | 
|         { | 
|             for (int i = 0; i < nowMailData.Items.Count; i++) | 
|             { | 
|                 CellInfo cellInfo = new CellInfo(); | 
|                 cellInfo.infoInt1 = nowMailData.MailState; | 
|                 scrAwardItem.AddCell(ScrollerDataType.Header, i); | 
|             } | 
|         } | 
|         scrAwardItem.Restart(); | 
|     } | 
|   | 
|     private void Display() | 
|     { | 
|         if (nowMailData == null) | 
|             return; | 
|         transNoAward.SetActive(!isHasAward); | 
|         transAward.SetActive(isHasAward); | 
|         txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime); | 
|              | 
|         if (nowMailData.IsTemplateMail()) | 
|         { | 
|             string key = nowMailData.GetTemplateKey(); | 
|             if (MailConfig.HasKey(key)) | 
|             { | 
|                 MailConfig config = MailConfig.Get(key); | 
|                 var templateParams = nowMailData.GetTemplateParams(); | 
|                 string content = string.Format(config.Content, templateParams.ToArray()); | 
|                 txtTitle.text = config.Title; | 
|                 txtNoAwardInfo.text = content; | 
|                 txtAwardInfo.text = content; | 
|             } | 
|             else | 
|             { | 
|                 txtTitle.text = nowMailData.Title; | 
|                 txtNoAwardInfo.text = nowMailData.Text; | 
|                 txtAwardInfo.text = nowMailData.Text; | 
|             } | 
|         } | 
|         else | 
|         { | 
|             txtTitle.text = nowMailData.Title; | 
|             txtNoAwardInfo.text = nowMailData.Text; | 
|             txtAwardInfo.text = nowMailData.Text; | 
|         } | 
|   | 
|         int expiryDays = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays); | 
|         txtExpiryDate.text = expiryDays > 0 ? Language.Get("Mail07", expiryDays) : string.Empty; | 
|   | 
|     } | 
|   | 
|     private void UpdateDataInfo() | 
|     { | 
|         if (!model.TryGetMailData(model.nowUuid, out nowMailData)) | 
|         { | 
|             UIManager.Instance.CloseWindow<MailInfoWin>(); | 
|         } | 
|         isHasAward = nowMailData != null && nowMailData.Items != null; | 
|     } | 
| } |