B08_TaskListItem.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Newtonsoft.Json;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class B08_TaskListItem : MonoBehaviour
  8. {
  9. public Text typeText;
  10. public Text titleText;
  11. public Text stateText;
  12. public Text dateText;
  13. public Text ctrlText;
  14. public GameObject more;
  15. public Button moreButton;
  16. public bool moreMessage = false;
  17. public RectTransform rect;
  18. public GameObject pointItemPrefab;
  19. public List<B08_TaskPointItem> PointItems = new List<B08_TaskPointItem>();
  20. public Transform itemContent;
  21. public B08_TaskInfoData InfoData;
  22. public GCYWLayer gcywLayer;
  23. public static B08_TaskListItem currentTaskListItem;
  24. public string id;
  25. public string xunjianType;
  26. public void Init()
  27. {
  28. rect = this.GetComponent<RectTransform>();
  29. typeText = this.transform.Find("typeText").GetComponent<Text>();
  30. titleText = this.transform.Find("titleText").GetComponent<Text>();
  31. stateText = this.transform.Find("stateText").GetComponent<Text>();
  32. dateText = this.transform.Find("dateText").GetComponent<Text>();
  33. ctrlText = this.transform.Find("ctrlText").GetComponent<Text>();
  34. more = this.transform.Find("more").gameObject;
  35. more.SetActive(false);
  36. moreButton = ctrlText.GetComponent<Button>();
  37. moreButton.onClick.AddListener(() => { ChangeMoreMessage(!moreMessage); });
  38. moreMessage = false;
  39. ctrlText.text = "<color=#00EFFF>详情</color>";
  40. rect.sizeDelta = new Vector2(360, 38);
  41. more.SetActive(false);
  42. }
  43. private async void ChangeMoreMessage(bool moreMes = false)
  44. {
  45. try
  46. {
  47. moreMessage = moreMes;
  48. if (moreMessage)
  49. {
  50. if (currentTaskListItem != null && currentTaskListItem != this)
  51. {
  52. if (currentTaskListItem.moreMessage)
  53. {
  54. currentTaskListItem.ChangeMoreMessage(false);
  55. }
  56. }
  57. ctrlText.text = "<color=#00FF3F>收起</color>";
  58. rect.sizeDelta = new Vector2(360, 354);
  59. more.SetActive(true);
  60. }
  61. else
  62. {
  63. ctrlText.text = "<color=#00EFFF>详情</color>";
  64. rect.sizeDelta = new Vector2(360, 38);
  65. more.SetActive(false);
  66. }
  67. var infoDataStr=await HttpHelper._Instance.B08_API_TaskInfo(id);
  68. Debug.Log(infoDataStr);
  69. if (moreMessage)
  70. {
  71. currentTaskListItem = this;
  72. InfoData = JsonConvert.DeserializeObject<B08_TaskInfo>(infoDataStr).Data;
  73. if (InfoData.taskItems == null) return;
  74. for (int i = 0; i < InfoData.taskItems.Length; i++)
  75. {
  76. B08_TaskPointItem tempItem = Instantiate(pointItemPrefab, itemContent).GetComponent<B08_TaskPointItem>();
  77. tempItem.SetData(gcywLayer, InfoData.taskItems[i], i, InfoData.createTime);
  78. var button = tempItem.GetComponent<ExtendedButton_PointItem>();
  79. button.index = i;
  80. //button.onPointerEnter += gcywLayer.SetTaskPointIconHeightLight;
  81. PointItems.Add(tempItem);
  82. }
  83. gcywLayer.SetTaskImgPanelData(InfoData.locations.locations, InfoData.createTime);
  84. }
  85. }
  86. catch (Exception e)
  87. {
  88. Debug.LogError(e.ToString());
  89. }
  90. }
  91. public void SetData(GCYWLayer baseLayer, B08_TaskListData data)
  92. {
  93. gcywLayer = baseLayer;
  94. id = data.id;
  95. xunjianType = data.xunjianType;
  96. InfoData = null;
  97. string typeStr = "";
  98. if (xunjianType == null)
  99. {
  100. xunjianType = "4";
  101. typeStr = "定期专项";
  102. }
  103. else
  104. {
  105. switch (xunjianType)
  106. {
  107. case "0":
  108. typeStr = "电气";
  109. break;
  110. case "1":
  111. typeStr = "闸站";
  112. break;
  113. case "2":
  114. typeStr = "堤防";
  115. break;
  116. case "3":
  117. typeStr = "交叉建筑";
  118. break;
  119. case "4":
  120. case "":
  121. typeStr = "定期专项";
  122. break;
  123. }
  124. }
  125. typeText.text = typeStr;
  126. titleText.text = data.title;
  127. switch (data.status)
  128. {
  129. case 0:
  130. stateText.text = "待派工";
  131. break;
  132. case 1:
  133. stateText.text = "待整改";
  134. break;
  135. case 2:
  136. stateText.text = "待验收";
  137. break;
  138. case 3:
  139. stateText.text = "已整改";
  140. break;
  141. }
  142. dateText.text = data.createTime;
  143. for (int i = 0; i < PointItems.Count; i++)
  144. {
  145. Destroy(PointItems[i].gameObject);
  146. }
  147. PointItems.Clear();
  148. }
  149. }