using System; using System.Collections; using System.Collections.Generic; using Bitsplash.DatePicker; using LitJson; using UnityEngine; using UnityEngine.UI; public class CaoZuoRizhi : MonoBehaviour { public UIScrollScript uiScroll; public GameObject go; List list = new List(); long startl; long sendl; public DatePickerDropDown ds1; public DatePickerDropDown ds2; public void chooseA() { StartCoroutine(chooseYanChi(ds1.Label,(l)=> { startl=l; })); } public void chooseB() { StartCoroutine(chooseYanChi(ds2.Label, (l) => { sendl=l; })); } IEnumerator chooseYanChi(Text t,Action callback) { yield return null; string dateString = t.text; Debug.Log("chooseYanChi===>"+ds1.Label.text); DateTime dateTime = DateTime.Parse(dateString); long timestamp = ((DateTimeOffset)dateTime).ToUnixTimeSeconds(); Debug.Log("Timestamp: " + timestamp); callback.Invoke(timestamp); } public void sousuo() { RemoveAll(); JsonData d =new JsonData(); d["start_time"] =startl; d["end_time"] =sendl; d["page"] =1; d["size"] =MaxLiebiao; Debug.Log("sousuo==>"+d.ToJson()); startinit=false; StartCoroutine(getreplist(d)); } bool startinit=false; void OnEnable() { ds1.Label.text ="选择日期"; ds2.Label.text ="选择日期"; uiScroll.Init(); RemoveAll(); JsonData d =new JsonData(); d["start_time"] =0; d["end_time"] =((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); startl = 0; sendl =((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); d["page"] =1; d["size"] =MaxLiebiao; startinit=false; StartCoroutine(getreplist(d)); uiScroll.onUpdateItem -= ContentUpdateItem; uiScroll.onUpdateItem += ContentUpdateItem; uiScroll.onEatUpItem -= EatUpItem; uiScroll.onEatUpItem += EatUpItem; } private void EatUpItem() { if(nextdata!=null) StartCoroutine(getreplist(nextdata)); nextdata=null; } private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex) { if (realIndex >= 0&&datamsg.Count>realIndex) { RiZhiItem xitem = item.GetComponent(); xitem.init(datamsg[realIndex]); item.SetActive(true); } else { item.SetActive(false); } } private void Awake() { list.Add(go); } public void RemoveAll() { datamsg=new List(); } List datamsg =new List(); int MaxLiebiao=11; public JsonData nextdata; public IEnumerator getreplist(JsonData jd) { int page =int.Parse( jd["page"].ToString()); int total =int.Parse( jd["page"].ToString()); Debug.Log("getreplist start"); yield return StartCoroutine(DataManager.Instance.GetRePort(jd,(msg)=>{ JsonData jd =JsonMapper.ToObject(msg); for (int i = list.Count; i < MaxLiebiao; i++) { GameObject n =GameObject.Instantiate(go,go.transform.parent); list.Add(n); } total=int.Parse( jd["data"]["page"]["total_page"].ToString()); if(!startinit) { Debug.Log("总共"+int.Parse( jd["data"]["page"]["total_count"].ToString())); for (int i = 0; i < MaxLiebiao; i++) { if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i) { list[i].GetComponent().init(jd["data"]["list"][i]); list[i].SetActive(true); datamsg.Add(jd["data"]["list"][i]); }else { list[i].SetActive(false); } } } else { for (int i = 0; i < MaxLiebiao; i++) { if(jd["data"]["list"].Count> i) { datamsg.Add(jd["data"]["list"][i]); } } } uiScroll.InitList(0, datamsg.Count); startinit=true; Debug.Log("getreplist end"); })); if(page+1<=total) { jd["page"] = (page+1); nextdata = jd; // yield return getreplist(jd); } else { nextdata=null; } } }