You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
5.8 KiB
219 lines
5.8 KiB
8 months ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using TMPro;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using System.Linq;
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 岗位职级数据存储类(只获取一遍组织机构)
|
||
|
/// </summary>
|
||
|
public class PostsData
|
||
|
{
|
||
|
private static PostsData _Instance;
|
||
|
private PostsData() { }
|
||
|
public static PostsData Instance
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (_Instance == null)
|
||
|
{
|
||
|
_Instance = new PostsData();
|
||
|
}
|
||
|
return _Instance;
|
||
|
}
|
||
|
}
|
||
|
private List<Posts> AllData = new List<Posts>();
|
||
|
public List<Posts> GetOrgDatas()
|
||
|
{
|
||
|
lock (this)
|
||
|
{
|
||
|
return this.AllData;
|
||
|
}
|
||
|
}
|
||
|
public void SetData(List<Posts> datas)
|
||
|
{
|
||
|
lock (this)
|
||
|
{
|
||
|
foreach (var item in datas)
|
||
|
{
|
||
|
if (!AllData.Contains(item))
|
||
|
AllData.Add(item);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public class PostsLoadPanel : MonoBehaviour
|
||
|
{
|
||
|
public Toggle Top;
|
||
|
public Image ShowImage;
|
||
|
public Image HideImage;
|
||
|
public TMP_Text ShowOrgName;
|
||
|
public GameObject Main;
|
||
|
public Transform PostsParent;
|
||
|
public GameObject PostsItem;
|
||
|
[SerializeField]
|
||
|
public List<Posts> SelectDatas = new List<Posts>();
|
||
|
public Color NormalColor;
|
||
|
public Image NoneDataImage;
|
||
|
private OrgItemData lastOrgData = null;
|
||
|
private string PortsApi = "/api/Posts";
|
||
|
private List<Posts> AllResultData = new List<Posts>();
|
||
|
void Start()
|
||
|
{
|
||
|
if (AllResultData.Count == 0)
|
||
|
{
|
||
|
var Url = "";
|
||
|
if (HTTPRequestManager.Instance != null)
|
||
|
{
|
||
|
Url = $"{PortsApi}?PageNumber={1}&PageSize={10000}";
|
||
|
}
|
||
|
//向服务端请求数据
|
||
|
HTTPRequestManager.Instance.GetJson<List<Posts>>(Url, SkipPageSuccessed, SkipPageError);
|
||
|
}
|
||
|
//else
|
||
|
//{
|
||
|
// DataBind(AllResultData);
|
||
|
//}
|
||
|
Top.onValueChanged.AddListener(Top_ValueChanged);
|
||
|
}
|
||
|
private void Top_ValueChanged(bool IsOn)
|
||
|
{
|
||
|
Main.SetActive(IsOn);
|
||
|
ShowImage.gameObject.SetActive(IsOn);
|
||
|
HideImage.gameObject.SetActive(!IsOn);
|
||
|
if (lastOrgData != null)
|
||
|
{
|
||
|
AutoBind();
|
||
|
Main.SetActive(IsOn);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Main.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
public void OrgDataBind(OrgItemData organizationsData)
|
||
|
{
|
||
|
if (lastOrgData != organizationsData)
|
||
|
{
|
||
|
lastOrgData = organizationsData;
|
||
|
if (lastOrgData != null)
|
||
|
{
|
||
|
DataBind(AllResultData.Where(a => a.level == lastOrgData.level).ToList());
|
||
|
//AutoBind();
|
||
|
}
|
||
|
SelectDatas.Clear();
|
||
|
ShowOrgName.text = "请先选择组织机构选择";
|
||
|
ShowOrgName.color = NormalColor;
|
||
|
}
|
||
|
if (Top.isOn)
|
||
|
{
|
||
|
Top.isOn = false;
|
||
|
}
|
||
|
}
|
||
|
private void AutoBind()
|
||
|
{
|
||
|
StopAllCoroutines();
|
||
|
StartCoroutine(autoBind());
|
||
|
}
|
||
|
IEnumerator autoBind()
|
||
|
{
|
||
|
yield return new WaitForSeconds(0.1f);
|
||
|
float height = PostsParent.GetComponent<RectTransform>().sizeDelta.y < 330 ? PostsParent.GetComponent<RectTransform>().sizeDelta.y : 330;
|
||
|
Main.GetComponent<RectTransform>().sizeDelta = new Vector2(
|
||
|
Main.GetComponent<RectTransform>().sizeDelta.x, height);
|
||
|
}
|
||
|
|
||
|
private void DataBind(List<Posts> allResultData)
|
||
|
{
|
||
|
foreach (Transform item in PostsParent)
|
||
|
{
|
||
|
if (item != NoneDataImage.transform)
|
||
|
Destroy(item.gameObject);
|
||
|
}
|
||
|
if (allResultData.Count > 0)
|
||
|
{
|
||
|
NoneDataImage.gameObject.SetActive(false);
|
||
|
foreach (var item in allResultData)
|
||
|
{
|
||
|
GameObject go = Instantiate(PostsItem, PostsParent);
|
||
|
go.GetComponent<PostsItem>().DataBind(item, this);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
NoneDataImage.gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void SkipPageError(int code, string message)
|
||
|
{
|
||
|
//MessageNotifyBox.Instance.ShowDialogOK("获取岗位职级失败!");
|
||
|
Debug.LogError("获取岗位职级失败!");
|
||
|
}
|
||
|
|
||
|
private void SkipPageSuccessed(List<Posts> obj)
|
||
|
{
|
||
|
if (obj.Count > 0)
|
||
|
{
|
||
|
foreach (var item in obj)
|
||
|
{
|
||
|
AllResultData.Add(item);
|
||
|
//Debug.Log(item.Name);
|
||
|
}
|
||
|
}
|
||
|
//DataBind(AllResultData);
|
||
|
}
|
||
|
|
||
|
public void OnSelect(Posts data, bool IsOn)
|
||
|
{
|
||
|
if (IsOn)
|
||
|
{
|
||
|
if (!SelectDatas.Contains(data))
|
||
|
{
|
||
|
SelectDatas.Add(data);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (SelectDatas.Contains(data))
|
||
|
{
|
||
|
SelectDatas.Remove(data);
|
||
|
}
|
||
|
}
|
||
|
if (SelectDatas.Count > 0)
|
||
|
{
|
||
|
string showName = "";
|
||
|
foreach (var item in SelectDatas)
|
||
|
{
|
||
|
showName += item.Name;
|
||
|
if (SelectDatas.IndexOf(item) < SelectDatas.Count - 1)
|
||
|
showName += ",";
|
||
|
}
|
||
|
if (showName.Length >= 17)
|
||
|
{
|
||
|
showName = showName.Substring(0, 16) + "...";
|
||
|
}
|
||
|
ShowOrgName.text = showName;
|
||
|
ShowOrgName.color = Color.white;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ShowOrgName.text = "请先选择组织机构选择";
|
||
|
ShowOrgName.color = NormalColor;
|
||
|
}
|
||
|
}
|
||
|
public void Reset()
|
||
|
{
|
||
|
foreach (Transform item in PostsParent)
|
||
|
{
|
||
|
if (item.GetComponent<PostsItem>())
|
||
|
item.gameObject.GetComponent<PostsItem>().M_Toggle.isOn = false;
|
||
|
}
|
||
|
Top.isOn = false;
|
||
|
ShowOrgName.text = "请先选择组织机构选择";
|
||
|
ShowOrgName.color = NormalColor;
|
||
|
}
|
||
|
}
|