112 lines
3.6 KiB
C#
112 lines
3.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using WI;
|
|
using UnityEngine.UI;
|
|
using static MQTT;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace CHN
|
|
{
|
|
public class Panel_CompleteAlramHistory : PanelBase, ISingle, IPopupPanel
|
|
{
|
|
public UI_CompleteTimeAlarmInfo prefab_completeTimeAlarmInfo;
|
|
public ScrollRect ScrollView_CompleteAlramHistory;
|
|
public Button Button_Close;
|
|
public Image Image_Loading;
|
|
|
|
public Dictionary<string, UI_CompleteTimeAlarmInfo> completeInfoList = new();
|
|
public List<UI_CompleteTimeAlarmInfo> notCheckAlramList = new();
|
|
|
|
public Action<string> onClickAlram;
|
|
public Action<int> onCheckAlarm;
|
|
//public Action<CompleteInfo, bool> onCheckAlarmData;
|
|
public Action onOpen;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
prefab_completeTimeAlarmInfo = Resources.Load<UI_CompleteTimeAlarmInfo>("Prefabs/UI/PRF_UI_CompleteTimeAlramInfo");
|
|
Button_Close.onClick.AddListener(Close);
|
|
notCheckAlramList.Clear();
|
|
completeInfoList.Clear();
|
|
}
|
|
public void Open()
|
|
{
|
|
SetActive(true);
|
|
onOpen?.Invoke();
|
|
}
|
|
public void Close()
|
|
{
|
|
SetActive(false);
|
|
}
|
|
public void ActiveLoadingImage(bool isActive)
|
|
{
|
|
var active = isActive ? false : true;
|
|
Image_Loading.gameObject.SetActive(active);
|
|
}
|
|
public void SetAlarmInfoItems(List<CompleteInfo> infos)
|
|
{
|
|
ActiveLoadingImage(true);
|
|
|
|
var sortedInfos = infos;
|
|
|
|
for (int i = 0; i < sortedInfos.Count; i++)
|
|
{
|
|
if (completeInfoList.ContainsKey(sortedInfos[i].worknm))
|
|
{
|
|
completeInfoList[sortedInfos[i].worknm].SetInfo(sortedInfos[i]);
|
|
}
|
|
else
|
|
{
|
|
var infoItem = Instantiate(prefab_completeTimeAlarmInfo, ScrollView_CompleteAlramHistory.content);
|
|
infoItem.SetInfo(sortedInfos[i]);
|
|
infoItem.onCheck += CheckAlram;
|
|
|
|
completeInfoList.Add(sortedInfos[i].worknm, infoItem);
|
|
|
|
if (!infoItem.isCheck)
|
|
{
|
|
notCheckAlramList.Add(infoItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
BlinkAlarmItems();
|
|
}
|
|
private List<CompleteInfo> SetSortInfoData(List<CompleteInfo> infos)
|
|
{
|
|
var sortedInfos = infos.Select(data =>
|
|
{
|
|
DateTime parsedDate;
|
|
bool isValid = DateTime.TryParse(data.ptotm, out parsedDate);
|
|
return new
|
|
{
|
|
AlarmData = data,
|
|
IsValid = isValid,
|
|
Date = parsedDate
|
|
};
|
|
})
|
|
.Where(item => item.IsValid)
|
|
.OrderByDescending(item => item.Date)
|
|
.Select(item => item.AlarmData)
|
|
.ToList();
|
|
|
|
return sortedInfos;
|
|
}
|
|
private void BlinkAlarmItems()
|
|
{
|
|
onCheckAlarm?.Invoke(notCheckAlramList.Count);
|
|
}
|
|
private void CheckAlram(UI_CompleteTimeAlarmInfo completeTimeAlarmInfo)
|
|
{
|
|
onClickAlram?.Invoke(completeTimeAlarmInfo.completeInfo.workcd);
|
|
|
|
//onCheckAlarmData?.Invoke(completeTimeAlarmInfo.completeInfo, completeTimeAlarmInfo.isCheck);
|
|
//notCheckAlramList.Remove(completeTimeAlarmInfo);
|
|
//onCheckAlarm?.Invoke(notCheckAlramList.Count);
|
|
}
|
|
}
|
|
}
|
|
|