CaoZuoRizhi.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Bitsplash.DatePicker;
  5. using LitJson;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class CaoZuoRizhi : MonoBehaviour
  9. {
  10. public UIScrollScript uiScroll;
  11. public GameObject go;
  12. List<GameObject> list = new List<GameObject>();
  13. long startl;
  14. long sendl;
  15. public DatePickerDropDown ds1;
  16. public DatePickerDropDown ds2;
  17. public void chooseA()
  18. {
  19. StartCoroutine(chooseYanChi(ds1.Label,(l)=> {
  20. startl=l;
  21. }));
  22. }
  23. public void chooseB()
  24. {
  25. StartCoroutine(chooseYanChi(ds2.Label, (l) => {
  26. sendl=l;
  27. }));
  28. }
  29. IEnumerator chooseYanChi(Text t,Action<long> callback)
  30. {
  31. yield return null;
  32. string dateString = t.text;
  33. Debug.Log("chooseYanChi===>"+ds1.Label.text);
  34. DateTime dateTime = DateTime.Parse(dateString);
  35. long timestamp = ((DateTimeOffset)dateTime).ToUnixTimeSeconds();
  36. Debug.Log("Timestamp: " + timestamp);
  37. callback.Invoke(timestamp);
  38. }
  39. public void sousuo()
  40. {
  41. RemoveAll();
  42. JsonData d =new JsonData();
  43. d["start_time"] =startl;
  44. d["end_time"] =sendl;
  45. d["page"] =1;
  46. d["size"] =MaxLiebiao;
  47. Debug.Log("sousuo==>"+d.ToJson());
  48. startinit=false;
  49. StartCoroutine(getreplist(d));
  50. }
  51. bool startinit=false;
  52. void OnEnable()
  53. {
  54. ds1.Label.text ="选择日期";
  55. ds2.Label.text ="选择日期";
  56. uiScroll.Init();
  57. RemoveAll();
  58. JsonData d =new JsonData();
  59. d["start_time"] =0;
  60. d["end_time"] =((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
  61. startl = 0;
  62. sendl =((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
  63. d["page"] =1;
  64. d["size"] =MaxLiebiao;
  65. startinit=false;
  66. StartCoroutine(getreplist(d));
  67. uiScroll.onUpdateItem -= ContentUpdateItem;
  68. uiScroll.onUpdateItem += ContentUpdateItem;
  69. uiScroll.onEatUpItem -= EatUpItem;
  70. uiScroll.onEatUpItem += EatUpItem;
  71. }
  72. private void EatUpItem()
  73. {
  74. if(nextdata!=null)
  75. StartCoroutine(getreplist(nextdata));
  76. nextdata=null;
  77. }
  78. private void ContentUpdateItem(GameObject item, int wrapIndex, int realIndex)
  79. {
  80. if (realIndex >= 0&&datamsg.Count>realIndex)
  81. {
  82. RiZhiItem xitem = item.GetComponent<RiZhiItem>();
  83. xitem.init(datamsg[realIndex]);
  84. item.SetActive(true);
  85. }
  86. else
  87. {
  88. item.SetActive(false);
  89. }
  90. }
  91. private void Awake() {
  92. list.Add(go);
  93. }
  94. public void RemoveAll()
  95. {
  96. datamsg=new List<JsonData>();
  97. }
  98. List<JsonData> datamsg =new List<JsonData>();
  99. int MaxLiebiao=11;
  100. public JsonData nextdata;
  101. public IEnumerator getreplist(JsonData jd)
  102. {
  103. int page =int.Parse( jd["page"].ToString());
  104. int total =int.Parse( jd["page"].ToString());
  105. Debug.Log("getreplist start");
  106. yield return StartCoroutine(DataManager.Instance.GetRePort(jd,(msg)=>{
  107. JsonData jd =JsonMapper.ToObject(msg);
  108. for (int i = list.Count; i < MaxLiebiao; i++)
  109. {
  110. GameObject n =GameObject.Instantiate(go,go.transform.parent);
  111. list.Add(n);
  112. }
  113. total=int.Parse( jd["data"]["page"]["total_page"].ToString());
  114. if(!startinit)
  115. {
  116. Debug.Log("总共"+int.Parse( jd["data"]["page"]["total_count"].ToString()));
  117. for (int i = 0; i < MaxLiebiao; i++)
  118. {
  119. if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i)
  120. {
  121. list[i].GetComponent<RiZhiItem>().init(jd["data"]["list"][i]);
  122. list[i].SetActive(true);
  123. datamsg.Add(jd["data"]["list"][i]);
  124. }else
  125. {
  126. list[i].SetActive(false);
  127. }
  128. }
  129. }
  130. else
  131. {
  132. for (int i = 0; i < MaxLiebiao; i++)
  133. {
  134. if(jd["data"]["list"].Count> i)
  135. {
  136. datamsg.Add(jd["data"]["list"][i]);
  137. }
  138. }
  139. }
  140. uiScroll.InitList(0, datamsg.Count);
  141. startinit=true;
  142. Debug.Log("getreplist end");
  143. }));
  144. if(page+1<=total)
  145. {
  146. jd["page"] = (page+1);
  147. nextdata = jd;
  148. // yield return getreplist(jd);
  149. }
  150. else
  151. {
  152. nextdata=null;
  153. }
  154. }
  155. }