Tz2/Assets/Zion/Scripts/Document/DocumentManagement.cs

723 lines
24 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DefaultNamespace.ProcessMode;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DefaultNamespace;
using Framework.Manager;
using MotionFramework;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static InterfaceManager;
using HighlightPlus;
/// <summary>
/// 单据验收管理
/// </summary>
public class DocumentManagement : MonoBehaviour
{
/// <summary>
/// 单据管理实例
/// </summary>
public static DocumentManagement Instance;
/// <summary>
/// 显示按钮
/// </summary>
public Button btnShowToggle;
/// <summary>
/// 单据Group
/// </summary>
public ToggleGroup toggleGroup;
/// <summary>
/// 单据集合
/// </summary>
[Header("单据集合")] public DocumentCollection[] documentCollections;
/// <summary>
/// 采购物资入库单据集合
/// </summary>
[Header("采购物资入库单据集合记录")] public DocumentCollection[] purchaseDocumentCollections;
/// <summary>
/// 调拨入库单据
/// </summary>
[Header("调拨入库单据集合记录")] public DocumentCollection[] documentGoListDBRK;
/// <summary>
/// 退出退役资产物资代保管出库作业
/// </summary>
[Header("退出退役资产物资代保管出库作业")] public DocumentCollection[] documentGoListTC;
/// <summary>
/// 退料物资入库
/// </summary>
[Header("退料物资入库")] public DocumentCollection[] documentGoListTLWZRK;
/// <summary>
/// 跨省调拨物资出库任务
/// </summary>
[Header("跨省调拨物资出库任务")] public DocumentCollection[] documentGoListKSDBWZ;
/// <summary>
/// 跨省调拨物资出库任务
/// </summary>
[Header("箱式开闭所借用物资领料出库系统操作")] public DocumentCollection[] documentGoListXSKBSJYWZ;
/// <summary>
/// 库存物资报废
/// </summary>
[Header("库存物资报废")] public DocumentCollection[] documentGoListKCWZBF;
/// <summary>
/// 物资领用出库
/// </summary>
[Header("领用出库")] public DocumentCollection[] documentGoListWZLYCK;
/// <summary>
/// 退出退役资产代保管入库作业
/// </summary>
[Header("退出退役资产代保管入库作业")] public DocumentCollection[] documentGoListTCYUDBGRK;
/// <summary>
/// 电缆分支箱跨地市物资调配
/// </summary>
[Header("电缆分支箱跨地市物资调配")] public DocumentCollection[] documentGoListDLFZXKSWZDP;
/// <summary>
/// 重点物资排产计划制定
/// </summary>
[Header("重点物资排产计划制定")] public DocumentCollection[] documentGoListDLZDWZPCJH;
/// <summary>
/// 废旧物资入库
/// </summary>
[Header("废旧物资入库")] public DocumentCollection[] documentGoListDLFJWZRK;
/// <summary>
/// 借用物资入库
/// </summary>
[Header("借用物资入库")] public DocumentCollection[] documentGoListJYWZRK;
/// <summary>
/// 单据按钮预制体
/// </summary>
public GameObject documentButtonPrefab;
/// <summary>
/// tog按钮父物体
/// </summary>
public Transform togParent;
/// <summary>
/// 验收单父物体
/// </summary>
public Transform acceptParent;
/// <summary>
/// tog按钮列表
/// </summary>
public List<Toggle> togList = new List<Toggle>();
/// <summary>
/// tog按钮列表高亮物体列表
/// </summary>
public List<Transform> HightObjToList = new List<Transform>();
/// <summary>
/// 单据列表
/// </summary>
public List<GameObject> documentGoList = new List<GameObject>();
/// <summary>
/// 单据
/// </summary>
public List<DocumentScript> documentScripts;
/// <summary>
/// 单据验收完毕保存按钮
/// </summary>
public Button btnSaveQuantityDocumentManagement;
/// <summary>
/// 单据填写保存按钮
/// </summary>
public Button btnSaveQuantityDocumentManagementTemp;
/// <summary>
/// 单据验收完毕是否已经保存
/// </summary>
private bool isSave = true;
/// <summary>
/// 单据确认是否已经保存
/// </summary>
private bool isSaveTemp = true;
/// <summary>
/// 单据确认管理器
/// </summary>
public List<UI_StampConfirmation> uI_StampConfirmations = new List<UI_StampConfirmation>();
/// <summary>
/// 单据确认输入框列表
/// </summary>
public List<TMP_InputField> InputFieldsConfirm = new List<TMP_InputField>();
/// <summary>
/// 单据确认输入框列表高亮框
/// </summary>
public List<GameObject> hightObjConfirm = new List<GameObject>();
/// <summary>
/// 入库单
/// </summary>
public WarehouseReceipt warehouseReceipt;
private Framework.Dto.InventoryReversalVoucherAnalyzer inventoryReversalVoucherAnalyzer;
#region
/// <summary>
/// 单据验收完毕保存按钮高亮物体
/// </summary>
public Transform btnSaveQuantityDocumentManagementHighlightObj;
/// <summary>
/// 单据填写保存按钮高亮物体
/// </summary>
public Transform btnSaveQuantityDocumentManagementTempHighlightObj;
/// <summary>
/// 单据显示按钮高亮物体
/// </summary>
public Transform btnShowToggleHighlightObj;
#endregion
/// <summary>
/// 是否填写单据验收
/// </summary>
bool isSaveInput = false;
private void Awake()
{
Instance = this;
btnSaveQuantityDocumentManagement = FindObjectByName<Button>("btnSaveQuantityDocumentManagement");
btnSaveQuantityDocumentManagementHighlightObj = FindObjectByName<Transform>("btnSaveQuantityDocumentManagementHighlightObj");
btnSaveQuantityDocumentManagementTemp = FindObjectByName<Button>("btnSaveQuantityDocumentManagementTemp");
btnSaveQuantityDocumentManagementTempHighlightObj = FindObjectByName<Transform>("btnSaveQuantityDocumentManagementTempHighlightObj");
btnShowToggleHighlightObj = FindObjectByName<Transform>("btnShowToggleHighlightObj");
}
// Start is called before the first frame update
void Start()
{
}
private void CheckAndDisplayMatchingSubject()
{
string examName = MotionEngine.GetModule<GlobalDataStorage>().ExamName;
if (string.IsNullOrEmpty(examName))
{
Debug.LogWarning("未获取到题目名称");
return;
}
// 检查是否包含"调拨入库"
if (examName.Contains("调拨物资入库"))
{
Debug.Log($"题目包含调拨入库,显示调拨入库相关单据");
// 显示调拨入库单据
documentCollections = documentGoListDBRK;
}
else if (examName.Contains("到货验收"))
{
Debug.Log($"题目包含到货验收,显示采购物资入库单据");
// 显示采购物资入库单据
documentCollections = purchaseDocumentCollections;
}
else if (examName.Contains("代保管物资出库"))
{
Debug.Log($"题目包含到货验收,显示代保管出库");
// 显示采购物资入库单据
documentCollections = documentGoListTC;
}
else if (examName.Contains("退出退役资产代保管入库作业") || examName.Contains("代保管物资入库")|| examName.Contains("退出退役代保管入库") )
{
Debug.Log($"题目包含到货验收,显示退出退役资产代保管入库作业");
// 显示采购物资入库单据
documentCollections = documentGoListTCYUDBGRK;
}
else if (examName.Contains("跨省调拨物资"))
{
Debug.Log($"题目包含到货验收,显示退出退役资产物资代保管出库作业");
// 显示采购物资入库单据
documentCollections = documentGoListKSDBWZ;
}
else if (examName.Contains("借用物资出库"))
{
documentCollections = documentGoListXSKBSJYWZ;
}
else if (examName.Contains("库存物资报废"))
{
documentCollections = documentGoListKCWZBF;
}
else if (examName.Contains("领用出库"))
{
documentCollections = documentGoListWZLYCK;
}
else if (examName.Contains("退料物资入库"))
{
documentCollections = documentGoListTLWZRK;
}
else if (examName.Contains("电缆分支箱跨地市物资调配"))
{
inventoryReversalVoucherAnalyzer = (Framework.Dto.InventoryReversalVoucherAnalyzer)MotionEngine.GetModule<GlobalDataStorage>().materialTaskObj;
if (inventoryReversalVoucherAnalyzer.formselection == "需求数量缺失")
{
var doc = documentGoListDLFZXKSWZDP.ToList();
doc.RemoveAt(1);
documentCollections = doc.ToArray();
}
else
{
var doc = documentGoListDLFZXKSWZDP.ToList();
doc.RemoveAt(0);
documentCollections = doc.ToArray();
}
}
else if (examName.Contains("重点物资排产计划制定"))
{
documentCollections = documentGoListDLZDWZPCJH;
}
else if (examName.Contains("废旧物资入库") || examName.Contains("不可用办理实物退库"))
{
documentCollections = documentGoListDLFJWZRK;
}
else if (examName.Contains("借用物资系统归还系统操作") || examName.Contains("借用物资入库"))
{
documentCollections = documentGoListJYWZRK;
}
}
bool isdown=false;
/// <summary>
/// 初始化
/// </summary>
public void Init()
{
CheckAndDisplayMatchingSubject();
toggleGroup = GetComponent<ToggleGroup>();
togParent = transform.Find("togParent");
acceptParent = transform.Find("acceptParent");
documentButtonPrefab = Resources.Load<GameObject>("Prefabs/单据/tog单据");
if (btnShowToggle != null)
{
btnShowToggle.onClick.AddListener(() =>
{
ShowToggle();
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("重点物资排产计划制定") && !isdown)
{
btnSaveQuantityDocumentManagement.gameObject.SetActive(false);
btnSaveQuantityDocumentManagementTemp.gameObject.SetActive(false);
if (!isdown)
{
isdown = true;
FileComponent.DownloadSingleFile("图纸及排产计划确认_答题卡1");
}
}
});
}
if (documentButtonPrefab == null)
{
return;
}
for (int i = 0; i < documentCollections.Length; i++)
{
//string[] _name = documentCollections[i].name.Split('_');
GenerateDocument(documentCollections[i].name);
}
////保存按钮
btnSaveQuantityDocumentManagement.onClick.AddListener(() =>
{
btnSaveQuantityDocumentManagement.enabled = false;
StartCoroutine(SaveQuantityDocumentManagement(btnSaveQuantityDocumentManagement.name));
});
btnSaveQuantityDocumentManagementTemp.onClick.AddListener(() =>
{
btnSaveQuantityDocumentManagementTemp.enabled = false;
isSaveInput = true;
StartCoroutine(SaveQuantityDocumentManagementTemp(btnSaveQuantityDocumentManagementTemp.name));
});
//单据生成后执行
Invoke(nameof(ExecuteAfterDocumentGeneration), 1);
}
/// <summary>
/// 保存按钮(单据验收完毕保存按钮)
/// </summary>
/// <returns></returns>
private IEnumerator SaveQuantityDocumentManagement(string btname)
{
List<UI_StampConfirmation> uI_StampConfirmations = UI_StampConfirmationManager.Instance.uI_StampConfirmations;
List<string> stampNames = new List<string>();
for (int i = uI_StampConfirmations.Count - 1; i >= 0; i--)
{
string IsChecked = uI_StampConfirmations[i].IsClick ? "true" : "false";
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName == "电缆分支箱跨地市物资调配" && inventoryReversalVoucherAnalyzer.formselection == "默认")
{
if (uI_StampConfirmations[i].name == "需求数量确认")
{
IsChecked = "true";
}
}
stampNames.Add(IsChecked);
}
yield return new WaitForSeconds(0.5f);
bool isMatch = MotionFramework.MotionEngine.GetModule<ProcessManager>().HandleClick(stampNames);
Debug.Log("单据验收完毕");
isSave = false;
btnSaveQuantityDocumentManagement.gameObject.SetActive(false);
btnSaveQuantityDocumentManagementHighlightObj.gameObject.SetActive(true);
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("不可用办理实物退库") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("废旧物资入库"))
{
LoadTriggerNextGuide("关闭");
GameObject weight = GameObject.Find("地磅-称重台");
weight.GetComponent<HighlightEffect>().highlighted = true;
GameObject weightpole = GameObject.Find("地磅-称重杆");
weightpole.GetComponent<HighlightEffect>().highlighted = true;
}
else
{
LoadTriggerNextGuide(btname);
}
}
/// <summary>
/// 保存按钮(单据填写保存按钮)
/// </summary>
/// <returns></returns>
private IEnumerator SaveQuantityDocumentManagementTemp(string btname)
{
List<string> stampNames = new List<string>();
for (int i = 0; i < InputFieldsConfirm.Count; i++)
{
stampNames.Add(InputFieldsConfirm[i].text);
}
yield return new WaitForSeconds(0.5f);
//单据确认
bool isMatch = MotionFramework.MotionEngine.GetModule<ProcessManager>().HandleClick(stampNames);
Debug.Log("单据确认完毕");
isSaveTemp = false;
btnSaveQuantityDocumentManagementTempHighlightObj.gameObject.SetActive(true);
btnSaveQuantityDocumentManagementTemp.gameObject.SetActive(false);
for (int i = 0; i < hightObjConfirm.Count; i++)
{
hightObjConfirm[i].SetActive(false);
}
LoadTriggerNextGuide(btname);
}
/// <summary>
/// 单据生成后执行
/// </summary>
private void ExecuteAfterDocumentGeneration()
{
UI_StampConfirmationManager.Instance.ExecuteAfterDocumentGeneration();
uI_StampConfirmations = FindObjectsOfType<UI_StampConfirmation>(true).ToList();
for (int i = 0; i < documentScripts.Count; i++)
{
for (int j = 0; j < documentScripts[i].tMP_InputFields.Count; j++)
{
if (documentCollections[i].isShow)
{
InputFieldsConfirm.Add(documentScripts[i].tMP_InputFields[j]);
}
}
}
}
/// <summary>
/// 显示单据
/// </summary>
/// <param name="name"></param>
public void ShowDocument(Toggle tog)
{
string _name = tog.name.Replace("Tog", "");
for (int i = 0; i < documentGoList.Count; i++)
{
documentGoList[i].SetActive(documentGoList[i].name.Contains(_name));
}
}
/// <summary>
/// 按钮显示
/// </summary>
public void ShowToggle()
{
for (int i = 0; i < togList.Count; i++)
{
togList[i].gameObject.SetActive(documentCollections[i].isShow);
}
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("代保管物资出库") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("领用出库"))
{
togList[0].isOn = false;
}
else
{
togList[0].isOn = true;
}
ShowDocument(togList[0]);
if (MotionEngine.GetModule<ProcessManager>().GetCurrentActionTitle() == "单据验收"|| MotionEngine.GetModule<ProcessManager>().GetCurrentActionTitle() == "分领导未签字校验")
{
btnSaveQuantityDocumentManagement.gameObject.SetActive(true);
}
if (MotionEngine.GetModule<ProcessManager>().GetCurrentActionTitle() == "单据确认")
{
btnSaveQuantityDocumentManagementTemp.gameObject.SetActive(true);
}
//btnSaveQuantityDocumentManagement.gameObject.SetActive(isSave);
//btnSaveQuantityDocumentManagementTemp.gameObject.SetActive(isSaveTemp);
LoadTriggerNextGuide("单据");
}
/// <summary>
/// 隐藏按钮显示
/// </summary>
/// <param name="name"></param>
public void IsShowTrue(string name)
{
for (int i = 0; i < documentCollections.Length; i++)
{
if (documentCollections[i].name.Contains(name))
{
documentCollections[i].isShow = true;
}
}
}
/// <summary>
/// 生成新的单据
/// </summary>
/// <param name="name"></param>
public void GenerateDocument(string name)
{
string[] _name = name.Split('_');
if (_name.Length > 1)
{
//生成按钮
GameObject go = Instantiate(documentButtonPrefab, togParent);
go.SetActive(false); //隐藏按钮
go.transform.name = "Tog" + _name[1];
Toggle tog = go.GetComponent<Toggle>();
if (tog != null && togParent != null)
{
togList.Add(tog);
Transform highlightObj = FindChildRecursively(tog.transform, "HighlightObj"); // tog.transform.Find("HighlightObj");//FindChildRecursively
if (highlightObj != null)
{
HightObjToList.Add(highlightObj);
highlightObj.transform.name = tog.name;
// 物体找到,可以进行相关操作
Debug.Log("找到 HighlightObj");
}
else
{
Debug.Log("未找到 HighlightObj");
}
tog.group = toggleGroup;
tog.onValueChanged.AddListener((bool isOn) =>
{
if (isOn)
{
Debug.Log(tog.name + "单据按钮被点击");
ShowDocument(tog);
HightObjToListFalse(tog.name);
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("代保管物资出库"))
{
TutorialGuideManager.Instance.TriggerNextGuide();
}
//LoadTriggerNextGuide();
}
});
tog.GetComponentInChildren<TextMeshProUGUI>().text = _name[1];
}
//生成单据
GameObject documentPrefab = Resources.Load<GameObject>("Prefabs/单据/" + _name[0] + "/" + _name[1]);
if (documentPrefab != null && acceptParent != null)
{
GameObject documentGo = Instantiate(documentPrefab, acceptParent);
documentGoList.Add(documentGo);
documentGo.transform.localPosition = Vector3.zero;
documentGo.transform.name = "Panel" + _name[1];
documentGo.SetActive(false);
DocumentScript documentScript = documentGo.GetComponent<DocumentScript>();
if (documentScript != null)
{
documentScripts.Add(documentScript);
}
Button btnClose = documentGo.transform.Find(_name[1] + "_btnClose").GetComponent<Button>();
if (btnClose != null)
{
btnClose.onClick.AddListener(() =>
{
for (int i = 0; i < togList.Count; i++)
{
togList[i].gameObject.SetActive(false);
documentGoList[i].SetActive(false);
}
btnSaveQuantityDocumentManagement.gameObject.SetActive(false);
btnSaveQuantityDocumentManagementTemp.gameObject.SetActive(false);
string str = MotionEngine.GetModule<ProcessManager>().GetCurrentActionTitle();
if (isSaveInput ||
str.Contains("数量清点") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("借用物资系统归还系统操作") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("借用物资入库") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("库存物资报废流程") ||
MotionEngine.GetModule<GlobalDataStorage>().ExamName.Contains("领用出库"))
{
LoadTriggerNextGuide(btnClose.name);
}
else
{
LoadTriggerNextGuide("关闭");
}
});
}
if (_name[1] == "入库单")
{
warehouseReceipt = documentGo.GetComponent<WarehouseReceipt>();
}
}
else
{
Debug.Log("未找到单据预制体:" + _name[0] + "/" + _name[1]);
}
}
else
{
Debug.Log("单据名称格式错误:" + name);
}
}
/// <summary>
/// 单据签字(外部调用)
/// </summary>
public void HightObjConfirmShow()
{
if (MotionFramework.MotionEngine.GetModule<ProcessManager>()._currentMode == ProcessMode.)
{
for (int i = 0; i < hightObjConfirm.Count; i++)
{
hightObjConfirm[i].SetActive(true);
}
btnSaveQuantityDocumentManagementTempHighlightObj.gameObject.SetActive(true);
}
}
/// <summary>
/// 入库单签字
/// </summary>
public void HightObjWarehouseReceiptShow()
{
if (MotionFramework.MotionEngine.GetModule<ProcessManager>()._currentMode == ProcessMode. && warehouseReceipt != null)
{
for (int i = 0; i < HightObjToList.Count; i++)
{
if (HightObjToList[i].name == "入库单")
{
HightObjToList[i].gameObject.SetActive(true);
}
}
}
}
/// <summary>
/// 隐藏按钮显示
/// </summary>
/// <param name="_name"></param>
public void HightObjToListFalse(string _name)
{
_name = _name.Replace("Tog", "");
for (int i = 0; i < HightObjToList.Count; i++)
{
if (HightObjToList[i].name.Contains(_name))
{
HightObjToList[i].gameObject.SetActive(false);
}
}
}
/// <summary>
/// 查找指定物体下对应名字的子物体
/// </summary>
/// <param name="parent"></param>
/// <param name="name"></param>
/// <returns></returns>
private Transform FindChildRecursively(Transform parent, string name)
{
foreach (Transform child in parent)
{
if (child.name == name)
return child;
Transform result = FindChildRecursively(child, name);
if (result != null)
return result;
}
return null;
}
}
/// <summary>
/// 单据
/// </summary>
[System.Serializable]
public class DocumentCollection
{
/// <summary>
/// 单据名称
/// </summary>
public string name;
/// <summary>
/// 显示(按钮是否显示,有的单据为操作过程中生成的单据,刚开始不显示,生成单据后才显示)
/// </summary>
public bool isShow;
}