CaoZuoRizhi.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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+86400;
  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. uiScroll.Init();
  97. nextdata=null;
  98. datamsg=new List<JsonData>();
  99. }
  100. List<JsonData> datamsg =new List<JsonData>();
  101. int MaxLiebiao=15;
  102. public JsonData nextdata;
  103. public IEnumerator getreplist(JsonData jd)
  104. {
  105. int page =int.Parse( jd["page"].ToString());
  106. int total =int.Parse( jd["page"].ToString());
  107. Debug.Log("getreplist start"+uiScroll.GetComponent<RectTransform>().anchoredPosition.y);
  108. yield return StartCoroutine(DataManager.Instance.GetRePort(jd,(msg)=>{
  109. JsonData jd =JsonMapper.ToObject(msg);
  110. for (int i = list.Count; i < MaxLiebiao; i++)
  111. {
  112. GameObject n =GameObject.Instantiate(go,go.transform.parent);
  113. list.Add(n);
  114. }
  115. total=int.Parse( jd["data"]["page"]["total_page"].ToString());
  116. if(!startinit)
  117. {
  118. Debug.Log("总共"+int.Parse( jd["data"]["page"]["total_count"].ToString()));
  119. for (int i = 0; i < MaxLiebiao; i++)
  120. {
  121. if(jd["data"]["list"].ToString()!="[]"&&jd["data"]["list"].Count> i)
  122. {
  123. list[i].GetComponent<RiZhiItem>().init(jd["data"]["list"][i]);
  124. list[i].SetActive(true);
  125. datamsg.Add(jd["data"]["list"][i]);
  126. }else
  127. {
  128. list[i].SetActive(false);
  129. }
  130. }
  131. uiScroll.InitList(0, datamsg.Count);
  132. }
  133. else
  134. {
  135. for (int i = 0; i < MaxLiebiao; i++)
  136. {
  137. if(jd["data"]["list"].Count> i)
  138. {
  139. datamsg.Add(jd["data"]["list"][i]);
  140. }
  141. }
  142. uiScroll.InitList(0, datamsg.Count);
  143. }
  144. startinit=true;
  145. Debug.Log("getreplist end"+datamsg.Count);
  146. if(datamsg.Count == 0 )
  147. {
  148. go.transform.parent.parent.parent.gameObject.SetActive(false);
  149. }
  150. else
  151. {
  152. go.transform.parent.parent.parent.gameObject.SetActive(true);
  153. }
  154. Invoke("UpdatePos",0.1f);
  155. Debug.Log("getreplist start"+uiScroll.GetComponent<RectTransform>().anchoredPosition.y);
  156. }));
  157. if(page+1<=total)
  158. {
  159. jd["page"] = (page+1);
  160. nextdata = jd;
  161. // yield return getreplist(jd);
  162. }
  163. else
  164. {
  165. nextdata=null;
  166. }
  167. }
  168. void UpdatePos()
  169. {
  170. uiScroll.GetComponent<RectTransform>().anchoredPosition= new Vector2(uiScroll.GetComponent<RectTransform>().anchoredPosition.x,uiScroll.GetComponent<RectTransform>().anchoredPosition.y+1);
  171. }
  172. }