InviteDlg.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using LitJson;
  2. using SC.XR.Unity;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XRTool.Util;
  10. public class InviteDlg : UnitySingleton<InviteDlg>
  11. {
  12. public Button searchBtn;
  13. public Button inviteBtn;
  14. public Button clearBtn;
  15. public Button closeBtn;
  16. public GameObject noLinkMan;
  17. public Text shoumsgText;
  18. public SCInputField searchInputField;
  19. public UserList userList;
  20. public GameObject hisTextObj;
  21. public Image inviteBtnImage;
  22. public List<InviteUserConfig> InviteUnionIdList = new List<InviteUserConfig>();//选择还未被邀请
  23. public List<InviteUserConfig> InvitingUnionIdList = new List<InviteUserConfig>();//已经邀请了还没同意或者拒绝
  24. // Start is called before the first frame update
  25. protected override void Awake()
  26. {
  27. base.Awake();
  28. WSHandler.Office.OnUserSearch += UserSearch;
  29. WSHandler.Office.OnInviteUsers += InviteUsers;
  30. WSHandler.Office.OnCallRecordsList += CallRecordsList;
  31. }
  32. protected override void OnDestroy()
  33. {
  34. base.OnDestroy();
  35. WSHandler.Office.OnUserSearch -= UserSearch;
  36. WSHandler.Office.OnInviteUsers -= InviteUsers;
  37. WSHandler.Office.OnCallRecordsList -= CallRecordsList;
  38. }
  39. private void InviteUsers(JsonData data)
  40. {
  41. if (data["data"]["code"].ToString() == "200")
  42. {
  43. for (int i = 0; i < InviteUnionIdList.Count; i++)
  44. {
  45. InvitingUnionIdList.Add(InviteUnionIdList[i]);
  46. }
  47. InviteUnionIdList.Clear();
  48. RoomOtherUser.Instance.UpdateList();
  49. }
  50. }
  51. private List<InviteUserConfig> inviteUserConfigList = new List<InviteUserConfig>();
  52. private void UserSearch(JsonData data)
  53. {
  54. switch (data["data"]["code"].ToString())
  55. {
  56. case "200":
  57. HideHistory();
  58. if (inviteUserConfigList.Count > 0)
  59. {
  60. inviteUserConfigList.Clear();
  61. }
  62. if (data["data"]["data"].Count > 0)
  63. {
  64. noLinkMan.SetActive(false);
  65. for (int i = 0; i < data["data"]["data"].Count; i++)
  66. {
  67. InviteUserConfig inviteUserConfig = new InviteUserConfig(data["data"]["data"][i]["unionId"].ToString(), data["data"]["data"][i]["phone"].ToString(), data["data"]["data"][i]["avatar"].ToString(), data["data"]["data"][i]["nickName"].ToString(), data["data"]["data"][i]["online"].ToString());
  68. inviteUserConfigList.Add(inviteUserConfig);
  69. }
  70. userList.Init(inviteUserConfigList);
  71. inviteUserConfigList.Clear();
  72. }
  73. else
  74. {
  75. noLinkMan.SetActive(true);
  76. shoumsgText.text = "无有效的联系人";
  77. }
  78. break;
  79. case "5001":
  80. HideHistory();
  81. noLinkMan.SetActive(true);
  82. shoumsgText.text = "无有效的联系人";
  83. break;
  84. default:
  85. break;
  86. }
  87. }
  88. private List<InviteUserConfig> historyConfigList = new List<InviteUserConfig>();
  89. public void ShowHistory()
  90. {
  91. InviteUnionIdList.Clear();
  92. clearBtn.gameObject.SetActive(false);
  93. userList.DestoryAll();
  94. hisTextObj.SetActive(true);
  95. InitInviteBtn();
  96. WSHandler.Office.GetRecordsList();
  97. }
  98. private List<InviteUserConfig> zaixianList = new List<InviteUserConfig>();
  99. private List<InviteUserConfig> mangluList = new List<InviteUserConfig>();
  100. private List<InviteUserConfig> lixianList = new List<InviteUserConfig>();
  101. private void AddHisInviteUserList(List<InviteUserConfig> inviteUserConfigs)
  102. {
  103. if (inviteUserConfigs.Count > 0)
  104. {
  105. for (int i = 0; i < inviteUserConfigs.Count; i++)
  106. {
  107. historyConfigList.Add(inviteUserConfigs[i]);
  108. }
  109. }
  110. }
  111. private void CallRecordsList(JsonData data)
  112. {
  113. if (data.Keys.Contains("data"))
  114. {
  115. if (data["data"]["data"].Count > 0)
  116. {
  117. noLinkMan.SetActive(false);
  118. for (int i = 0; i < data["data"]["data"].Count; i++)
  119. {
  120. if (!string.IsNullOrEmpty(data["data"]["data"][i]["nickName"].ToString()))
  121. {
  122. InviteUserConfig inviteUserConfig = new InviteUserConfig(data["data"]["data"][i]["contacts"].ToString(), data["data"]["data"][i]["phone"].ToString(), data["data"]["data"][i]["avatar"].ToString(), data["data"]["data"][i]["nickName"].ToString(), data["data"]["data"][i]["online"].ToString());
  123. switch (data["data"]["data"][i]["online"].ToString())
  124. {
  125. case "1":
  126. zaixianList.Add(inviteUserConfig);
  127. break;
  128. case "2":
  129. mangluList.Add(inviteUserConfig);
  130. break;
  131. case "0":
  132. lixianList.Add(inviteUserConfig);
  133. break;
  134. }
  135. }
  136. }
  137. AddHisInviteUserList(zaixianList);
  138. AddHisInviteUserList(mangluList);
  139. AddHisInviteUserList(lixianList);
  140. userList.Init(historyConfigList);
  141. zaixianList.Clear();
  142. mangluList.Clear();
  143. lixianList.Clear();
  144. historyConfigList.Clear();
  145. }
  146. else
  147. {
  148. noLinkMan.SetActive(true);
  149. shoumsgText.text = "暂时无记录";
  150. }
  151. }
  152. else
  153. {
  154. noLinkMan.SetActive(true);
  155. shoumsgText.text = "暂时无记录";
  156. }
  157. }
  158. public void HideHistory()
  159. {
  160. userList.DestoryAll();
  161. hisTextObj.SetActive(false);
  162. }
  163. void Start()
  164. {
  165. searchBtn.onClick.AddListener(ClickOnSearch);
  166. clearBtn.onClick.AddListener(ClickOnClear);
  167. closeBtn.onClick.AddListener(ClickOnClose);
  168. searchInputField.onValueChanged.AddListener(Inputscearchchanged);
  169. inviteBtn.onClick.AddListener(ClickOnInvite);
  170. //searchInputField.onEndEdit.AddListener(InputsearchEnd);
  171. }
  172. public void InitInviteBtn()
  173. {
  174. inviteBtn.enabled = false;
  175. Color color = Color.white;
  176. color.r = 71 / 255f;
  177. color.g = 126 / 255f;
  178. color.b = 186 / 255f;
  179. color.a = 220 / 255f;
  180. inviteBtnImage.color = color;
  181. }
  182. public void RecoverInviteBtn()
  183. {
  184. inviteBtn.enabled = true;
  185. Color color = Color.white;
  186. color.r = 76 / 255f;
  187. color.g = 166 / 255f;
  188. color.b = 255 / 255f;
  189. color.a = 230 / 255f;
  190. inviteBtnImage.color = color;
  191. }
  192. private void ClickOnInvite()
  193. {
  194. if (InvitingUnionIdList != null && InviteUnionIdList != null && InviteUnionIdList.Count > 0)
  195. {
  196. if (IsContains(InvitingUnionIdList, InviteUnionIdList))
  197. {
  198. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "邀请列表有用户正在通话中");
  199. }
  200. else
  201. {
  202. if (!string.IsNullOrEmpty(RoomMainInfo.roomNum))
  203. {
  204. if (RemoteRtc.Instance.customPeerList != null)
  205. {
  206. if (RemoteRtc.Instance.customPeerList.getPeers().Count + InvitingUnionIdList.Count + InviteUnionIdList.Count > RoomMainInfo.roomMaxPeopleNum - 1)
  207. {
  208. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, "房间人数大于房间总人数");
  209. }
  210. else
  211. {
  212. this.gameObject.SetActive(false);
  213. WSHandler.Office.InviteUsers(RoomMainInfo.roomNum, InviteUnionIdList);
  214. ClickOnClear();
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. public bool IsContains(List<InviteUserConfig> vs1, List<InviteUserConfig> vs2)
  222. {
  223. List<InviteUserConfig> vs3 = new List<InviteUserConfig>();
  224. vs3 = vs1.Intersect(vs2).ToList();
  225. if (vs3.Count > 0)
  226. {
  227. vs3 = null;
  228. return true;
  229. }
  230. else
  231. {
  232. vs3 = null;
  233. return false;
  234. }
  235. }
  236. //private void InputsearchEnd(string content)
  237. //{
  238. // if (content != "")
  239. // {
  240. // clearBtn.gameObject.SetActive(true);
  241. // }
  242. //}
  243. private void Inputscearchchanged(string content)
  244. {
  245. if (content == "")
  246. {
  247. if (gameObject.activeSelf)
  248. {
  249. ShowHistory();
  250. clearBtn.gameObject.SetActive(false);
  251. }
  252. }
  253. else
  254. {
  255. clearBtn.gameObject.SetActive(true);
  256. }
  257. }
  258. private void ClickOnSearch()
  259. {
  260. if (searchInputField.text != "")
  261. {
  262. if (searchInputField.text.Length >2)
  263. {
  264. WSHandler.Office.UserSearch(searchInputField.text);
  265. }
  266. else
  267. {
  268. HideHistory();
  269. noLinkMan.SetActive(true);
  270. shoumsgText.text = "无有效的联系人";
  271. }
  272. }
  273. }
  274. private void ClickOnClear()
  275. {
  276. if (searchInputField.text != "")
  277. {
  278. searchInputField.text = "";
  279. }
  280. clearBtn.gameObject.SetActive(false);
  281. }
  282. private void ClickOnClose()
  283. {
  284. InviteUnionIdList.Clear();
  285. this.gameObject.SetActive(false);
  286. ClickOnClear();
  287. }
  288. }