302 lines
9.4 KiB
C#
302 lines
9.4 KiB
C#
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;
|
||
/// <summary>
|
||
/// 用户编号
|
||
/// </summary>
|
||
public InputField[] userIDs;
|
||
/// <summary>
|
||
/// 客户名称
|
||
/// </summary>
|
||
public InputField[] userNames;
|
||
/// <summary>
|
||
/// 工作地点
|
||
/// </summary>
|
||
public InputField[] workSpace;
|
||
/// <summary>
|
||
/// 注意事项及安全措施
|
||
/// </summary>
|
||
public Button[] aqcss;
|
||
/// <summary>
|
||
/// 现场风险点分析
|
||
/// </summary>
|
||
public InputField[] fxdfx;
|
||
/// <summary>
|
||
/// 打钩框
|
||
/// </summary>
|
||
public Toggle[] toggles;
|
||
|
||
public GameObject jobCardPanel;
|
||
public GameObject jobChoiceQuestionPanel;
|
||
public OptionItem optionItemPrefab;
|
||
public Transform optionItemContent;
|
||
private Dictionary<string, string> tiMuAndOption = new Dictionary<string, string>();
|
||
|
||
public Text optionTitleText;
|
||
/// <summary>
|
||
/// 风险点分析
|
||
/// </summary>
|
||
public Button RiskPointAnalysisBtn;
|
||
/// <summary>
|
||
/// 安全措施
|
||
/// </summary>
|
||
public Button SafetyMeasuresBtn;
|
||
|
||
/// <summary>
|
||
/// 关闭按钮
|
||
/// </summary>
|
||
public Button closeBtn;
|
||
|
||
public JobCardData jData = new JobCardData();
|
||
|
||
|
||
// Use this for initialization
|
||
private void Start()
|
||
{
|
||
|
||
string jJson = FileUtil.ReadFromLocal("Local/姓名和地址.json");
|
||
jData = JsonConvert.DeserializeObject<JobCardData>(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>().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<JobCardData>(_url);
|
||
DataItem temp = GetCurrentUserInfoByUserNub(numb);
|
||
if (temp != null)
|
||
{
|
||
userNames[_index].text = temp.name;
|
||
workSpace[_index].text = temp.adress;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 0- 风险点,1-安全措施
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
public void OnClick()
|
||
{
|
||
jobChoiceQuestionPanel.SetActive(true);
|
||
optionTitleText.text = "注意事项及安全措施";
|
||
//GetAQCS();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 安全措施
|
||
/// </summary>
|
||
/// <param name="name"></param>
|
||
private void GetAQCS()
|
||
{
|
||
if (optionItemContent.childCount == 0)
|
||
{
|
||
//aqcsAndFxdfxUrl = WebIPAdress.Instance.dicAdresses["安全措施和风险点分析"];
|
||
//AQCS od = await AsyncWebReq.Get<AQCS>(aqcsAndFxdfxUrl);
|
||
|
||
string json = FileUtil.ReadFromLocal("Local/安全措施和风险点分析.json");
|
||
AQCS od = JsonConvert.DeserializeObject<AQCS>(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);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加分数
|
||
/// </summary>
|
||
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>().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<Text>();
|
||
if (temp.text == "")
|
||
{
|
||
temp.text = info;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
public timuAndOptoin hide()
|
||
{
|
||
timuAndOptoin timuAnd = new timuAndOptoin();
|
||
timuAnd.keyValuePairs = new Dictionary<string, string>(tiMuAndOption);
|
||
timuAnd.userID = new List<string>();
|
||
timuAnd.userName = new List<string>();
|
||
timuAnd.workSpace = new List<string>();
|
||
timuAnd.aqcss = new List<string>();
|
||
timuAnd.fxdfx = new List<string>();
|
||
timuAnd.bools = new List<bool>();
|
||
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>().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>().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;
|
||
}
|
||
}
|
||
}
|