123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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<GameObject> list = new List<GameObject>();
- 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<long> 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<RiZhiItem>();
- xitem.init(datamsg[realIndex]);
- item.SetActive(true);
- }
- else
- {
- item.SetActive(false);
- }
- }
- private void Awake() {
-
- list.Add(go);
- }
- public void RemoveAll()
- {
- datamsg=new List<JsonData>();
- }
- List<JsonData> datamsg =new List<JsonData>();
- 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<RiZhiItem>().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;
- }
-
- }
- }
|