| using System; | 
| 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 scrAward; | 
|     [SerializeField] TextEx txtExpiryDate; | 
|     [SerializeField] ImageEx imgHasAward; | 
|     [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() | 
|     { | 
|         base.OnPreOpen(); | 
|         scrAward.OnRefreshCell += OnRefreshLowRewardCell; | 
|         model.OnUpdateMailListEvent += OnUpdateMailListEvent; | 
|         model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent; | 
|         GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; | 
|         Display(); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         base.OnPreClose(); | 
|         scrAward.OnRefreshCell -= OnRefreshLowRewardCell; | 
|         model.OnUpdateMailListEvent -= OnUpdateMailListEvent; | 
|         model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent; | 
|         GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; | 
|     } | 
|   | 
|     private void OnSecondEvent() | 
|     { | 
|         txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime); | 
|         txtExpiryDate.text = model.FormatMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays); | 
|         txtExpiryDate.color = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays) >= 0 ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red); | 
|     } | 
|   | 
|     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() | 
|     { | 
|         Display(); | 
|     } | 
|   | 
|     private void OnUpdateMailListEvent() | 
|     { | 
|         Display(); | 
|     } | 
|   | 
|     private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell) | 
|     { | 
|         var _cell = cell.GetComponent<MailInfoAwardCell>(); | 
|         _cell?.Display(cell.index, cell); | 
|     } | 
|   | 
|   | 
|     private void Display() | 
|     { | 
|         if (!model.TryGetMailData(model.nowUuid, out nowMailData)) | 
|         { | 
|             UIManager.Instance.CloseWindow<MailInfoWin>(); | 
|             return; | 
|         } | 
|         isHasAward = nowMailData != null && nowMailData.HasAward(); | 
|         transNoAward.SetActive(!isHasAward); | 
|         transAward.SetActive(isHasAward); | 
|         btnHave.SetActive(isHasAward && nowMailData.MailState != 3); | 
|         imgHasAward.SetActive(nowMailData.MailState != 3 && nowMailData.HasAward()); | 
|         txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime); | 
|   | 
|         string key = nowMailData.GetTemplateKey(); | 
|         if (nowMailData.IsTemplateMail() && MailConfig.HasKey(key)) | 
|         { | 
|             MailConfig config = MailConfig.Get(key); | 
|             var templateParams = nowMailData.GetTemplateParams(); | 
|   | 
|             // 打印出即将用于格式化的所有信息 | 
|             //         Debug.Log($"[邮件调试] GUID: {nowMailData.GUID}"); | 
|             // Debug.Log($"[邮件调试] 原始参数JSON (nowMailData.Text): '{nowMailData.Text}'"); | 
|             // Debug.Log($"[邮件调试] 解析后的参数数量: {templateParams.Count}"); | 
|             // if (templateParams.Count > 0) | 
|             // { | 
|             //     for(int i = 0; i < templateParams.Count; i++) | 
|             //     { | 
|             //         Debug.Log($"[邮件调试] 参数[{i}]: {templateParams[i]}"); | 
|             //     } | 
|             // } | 
|             try | 
|             { | 
|                 string content = string.Format(config.Content, templateParams.ToArray()); | 
|                 txtNoAwardInfo.text = content; | 
|                 txtAwardInfo.text = content; | 
|                 txtTitle.text = config.Title; | 
|             } | 
|             catch (System.Exception ex) | 
|             { | 
|                 txtTitle.text = nowMailData.Title; | 
|                 txtNoAwardInfo.text = nowMailData.Text; | 
|                 txtAwardInfo.text = nowMailData.Text; | 
|                 Debug.LogError($"MailInfoWin 解析邮件参数失败! GUID: {nowMailData.GUID}, " + | 
|                                  $"原始参数JSON: '{nowMailData.Text}', 错误: {ex.Message}"); | 
|             } | 
|         } | 
|         else | 
|         { | 
|             txtTitle.text = nowMailData.Title; | 
|             txtNoAwardInfo.text = nowMailData.Text; | 
|             txtAwardInfo.text = nowMailData.Text; | 
|         } | 
|         txtExpiryDate.text = model.FormatMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays); | 
|         txtExpiryDate.color = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays) >= 0 ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red); | 
|         scrAward.Refresh(); | 
|         if (isHasAward) | 
|         { | 
|             for (int i = 0; i < nowMailData.Items.Count; i++) | 
|             { | 
|                 CellInfo cellInfo = new CellInfo(); | 
|                 cellInfo.infoStr1 = nowMailData.GUID; | 
|                 scrAward.AddCell(ScrollerDataType.Header, i, cellInfo); | 
|             } | 
|         } | 
|         scrAward.Restart(); | 
|     } | 
|   | 
| } |