236 lines
6.5 KiB
C#
236 lines
6.5 KiB
C#
using Adam;
|
||
using Components;
|
||
using MobileTerminal;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Utility;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author #AUTHOR#
|
||
//@create #CREATEDATE#
|
||
//@company #COMPANY#
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
|
||
public class MobileTerminalController : MonoBehaviour
|
||
{
|
||
//private string userViewUrl;
|
||
//private string tabelViewUrl;
|
||
public InputField number;
|
||
/// <summary>
|
||
/// 表记数据
|
||
/// </summary>
|
||
public Button outsideBtn;
|
||
/// <summary>
|
||
/// 用户数据
|
||
/// </summary>
|
||
public Button electricitBtn;
|
||
public Button backBtn;
|
||
public Button closeBtn;
|
||
|
||
public GameObject tapView;
|
||
public GameObject userView;
|
||
|
||
public Transform userContent;
|
||
public Transform tapContent;
|
||
public MobileTerminalTipsItem itemPrfab;
|
||
//[HideInInspector]
|
||
public UserViewData uData = new UserViewData();
|
||
public SingleUserData singleUserData = new SingleUserData();
|
||
|
||
//[HideInInspector]
|
||
public TableViewData tData = new TableViewData();
|
||
public SingleTableData singleTableData = new SingleTableData();
|
||
|
||
public JObject jbsx;
|
||
public JObject jbxx;
|
||
public List<JObject> jlzzxx = new List<JObject>();
|
||
|
||
public bool isOnLoad = false;
|
||
public Text requset;
|
||
|
||
// Use this for initialization
|
||
private void Start()
|
||
{
|
||
requset.text = "";
|
||
closeBtn.onClick.AddListener(() =>
|
||
{
|
||
UIManager.Instance.bottomCotroller.SwitchFirstPerson(true);
|
||
});
|
||
|
||
string uJson = FileUtil.ReadFromLocal("Local/用户视图.json");
|
||
uData = JsonConvert.DeserializeObject<UserViewData>(uJson);
|
||
string tJson = FileUtil.ReadFromLocal("Local/表记视图.json");
|
||
tData = JsonConvert.DeserializeObject<TableViewData>(uJson);
|
||
|
||
//userViewUrl = WebIPAdress.Instance.dicAdresses["用户视图"];
|
||
//tabelViewUrl = WebIPAdress.Instance.dicAdresses["表记视图"];
|
||
outsideBtn.onClick.AddListener(OnOutsideView);
|
||
electricitBtn.onClick.AddListener(OnElectricitView);
|
||
backBtn.onClick.AddListener(OnBack);
|
||
SwitchView(-1);
|
||
}
|
||
/// <summary>
|
||
/// 通过用户编号获取指定用户视图
|
||
/// </summary>
|
||
/// <param name="userID"></param>
|
||
/// <returns></returns>
|
||
public SingleUserData GetSingleUserDataByUserID(string userID)
|
||
{
|
||
SingleUserData singleUserDataTemp = new SingleUserData();
|
||
if (uData.data.data.Count > 0)
|
||
{
|
||
List<SingleUserData> users = uData.data.data;
|
||
for (int i = 0; i < users.Count; i++)
|
||
{
|
||
if (users[i].data[5].Contains(userID))
|
||
{
|
||
singleUserDataTemp.data = users[i].data;
|
||
}
|
||
}
|
||
}
|
||
return singleUserDataTemp;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过用户编号获取指定用户视图
|
||
/// </summary>
|
||
/// <param name="userID"></param>
|
||
/// <returns></returns>
|
||
public SingleTableData GetSingleTableDataByUserID(string userID)
|
||
{
|
||
SingleTableData singleTableDataTemp = new SingleTableData();
|
||
if (tData.data.data.Count > 0)
|
||
{
|
||
List<SingleTableData> users = tData.data.data;
|
||
for (int i = 0; i < users.Count; i++)
|
||
{
|
||
if (users[i].data[5].Contains(userID))
|
||
{
|
||
singleTableDataTemp.data = users[i].data;
|
||
}
|
||
}
|
||
}
|
||
return singleTableDataTemp;
|
||
}
|
||
|
||
public void OnUser()
|
||
{
|
||
if (userContent.childCount > 0)
|
||
{
|
||
for (int i = 0; i < userContent.childCount; i++)
|
||
{
|
||
Destroy(userContent.GetChild(i).gameObject);
|
||
}
|
||
}
|
||
isOnLoad = true;
|
||
string userID = ToolUtility.SubUserNum(number.text);
|
||
//string url = userViewUrl + userID;
|
||
//uData = await AsyncWebReq.Get<UserViewData>(url);
|
||
|
||
singleUserData = GetSingleUserDataByUserID(userID);
|
||
|
||
if (singleUserData.data == null)
|
||
{
|
||
StopCoroutine(WaitShowRequset(null));
|
||
StartCoroutine(WaitShowRequset("用户不存在"));
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < singleUserData.data.Count; i++)
|
||
{
|
||
MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, userContent);
|
||
itemTip.SetValue(singleUserData.data[i]);
|
||
}
|
||
SwitchView(0);
|
||
}
|
||
isOnLoad = false;
|
||
}
|
||
|
||
public void OnTable()
|
||
{
|
||
if (tapContent.childCount > 0)
|
||
{
|
||
for (int i = 0; i < tapContent.childCount; i++)
|
||
{
|
||
Destroy(tapContent.GetChild(i).gameObject);
|
||
}
|
||
}
|
||
isOnLoad = true;
|
||
string userID = ToolUtility.SubUserNum(number.text);
|
||
//string url = tabelViewUrl + userID;
|
||
//tData = await AsyncWebReq.Get<TableViewData>(url);
|
||
singleTableData = GetSingleTableDataByUserID(userID);
|
||
if (singleTableData.data == null)
|
||
{
|
||
StopCoroutine(WaitShowRequset(null));
|
||
StartCoroutine(WaitShowRequset("用户不存在"));
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < singleTableData.data.Count; i++)
|
||
{
|
||
MobileTerminalTipsItem itemTip = Instantiate(itemPrfab, tapContent);
|
||
itemTip.SetValue(singleTableData.data[i]);
|
||
}
|
||
SwitchView(1);
|
||
}
|
||
|
||
isOnLoad = false;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 用户数据
|
||
/// </summary>
|
||
public void OnElectricitView()
|
||
{
|
||
if (isOnLoad) return;
|
||
if (number.text == "") return;
|
||
OnUser();
|
||
|
||
}
|
||
/// <summary>
|
||
/// 表记数据
|
||
/// </summary>
|
||
public void OnOutsideView()
|
||
{
|
||
if (isOnLoad) return;
|
||
if (number.text == "") return;
|
||
OnTable();
|
||
|
||
}
|
||
|
||
private IEnumerator WaitShowRequset(string info)
|
||
{
|
||
requset.text = info;
|
||
yield return new WaitForSeconds(3f);
|
||
requset.text = "";
|
||
}
|
||
|
||
public void SwitchView(int index)
|
||
{
|
||
|
||
userView.SetActive(index == 0);
|
||
tapView.SetActive(index == 1);
|
||
if (index == 0 || index == 1)
|
||
{
|
||
backBtn.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
backBtn.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
public void OnBack()
|
||
{
|
||
SwitchView(-1);
|
||
}
|
||
}
|