上海虹口龙之梦项目
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.
 
 
 
 

168 lines
6.4 KiB

using System;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class SafeguardTablePanel : UIView
{
public GameObject Item;
public Button AddButton;
public Button SaveButton;
public Toggle SHLQToggle;
public Toggle ZQBZToggle;
public Toggle TXBZToggle;
private string getUrl = null;
private string postUrl = null;
public LogisticsSafeguards Data = new LogisticsSafeguards()
{
Safeguards = new List<LogisticsSafeguard>()
};
public override void Awake()
{
base.Awake();
Item = Find("Scroll View/Viewport/Content/Item");
AddButton = Find<Button>("Bottom/AddButton");
SaveButton = Find<Button>("Bottom/SaveButton");
SHLQToggle = Find<Toggle>("TitleBar/SHLQ");
ZQBZToggle = Find<Toggle>("TitleBar/ZQBZ");
TXBZToggle = Find<Toggle>("TitleBar/TXBZ");
AddButton.OnClickAsObservable()
.Subscribe(_ => NewItem());
SaveButton.OnClickAsObservable()
.Subscribe(_ => SaveData());
SHLQToggle.OnValueChangedAsObservable()
.Subscribe(value =>
{
if (value)
{
//url = Application.streamingAssetsPath + "/LianQinBaoZhang/SheHuiLianQin.json";
getUrl = HttpManager.Instance.GetSocialJointServices;
postUrl = HttpManager.Instance.PostSocialJointServices;
GetData();
}
}).AddTo(gameObject);
ZQBZToggle.OnValueChangedAsObservable()
.Subscribe(value =>
{
if (value)
{
//url = Application.streamingAssetsPath + "/LianQinBaoZhang/ZhanQinBaoZhang.json";
getUrl = HttpManager.Instance.GetCombatSupport;
postUrl = HttpManager.Instance.PostCombatSupport;
GetData();
}
}).AddTo(gameObject);
TXBZToggle.OnValueChangedAsObservable()
.Subscribe(value =>
{
if (value)
{
//url = Application.streamingAssetsPath + "/LianQinBaoZhang/TongXinBaoZhang.json";
getUrl = HttpManager.Instance.GetCommunicationSupport;
postUrl = HttpManager.Instance.PostCommunicationSupport;
GetData();
}
}).AddTo(gameObject);
}
private void SaveData()
{
Data.Safeguards.Clear();
foreach (Transform t in Item.transform.parent)
{
if (t.gameObject.activeSelf)
{
LogisticsSafeguardReactive tempdata = new LogisticsSafeguardReactive();
var DWMC = t.Find("Infos/UnitName").GetComponent<Text>();
var DWDZ = t.Find("Infos/Address").GetComponent<Text>();
var FR = t.Find("Infos/JuridicalPerson").GetComponent<Text>();
var DH = t.Find("Infos/Phone").GetComponent<Text>();
var JSRY = t.Find("Infos/PersonCount").GetComponent<Text>();
var YSC = t.Find("Infos/TruckCount").GetComponent<Text>();
var BZ = t.Find("Infos/Remark").GetComponent<Text>();
var BZP = t.Find("Infos/SecurityGoods").GetComponent<Text>();
var BZNL = t.Find("Infos/SupportCapability").GetComponent<Text>();
var KCL = t.Find("Infos/Inventory").GetComponent<Text>();
tempdata.Id.Value = t.gameObject.name;
tempdata.UnitName.Value = DWMC.text;
tempdata.Address.Value = DWDZ.text;
tempdata.JuridicalPerson.Value = FR.text;
tempdata.Phone.Value = DH.text;
tempdata.PersonCount.Value = JSRY.text;
tempdata.TruckCount.Value = YSC.text;
tempdata.Remark.Value = BZ.text;
tempdata.SecurityGoods.Value = BZP.text;
tempdata.SupportCapability.Value = BZNL.text;
tempdata.Inventory.Value = KCL.text;
Data.Safeguards.Add(tempdata.GetData());
}
}
Debug.Log(postUrl);
HttpManager.Instance.Post(postUrl, Data);
}
private void NewItem()
{
var table = Instantiate(Item);
table.SetActive(true);
table.name = $"Safeguard{Guid.NewGuid()}";
table.transform.SetParent(Item.transform.parent, false);
}
private void GetData()
{
ClearList();
HttpManager.Instance.Get<LogisticsSafeguards>(getUrl, data =>
{
Data = data;
foreach (var tempdata in Data.Safeguards)
{
var table = GameObject.Instantiate(Item);
table.SetActive(true);
table.transform.SetParent(Item.transform.parent, false);
table.name = tempdata.Id;
var DWMC = table.transform.Find("Infos/UnitName").GetComponent<Text>();
var DWDZ = table.transform.Find("Infos/Address").GetComponent<Text>();
var FR = table.transform.Find("Infos/JuridicalPerson").GetComponent<Text>();
var DH = table.transform.Find("Infos/Phone").GetComponent<Text>();
var JSRY = table.transform.Find("Infos/PersonCount").GetComponent<Text>();
var YSC = table.transform.Find("Infos/TruckCount").GetComponent<Text>();
var BZ = table.transform.Find("Infos/Remark").GetComponent<Text>();
var BZP = table.transform.Find("Infos/SecurityGoods").GetComponent<Text>();
var BZNL = table.transform.Find("Infos/SupportCapability").GetComponent<Text>();
var KCL = table.transform.Find("Infos/Inventory").GetComponent<Text>();
DWMC.text = tempdata.UnitName;
DWDZ.text = tempdata.Address;
FR.text = tempdata.JuridicalPerson;
DH.text = tempdata.Phone;
JSRY.text = tempdata.PersonCount;
YSC.text = tempdata.TruckCount;
BZ.text = tempdata.Remark;
BZP.text = tempdata.SecurityGoods;
BZNL.text = tempdata.SupportCapability;
KCL.text = tempdata.Inventory;
}
});
}
private void ClearList()
{
foreach (Transform t in Item.transform.parent)
{
if (t.gameObject.activeSelf)
{
GameObject.Destroy(t.gameObject);
}
}
}
}