CaoZuoRizhi.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. Debug.Log("wrapIndex==>"+wrapIndex);
  83. Debug.Log("realIndex==>"+realIndex);
  84. RiZhiItem xitem = item.GetComponent<RiZhiItem>();
  85. xitem.init(datamsg[realIndex]);
  86. item.SetActive(true);
  87. }
  88. else
  89. {
  90. item.SetActive(false);
  91. }
  92. }
  93. private void Awake() {
  94. list.Add(go);
  95. }
  96. public void RemoveAll()
  97. {
  98. uiScroll.Init();
  99. nextdata=null;
  100. datamsg=new List<JsonData>();
  101. }
  102. List<JsonData> datamsg =new List<JsonData>();
  103. int MaxLiebiao=11;
  104. public JsonData nextdata;
  105. public IEnumerator getreplist(JsonData jd)
  106. {
  107. int page =int.Parse( jd["page"].ToString());
  108. int total =int.Parse( jd["page"].ToString());
  109. Debug.Log("getreplist start");
  110. yield return StartCoroutine(DataManager.Instance.GetRePort(jd,(msg)=>{
  111. JsonData jd =JsonMapper.ToObject(msg);
  112. for (int i = list.Count; i < MaxLiebiao; i++)
  113. {
  114. GameObject n =GameObject.Instantiate(go,go.transform.parent);
  115. list.Add(n);
  116. }
  117. total=int.Parse( jd["data"]["page"]["total_page"].ToString());
  118. if(!startinit)
  119. {
  120. Debug.Log("总共"+int.Parse( jd["data"]["page"]["total_count"].ToString()));
  121. for (int i = 0; i < MaxLiebiao; i++)
  122. {
  123. if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i)
  124. {
  125. list[i].GetComponent<RiZhiItem>().init(jd["data"]["list"][i]);
  126. list[i].SetActive(true);
  127. datamsg.Add(jd["data"]["list"][i]);
  128. }else
  129. {
  130. list[i].SetActive(false);
  131. }
  132. }
  133. }
  134. else
  135. {
  136. for (int i = 0; i < MaxLiebiao; i++)
  137. {
  138. if(jd["data"]["list"].Count> i)
  139. {
  140. datamsg.Add(jd["data"]["list"][i]);
  141. }
  142. }
  143. }
  144. uiScroll.InitList(0, datamsg.Count);
  145. startinit=true;
  146. Debug.Log("getreplist end"+datamsg.Count);
  147. if(datamsg.Count == 0 )
  148. {
  149. go.transform.parent.parent.parent.gameObject.SetActive(false);
  150. }
  151. else
  152. {
  153. go.transform.parent.parent.parent.gameObject.SetActive(true);
  154. }
  155. }));
  156. if(page+1<=total)
  157. {
  158. jd["page"] = (page+1);
  159. nextdata = jd;
  160. // yield return getreplist(jd);
  161. }
  162. else
  163. {
  164. nextdata=null;
  165. }
  166. }
  167. }