using Components;
using JData;
using OData;
using Org.BouncyCastle.Asn1.Crmf;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json;
//============================================================
//支持中文,文件使用UTF-8编码
//@author YangHua
//@create 20230914
//@company Adam
//
//@description:工作卡控制器
//============================================================
namespace Adam
{
public class JobCardController : MonoBehaviour
{
//private string nameAndAdressUrl;
//private string aqcsAndFxdfxUrl;
public InputField userNum;
///
/// 用户编号
///
public InputField[] userIDs;
///
/// 客户名称
///
public InputField[] userNames;
///
/// 工作地点
///
public InputField[] workSpace;
///
/// 注意事项及安全措施
///
public Button[] aqcss;
///
/// 现场风险点分析
///
public InputField[] fxdfx;
///
/// 打钩框
///
public Toggle[] toggles;
public GameObject jobCardPanel;
public GameObject jobChoiceQuestionPanel;
public OptionItem optionItemPrefab;
public Transform optionItemContent;
private Dictionary tiMuAndOption = new Dictionary();
public Text optionTitleText;
///
/// 风险点分析
///
public Button RiskPointAnalysisBtn;
///
/// 安全措施
///
public Button SafetyMeasuresBtn;
///
/// 关闭按钮
///
public Button closeBtn;
public JobCardData jData = new JobCardData();
// Use this for initialization
private void Start()
{
string jJson = FileUtil.ReadFromLocal("Local/姓名和地址.json");
jData = JsonConvert.DeserializeObject(jJson);
for (int i = 0; i < userIDs.Length; i++)
{
int index = i;
userIDs[index].onSubmit.AddListener((string numb) =>
{
GetValue(numb, index);
});
}
RiskPointAnalysisBtn.onClick.AddListener(() =>
{
OnClick();
});
for (int i = 0; i < aqcss.Length; i++)
{
int index = i;
aqcss[index].onClick.AddListener(() =>
{
aqcss[index].transform.GetChild(0).GetComponent().text = "";
});
}
closeBtn.onClick.AddListener(() =>
{
UIManager.Instance.bottomCotroller.SwitchFirstPerson(true);
});
GetAQCS();
jobCardPanel.SetActive(false);
jobChoiceQuestionPanel.SetActive(false);
}
//private void Update()
//{
// if (Input.GetKeyDown("t"))
// {
// Debug.Log(AddScore().ToString());
// }
//}
public DataItem GetCurrentUserInfoByUserNub(string userNub)
{
for (int i = 0; i < jData.data.data.Count; i++)
{
if (jData.data.data[i].id.Contains(userNub))
return jData.data.data[i];
}
return null;
}
public void GetValue(string numb, int _index)
{
//nameAndAdressUrl = WebIPAdress.Instance.dicAdresses["姓名和地址"];
//string _url = nameAndAdressUrl + numb;
//JobCardData jData = await AsyncWebReq.Get(_url);
DataItem temp = GetCurrentUserInfoByUserNub(numb);
if (temp != null)
{
userNames[_index].text = temp.name;
workSpace[_index].text = temp.adress;
}
}
///
/// 0- 风险点,1-安全措施
///
///
public void OnClick()
{
jobChoiceQuestionPanel.SetActive(true);
optionTitleText.text = "注意事项及安全措施";
//GetAQCS();
}
///
/// 安全措施
///
///
private void GetAQCS()
{
if (optionItemContent.childCount == 0)
{
//aqcsAndFxdfxUrl = WebIPAdress.Instance.dicAdresses["安全措施和风险点分析"];
//AQCS od = await AsyncWebReq.Get(aqcsAndFxdfxUrl);
string json = FileUtil.ReadFromLocal("Local/安全措施和风险点分析.json");
AQCS od = JsonConvert.DeserializeObject(json);
for (int i = 0; i < od.data.list.Count; i++)
{
int index = i;
string keyTemp = od.data.list[index].key;
string valueTemp = od.data.list[index].value;
fxdfx[index].text = keyTemp;
tiMuAndOption.Add(keyTemp, valueTemp);
}
for (int i = 0; i < od.data.valueList.Count; i++)
{
int index = i;
OptionItem optionItemTemp = Instantiate(optionItemPrefab, optionItemContent);
string infoTemp = od.data.valueList[index];
index += 1;
optionItemTemp.SetValue(index.ToString(), infoTemp);
optionItemTemp.selfBtn.onClick.AddListener(() =>
{
OnOptionItemClick(infoTemp);
});
}
}
}
///
/// 添加分数
///
public int AddScore()
{
int score = 0;
int inputUserNum = int.Parse(userNum.text);
if (inputUserNum >= 1)
{
score += 3;
}
for (int j = 0; j < fxdfx.Length; j++)
{
string fxdfxTemp = fxdfx[j].text;
string aqcs = aqcss[j].transform.GetChild(0).GetComponent().text;
if (!string.IsNullOrEmpty(fxdfxTemp))
{
if (tiMuAndOption[fxdfxTemp].Equals(aqcs))
{
score += 1;
}
}
}
return score;
}
private void OnOptionItemClick(string info)
{
for (int i = 0; i < aqcss.Length; i++)
{
int index = i;
Text temp = aqcss[index].transform.GetChild(0).GetComponent();
if (temp.text == "")
{
temp.text = info;
break;
}
}
}
public timuAndOptoin hide()
{
timuAndOptoin timuAnd = new timuAndOptoin();
timuAnd.keyValuePairs = new Dictionary(tiMuAndOption);
timuAnd.userID = new List();
timuAnd.userName = new List();
timuAnd.workSpace = new List();
timuAnd.aqcss = new List();
timuAnd.fxdfx = new List();
timuAnd.bools = new List();
timuAnd.userSum = userNum.text;
for (int i = 0; i < userIDs.Length; i++)
{
timuAnd.userID.Add(userIDs[i].text);
}
for (int i = 0; i < userNames.Length; i++)
{
timuAnd.userName.Add(userNames[i].text);
}
for (int i = 0; i < workSpace.Length; i++)
{
timuAnd.workSpace.Add(workSpace[i].text);
}
for (int i = 0; i < aqcss.Length; i++)
{
timuAnd.aqcss.Add(aqcss[i].GetComponentInChildren().text);
}
for (int i = 0; i < fxdfx.Length; i++)
{
timuAnd.fxdfx.Add(fxdfx[i].text);
}
for (int i = 0; i < toggles.Length; i++)
{
timuAnd.bools.Add(toggles[i].isOn);
}
return timuAnd;
}
public void show(timuAndOptoin timuAnd)
{
for (int i = 0; i < userIDs.Length; i++)
{
userIDs[i].text = timuAnd.userID[i];
}
for (int i = 0; i < userNames.Length; i++)
{
userNames[i].text = timuAnd.userName[i];
}
for (int i = 0; i < workSpace.Length; i++)
{
workSpace[i].text = timuAnd.workSpace[i];
}
for (int i = 0; i < aqcss.Length; i++)
{
aqcss[i].GetComponentInChildren().text = timuAnd.aqcss[i];
}
for (int i = 0; i < fxdfx.Length; i++)
{
fxdfx[i].text = timuAnd.fxdfx[i];
}
for (int i = 0; i < toggles.Length; i++)
{
toggles[i].isOn = timuAnd.bools[i];
}
userNum.text = timuAnd.userSum;
}
}
}