/** *Copyright? 2016 by Orient Information Technology Co.,Ltd *All rights reserved. *FileName: JiedaiFrom *Author: #AUTHOR# *Date: #DATE# *Description: 功能描述或者使用说明 *History: 修改版本记录 */ using System.Collections; using UnityEngine; using UnityEngine.UI;
using GameFramework; using UnityGameFramework.Runtime; using System.Collections.Generic; using DG.Tweening; using System;
namespace Demo {
/// <summary>
/// 智能接待系统 定时接待 UI逻辑
/// </summary>
public class JiedaiFrom : UIFormLogic
{
#region UI
public PanelCtl pcl1;
public JiedaiItem jdiem;
/// <summary>
/// 界面物体 middle\middle2\middle3
/// </summary>
public GameObject middleGO;
public GameObject middle2GO;
public GameObject middle3GO;
//任务列表更多
public Button middleGO_AddTask;
public GameObject middle4GO;
//历史接待页面
public GameObject goTaskList;
//public Button hisBtn;
//接待与历史接待 按钮显示与隐藏
public Image jiedaibtn1;
public Image jiedaibtn2;
public Image lishijiedaibtn1;
public Image lishijiedaibtn2;
//设置重要与取消重要接待
public Button setbtn;
public Button resbtn;
//m3标题
public InputField inp_text;
//m3标题提示不能为空
public Text tishi_title;
public TaskData temp;
//一开始设置未修改
//public bool isRevise = false;
//历史接待搜索按钮 类型
public Image btn_type;
//历史接待搜索按钮 状态
public Image btn_state;
[Header(" 下拉框选择 ")]
public Dropdown selfCheck;
public Dropdown sceneModel;
[Tooltip("时间选择")]
public Text year_text;
public Text month_text;
public Text day_text;
public Text hour_text;
/// <summary>
/// 判断数据的下表
/// </summary>
public int Datainedex;
#endregion
/// <summary>
///
/// </summary>
private JieDaiData m_JiedaiData;
//获取数据库接待的列表
private List<Task_Table> task_Tables;
[Header(" JiedaiItem 预制体 ")]
//接待JiedaiItem 接待任务列表的预制体
public GameObject jiedaiItemPrefab;
public Transform parentTrs;
//public Dropdown drop;
public static DateTime curSelectTime = DateTime.Now;
protected internal override void OnOpen(object userData)
{
base.OnOpen(userData);
curSelectTime = DateTime.Now;
//获取接待页面数据
m_JiedaiData = JieDaiData.GetIns();
//显示界面获取未执行任务列表
ShowTasksTo();
}
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
}
protected internal override void OnClose(object userData)
{
base.OnClose(userData);
}
//判断是重要 还是一般接待
private int type = -1;
//历史接待里的数据列表
private List<Dictionary<string, string>> dict_list;
//历史接待列表里的预制体
public GameObject prefab_info;
public Transform content_info;
private void OnEnable()
{
dict_list = new List<Dictionary<string, string>>();
//链接服务器
GetData.instance.Send_Task_Table_Msg(InitHisTaskData);
GetData.instance.Send_Task_Table_Msg(InitTaskData);
}
/// <summary>
/// 历史接待 数据 委托
/// </summary>
Action<object> action;
#region Ui方法
private void Start()
{
action = InitHisTaskData;
action = InitTaskData;
}
/// <summary>
/// 获取接待任务具体信息
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public Task_Table GetTask(string index)
{
for (int i = 0; i < task_Tables.Count; i++)
{
if (task_Tables[i].task_id == index)
{
return task_Tables[i];
}
}
return null;
}
private void Update()
{
}
//string year_Input;
//string moth_Input;
//string day_Input;
//public void OnBtn_search()
//{
// //year_Input = search_ipt_year.text;
// //moth_Input = search_ipt_moth.text;
// //day_Input = search_ipt_day.text;
// //send
// //GetData.instance.Send_Search_Msg_condition(year_Input, InitHisTaskData);
// //GetData.instance.Send_Search_Msg_condition(moth_Input, InitHisTaskData);
// //GetData.instance.Send_Search_Msg_condition(day_Input, InitHisTaskData);
//}
/// <summary>
/// 实例化 历史接待数据
/// </summary>
/// <param name="ob"></param>
void InitHisTaskData (object obj) {
task_Tables = (List<Task_Table>)obj;
for (int i = 0; i < task_Tables.Count; i++)
{
//生成预制体
GameObject instanObj = GameObject.Instantiate(prefab_info, content_info);
//序号
instanObj.transform.Find("Text_Id").GetComponent<Text>().text = Convert.ToString(i + 1);
//标题
instanObj.transform.Find("Text_information").GetComponent<Text>().text = task_Tables[i].task_title;
//完成状态
string msg = string.Empty;
if (task_Tables[i].execution_condition == "0")
{
msg = "已完成";
}
else
{
msg = "未完成";
}
instanObj.transform.Find("Text_taskStatus").GetComponent<Text>().text = msg;
任务时间
instanObj.transform.Find("Text_time").GetComponent<Text>().text = task_Tables[i].execution_time;
创建人
instanObj.transform.Find("Text_creatName").GetComponent<Text>().text = task_Tables[i].creator_name;
接待类型
string msg1 = string.Empty;
if (task_Tables[i].task_type == "0")
{
msg1 = "一般";
}
else
{
msg1 = "重要";
}
instanObj.transform.Find("Text_receptionType").GetComponent<Text>().text = msg1;
设备情况
string msg2 = string.Empty;
if (task_Tables[i].equipment_state == "0")
{
msg2 = "正常";
}
else
{
msg2 = "故障";
}
instanObj.transform.Find("Text_deviceStatus").GetComponent<Text>().text = msg2;
}
}
/// <summary>
/// 实例化 任务列表数据
/// </summary>
/// <param name="ob"></param>
void InitTaskData(object obj)
{
task_Tables = (List<Task_Table>)obj;
for (int i = 0; i < task_Tables.Count; i++)
{
//生成预制体
GameObject instanObj = GameObject.Instantiate(jiedaiItemPrefab, parentTrs);
//预制体的背景颜色
instanObj.transform.Find("Text_time").GetComponent<Text>().text = task_Tables[i].task_type;
JiedaiItem jiedaiItem = instanObj.GetComponent<JiedaiItem>();
if (task_Tables[i].task_type =="0")
{
jiedaiItem.bg1.enabled=true;
jiedaiItem.bg2.enabled = false;
}
else
{
jiedaiItem.bg1.enabled = false;
jiedaiItem.bg2.enabled = true;
}
//标题
instanObj.transform.Find("Text_title").GetComponent<Text>().text = task_Tables[i].task_title;
string time = task_Tables[i].execution_time;//任务时间
if (time.Length ==10)
{
DateTime tmptime = new DateTime();
try
{
tmptime = new DateTime(int.Parse(time.Substring(0, 4)), int.Parse(time.Substring(4, 2)), int.Parse(time.Substring(6, 2)), int.Parse(time.Substring(8, 2)), 0, 0);
}
catch (Exception )
{
Debug.Log("任务时间字符串转换时间错误; " + time);
}
任务年月日
instanObj.transform.Find("Text_year_month_day").GetComponent<Text>().text = string.Format("{0}-{1}-{2}", tmptime.Year,tmptime.Month,tmptime.Day);
任务小时
instanObj.transform.Find("Text_hour_min").GetComponent<Text>().text = string.Format("{0}:00{1}", tmptime.Hour, (tmptime.Hour > 12 ? "PM" : "AM"));
任务天数
int days;
if (tmptime.Month != DateTime.Now.Month || tmptime.Year != DateTime.Now.Year)
{
days = (tmptime - DateTime.Now).Days;
}
else
{
days = tmptime.Day - DateTime.Now.Day;
}
instanObj.transform.Find("Text_time").GetComponent<Text>().text = (days) <= 0 ? "今天" : days == 1 ? "明天" : days == 2 ? "后天" : days.ToString() + "天";
}
else
{
Debug.Log("任务时间格式长度不对");
}
//TaskData tmp = new TaskData(task_Tables[i]);
//jiedaiItem.InitData(tmp, i);
jiedaiItem.onClickAction = delegate (JiedaiItem item)
{
OnMore(item);
};
//jiedaiItem.OnMore(JiedaiItem jiedai) = delegate ( JiedaiItem ob) {
// jdiem = jiedaiItem;
//};
}
}
/// <summary>
/// 添加按钮
/// </summary>
public void OnAddButtonClick()
{
//打开Middle2 关闭 Middle
//if (m_JiedaiData.IsAddTask == false)
//{
m_JiedaiData.IsAddTask = true;
middleGO.SetActive(false);
middle2GO.SetActive(true);
// }
// else
//{
// Log.Error("接待任务正在Add中。IsAddTask=" + m_JiedaiData.IsAddTask);
//}
}
/// <summary>
/// 设置或取消重要接待
/// </summary>
/// <summary>
/// 下一步按钮
/// </summary>
public void OnNextButtonClick()
{
//关闭Middle2 显示Middle3
//if (m_JiedaiData.IsAddTask == true)
//{
middle2GO.SetActive(false);
middle3GO.SetActive(true);
//m_JiedaiData.AddTaskOne()
//}
// else
// {
// Log.Error("接待任务没有添加。IsAddTask=" + m_JiedaiData.IsAddTask);
// }
}
/// <summary>
///取消按钮
/// </summary>
public void OnCancelButtonClick()
{
//关闭Middle2 显示Middle
//if (m_JiedaiData.IsAddTask == true)
//{
middleGO.SetActive(true);
middle2GO.SetActive(false);
m_JiedaiData.IsAddTask = false;
//}
}
/// <summary>
///返回上一步
/// </summary>
public void OnBackCancelButtonClick()
{
//关闭Middle3 显示Middle2
middle2GO.SetActive(true);
middle3GO.SetActive(false);
}
/// <summary>
///完成按钮 提交所有填写数据
/// </summary>
public void OnFinishCancelButtonClick()
{
//判断标题不能为空
if (inp_text.text == "")
{
tishi_title.gameObject.SetActive(true);
//开始携程
StartCoroutine(waitTime(2));
}
else
{
TaskData data = new TaskData();
data.OpenTime = curSelectTime;
//把执行条件 开启展馆自检程序
//data.M_selfChecks = selfCheck.value;
//把模式id 开馆情景
// data.M_sceneTypes = sceneModel.value;
//把输入的标题赋给data.M_title
data.M_title = GameObject.FindGameObjectWithTag("task_title").GetComponent<Text>().text;
//把输入的详情赋给data.M_information
data.M_information = GameObject.FindGameObjectWithTag("task_describe").GetComponent<Text>().text;
//把面板3的数据清空
GameObject.FindGameObjectWithTag("task_title").transform.parent.GetComponent<InputField>().text = "";
GameObject.FindGameObjectWithTag("task_describe").transform.parent.GetComponent<InputField>().text = "";
//选择的类型存给任务列表
data.M_type = type;
//定义唯一下标
data.index = Datainedex;
type = 0;
//添加数据
m_JiedaiData.UnperformedTask.Add(data);
//把数据存到数据库里
GetData.instance.Adddate_Task_Table(ceshi, data.OpenTime.ToString("yyyy-MM-dd-hh"), data.M_selfChecks, data.M_sceneTypes, data.M_title, data.M_information, data.M_type.ToString());
ceshi(null);
}
}
void ceshi(object obj)
{
JieDaiData.GetIns().UpdateTaskData(DataManger.task_table_list);
ShowTasksTo();
Datainedex++;
//关闭Middle3 显示Middle
middleGO.SetActive(true);
middle3GO.SetActive(false);
tishi_title.gameObject.SetActive(false);
OnSetBtn();
}
public void UpdateTask(TaskData taskData)
{
middleGO_AddTask.gameObject.SetActive(true);
//请求更新 更新本地数据
JieDaiData.GetIns().UpdateTaskData(taskData);
//请求更新 更新数据库数据
ceshi(null);
}
//携程 提示文本几秒之后消失
IEnumerator waitTime(float x)
{
yield return new WaitForSeconds(x);
tishi_title.gameObject.SetActive(false);
}
/// <summary>
/// 任务列表数据逆序 冒泡
/// </summary>
public void DataReverse()
{
TaskData temp;
for (int i = 0; i < m_JiedaiData.UnperformedTask.Count - 1; i++)
{
for (int j = 0; j < m_JiedaiData.UnperformedTask.Count - i - 1; j++)
{
if (m_JiedaiData.UnperformedTask[j].index < m_JiedaiData.UnperformedTask[j + 1].index)
{
temp = m_JiedaiData.UnperformedTask[j];
m_JiedaiData.UnperformedTask[j] = m_JiedaiData.UnperformedTask[j + 1];
m_JiedaiData.UnperformedTask[j + 1] = temp;
}
}
}
}
//界面显示 隐藏 历史界面按钮
public void OnTaskListClick()
{
middleGO.SetActive(false);
middle2GO.SetActive(false);
middle3GO.SetActive(false);
middle4GO.SetActive(false);
//显示到历史接待
goTaskList.SetActive(true);
//显示或隐藏
jiedaibtn1.gameObject.SetActive(false);
jiedaibtn2.gameObject.SetActive(true);
lishijiedaibtn1.gameObject.SetActive(false);
lishijiedaibtn2.gameObject.SetActive(true);
//GetData.instance.Send_Task_Table_Msg(InitHisTaskData);
//-------------todo---赋值-----
}
/// <summary>
/// 更多按钮
/// </summary>
public void OnMore(JiedaiItem jiedai)
{
//更多界面 接待详情显示
middle4GO.SetActive(true);
//PanelCtl ctl = middle4GO.transform.GetComponent<PanelCtl>();
middleGO_AddTask.gameObject.SetActive(false);
}
/// <summary>
/// 确定按钮
/// </summary>
public void Sure()
{
middle4GO.SetActive(false);
middleGO_AddTask.gameObject.SetActive(true);
}
/// <summary>
/// 修改按钮 获取修改后的数据
/// </summary>
public void Revise()
{
middle4GO.SetActive(false);
middleGO_AddTask.gameObject.SetActive(true);
}
//任务接待界面 按钮
public void OnTaskListClick1()
{
middleGO.SetActive(true);
//显示或隐藏
goTaskList.SetActive(false);
jiedaibtn1.gameObject.SetActive(true);
jiedaibtn2.gameObject.SetActive(false);
lishijiedaibtn1.gameObject.SetActive(true);
lishijiedaibtn2.gameObject.SetActive(false);
middle4GO.SetActive(false);
//-------------todo---赋值-----
}
public void OnSetBtn()
{
//设置重要接待
setbtn.gameObject.SetActive(false);
resbtn.gameObject.SetActive(true);
type = 1;
}
public void OnResBtn()
{
//取消重要接待
setbtn.gameObject.SetActive(true);
resbtn.gameObject.SetActive(false);
type = 0;
}
#endregion
/// <summary>
/// 定时接待任务显示在UI上面
/// 一个函数一个功能
/// </summary>
private void ShowTasksTo()
{
//逆序的方法Reverse()
DataReverse();
int count = m_JiedaiData.UnperformedTask.Count;
TaskData[] tempTasks = m_JiedaiData.UnperformedTask.ToArray();
for (int i = 0; i < count; i++)
{
GameObject go = null;
if (i < parentTrs.childCount)
{
go = parentTrs.GetChild(i).gameObject;
}
else
{
go = GameObject.Instantiate(jiedaiItemPrefab, parentTrs);
JiedaiItem item = go.GetComponent<JiedaiItem>();
if (item != null)
{
item.anbtn.onClick.AddListener(item.OnButtonClick);
}
}
go.SetActive(true);
JiedaiItem jiedaiItem = go.GetComponent<JiedaiItem>();
jiedaiItem.InitData(tempTasks[i], i);
jiedaiItem.onClickAction = delegate (JiedaiItem item)
{
OnMore(item);
};
}
if (parentTrs.childCount > count)
{
for (int i = count; i < parentTrs.childCount; i++)
{
parentTrs.GetChild(i).gameObject.SetActive(false);
}
}
}
//跳转回首页
public void OnLoginButtonClick()
{
//连接数据库 查询值返回结果
StarForce.GameEntry.UI.CloseUIForm(UIForm);
StarForce.GameEntry.UI.OpenUIForm(UIFormPath.INDEXFROM, "Login");
//判断列表里最近的日期
for (int i = 0; i < m_JiedaiData.UnperformedTask.Count - 2; i++)
{
if (m_JiedaiData.UnperformedTask[i].OpenTime < m_JiedaiData.UnperformedTask[i + 1].OpenTime)
{
temp = m_JiedaiData.UnperformedTask[i];
}
else
{
temp = m_JiedaiData.UnperformedTask[i + 1];
}
}
if (m_JiedaiData.UnperformedTask.Count == 1)
{
temp = m_JiedaiData.UnperformedTask[0];
}
if (m_JiedaiData.UnperformedTask.Count == 2)
{
if (m_JiedaiData.UnperformedTask[0].OpenTime < m_JiedaiData.UnperformedTask[1].OpenTime)
{
temp = m_JiedaiData.UnperformedTask[0];
}
else
{
temp = m_JiedaiData.UnperformedTask[1];
}
}
//this.transform.parent.Find("IndexFrom(Clone)").GetComponent<IndexFrom>().Set(temp);
}
/// <summary>
/// 判断开机时间距离当前的时间
/// </summary>
/// <param name="open"></param>
/// <returns></returns>
//string ToTime(System.DateTime open)
//{
// string str = "";
// System.TimeSpan tmp = open - System.DateTime.Now;
// switch (tmp.Days)
// {
// case 1:
// str = "明天";
// break;
// case 2:
// str = "后天";
// break;
// default:
// str = tmp.Days + "天";
// break;
// }
// return str;
//}
/// <summary>
/// 判断选择时间是上午还是下午
/// </summary>
void AddTaskOne()
{
//System.DateTime dateTime = new System.DateTime("")
}
//点击按钮左移
public void OnMoveonLeftClick()
{
parentTrs.transform.DOLocalMove(new Vector3(parentTrs.transform.localPosition.x + 220, 0, 0), 0.5f).OnComplete(() => { });
}
//点击按钮右移
public void OnMoveonRightClick()
{
parentTrs.transform.DOLocalMove(new Vector3(parentTrs.transform.localPosition.x - 220, 0, 0), 0.5f).OnComplete(() => { });
}
}
}
|