Manage.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. 好友管理器中心 包含了 删除好友 修改好友名字等接口
  3. */
  4. Namespace.register("U.MD.F.M"); //好友管理器的命名空间
  5. //#region 添加好友分组
  6. /**
  7. * 弹出好友分组
  8. *
  9. */
  10. U.MD.F.M.createFriendGroupPopup = function () {
  11. var _tempel,
  12. _temponeel,
  13. _temptwoel;
  14. //创建好友分组的样式
  15. _tempel = $$("div", { "className": "U_MD_U_L_Box_I U_MD_F_Add_TNL U_MD_F_G" });
  16. _temponeel = $$("div", {}, _tempel)
  17. _temptwoel = $$("input",
  18. {
  19. "placeholder": "请输入你要创建的分组",
  20. "onfocus": function () {
  21. U.UF.MR.inputPlaceholder(this, '请输入你要创建的分组名', "")
  22. },
  23. "onblur": function () {
  24. U.UF.MR.inputPlaceholder(this, "", '请输入你要创建的分组名');
  25. }
  26. }, _temponeel);
  27. //弹出好友对话框
  28. U.UF.UI.confirm(_tempel, function () {
  29. U.MD.F.M.createFriendGroup(_temptwoel);
  30. }); //创建一个对话框
  31. }
  32. /**
  33. * 确定添加好友
  34. *
  35. * @param {string} 好友分组id
  36. */
  37. U.MD.F.M.createFriendGroup = function (inputel) {
  38. var _value = inputel.value, //好友分组名字
  39. _groupid = Guid.newGuid(); //好友分组id
  40. //好友分组的名字不能大于20
  41. if (_value.length > 20) {
  42. U.alert("分组名不可超过20个字符");
  43. }
  44. //好友分组名字必须填写
  45. else if (!_value.isStrNull() && _value != inputel.defaultValue) {
  46. U.A.Request(US.CD, [US.DB, "UseStudio_Friends", "CreateFriendClass", _groupid, US.userInfo.userid, _value, ""], U.MD.F.M.asynCreateFriendGroup, ["", _value, _groupid]); //发送添加分组的请求
  47. }
  48. //没有输入的提示
  49. else {
  50. U.alert("请输入正确的群名");
  51. }
  52. }
  53. //添加好友分组异步
  54. U.MD.F.M.asynCreateFriendGroup = function (r) {
  55. var _groupinfo,
  56. _context = r.context;
  57. r = r.value; //得到服务器返回的值
  58. _groupinfo = new U.MD.F.T.friendGroupEntity(_context[2], _context[1], ""); //初始化一个好友分组
  59. //在好友数组的全局变量中添加好友分组的信息
  60. US.friend.allclass.push(_groupinfo);
  61. //重新点击打印好友分组,重新刷新分组
  62. $($("#U_MD_F_H_ZLTA").Child()[0]).Child()[0].onclick();
  63. //提示创建成功
  64. U.alert("创建" + _context[1] + "分组成功");
  65. }
  66. //#endregion
  67. //#region 删除好友
  68. /**
  69. * 删除好友
  70. *
  71. * @param {object} 删除用户信息
  72. */
  73. U.MD.F.M.deleteFriend = function (friendinfo, callback) {
  74. //数据库中删除好友
  75. U.A.Request(US.FRIEND, ["DeleteFriend", US.userInfo.userid, friendinfo.FriendsID, friendinfo.UserId], U.MD.F.M.asynDeleteFriend, ["", friendinfo, callback]); //ajax删除好友
  76. }
  77. /**
  78. * 删除好友异步
  79. *
  80. * @param {object} 删除用户信息
  81. */
  82. U.MD.F.M.asynDeleteFriend = function (r) {
  83. var _context = r.context,
  84. _message = "好友已删除",
  85. _friendinfo = _context[1]; //好友的信息;
  86. U.Json.del(US.friend.friends, { "FriendsID": _friendinfo.FriendsID }); //好友集里删除好友
  87. var _friendclassinfo = U.Json.select(US.friend.allclass, { "FriendsGroupID": _friendinfo.FriendsGroupID })[0], //好友分组的信息
  88. _friendclassuserinfo = U.Json.select(US.friend.friends, { "FriendsGroupID": _friendinfo.FriendsGroupID }), //好友分组的信息
  89. _el = $(".U_MD_F_H_ZLZOCO"), //获取用户的所有好友
  90. _friendel = $('#g' + _friendclassinfo.FriendsGroupID).Child(),
  91. _switchbootom = $("#U_MD_F_H_ZLTA").Child(); //好友或者群切换按钮
  92. //判断是否在当前好友选取下
  93. if ($('#U_MD_F_H_ZLTA .U_MD_F_H_ZLTOO')[0]) {
  94. //删除好友元素
  95. for (var i = 0; i < _el.length; i++) {
  96. if (_el[i].TID == _friendinfo.UserId) {//获取指定的删除的好友
  97. $(_el[i]).remove(); //删除指定的好友元素
  98. U.MD.F.W.delteFriendChat(_el[i].TID, $("#U_MD_F")[0]); //删除指定的好友聊天窗口
  99. _friendel[0].innerHTML = _friendclassinfo.FriendsGroupName + "(" + (_friendclassuserinfo.length) + ")"; //修改分组长度
  100. break;
  101. }
  102. }
  103. //修改好友信息
  104. //如果所有好友都清空了,那么则打印空好友的提示
  105. if (US.friend.allclass.length == 1 && !_friendclassuserinfo.length) {
  106. U.MD.F.printHasNoFriend(_friendel[1]);
  107. }
  108. _message = '好友' + (_friendinfo.UserNickName || _friendinfo.UserName) + '已从好友列表中删除';
  109. }
  110. var _win = $('.U_MD_F_TO[user="9dff9339-2d37-4072-b62e-3b0a027ae997"]');
  111. _win[0] && $('.U_MD_F_TOC', _win)[0].onclick();
  112. U.UF.C.isFunction(_context[2]) && _context[2]();
  113. U.alert(_message);
  114. };
  115. //#endregion
  116. //#region 添加好友
  117. /**
  118. * 添加好友
  119. *
  120. * @param {object} 用户信息
  121. * @param {object} 回调函数
  122. * @param {object} 删除用户信息
  123. */
  124. U.MD.F.M.addFriend = function (userinfo, cb, typename) {
  125. if (!U.MD.U.L.isLogin()) {
  126. typename = typename || "1"; //判断是添加直接对方为好友还是添加对方为好友需好友验证。
  127. //无法加本人为好友 同时不可与本人对话
  128. if (userInfo.userid != US.userInfo.userid) {
  129. //在好友里获取用户
  130. var _friendinfo = U.Json.select(US.friend.friends, { "UserId": userInfo.userid })[0];
  131. //判断是否已经添加了用户
  132. if (!_friendinfo) {
  133. U.MD.F.M.addFriendForm(userinfo, cb, typename); //弹出添加好友框
  134. }
  135. //如果用户已经是自己的好友,那么直接跳出聊天
  136. else {
  137. U.MD.F.W.popupFriendsForm(_friendinfo); //弹出聊天框
  138. }
  139. } else { U.Alert("不可以添加自己为好友哟!"); }
  140. }
  141. else { U.Alert("快速登录关注他(她)吧"); }
  142. }
  143. /**
  144. * 添加好友
  145. *
  146. * @param {object} 用户信息
  147. * @param {object} 删除用户信息
  148. */
  149. U.MD.F.M.addFriendForm = function (userinfo, cb, typename) {
  150. var i,
  151. _formel,
  152. _tempel,
  153. _temponeel,
  154. _temptwoel,
  155. _tempthreeel,
  156. _tempfourel,
  157. _friendgroupinfo = US.friend.allclass; //好友分组
  158. var _date = new Date();
  159. //创建添加好友信息分组信息
  160. _tempel = $$("div", { "className": "U_MD_U_UV_IAC" });
  161. _temponeel = $$("div", { "className": "U_MD_U_UV_IACA" }, _tempel);
  162. _temptwoel = $$("div", { "className": "U_MD_U_UV_IACL" },
  163. _temponeel); _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACLT" }, _temptwoel);
  164. $$("img",
  165. {
  166. "onerror": U.MD.C.imgError,
  167. "title": "点击查看",
  168. "src": U.MD.C.getHeadImage(userinfo.UserThumbnailImageHead)
  169. },
  170. _tempthreeel);
  171. _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACLB" }, _temptwoel);
  172. $$("div", { "className": "U_MD_D_Text_Abbreviation", "innerHTML": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);
  173. $$("div", { "className": "U_MD_D_Text_Abbreviation", "innerHTML": "性别:" + (userinfo.UserSex ? "男" : "女") }, _tempthreeel);
  174. $$("div", { "className": "U_MD_D_Text_Abbreviation", "innerHTML": "年龄:" + (U.UF.D.getYearMonthDay(_date.toLocaleDateString())[3] - U.UF.D.getYearMonthDay(userinfo.Birthday)[3]) }, _tempthreeel);
  175. _temptwoel = $$("div", { "className": "U_MD_U_UV_IACR" }, _temponeel);
  176. _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACRT" }, _temptwoel);
  177. $$("div", { "className": "U_MD_U_UV_IACRTL", "innerHTML": "备注姓名:" }, _tempthreeel);
  178. _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACRTR" }, _tempthreeel);
  179. _memoName = $$("input", { "value": userinfo.UserNickName || userinfo.UserName }, _tempthreeel);
  180. _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACRB" }, _temptwoel);
  181. $$("div", { "className": "U_MD_U_UV_IACRBL", "innerHTML": "分&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp组:" }, _tempthreeel);
  182. _tempthreeel = $$("div", { "className": "U_MD_U_UV_IACRBR" },
  183. _tempthreeel);
  184. _tempfourel = $$("select", {}, _tempthreeel);
  185. //添加用户到制定的好友分组处理
  186. _tempfourel.options.length = _friendgroupinfo.length;
  187. for (i = 0; i < _friendgroupinfo.length; i++) {
  188. _tempfourel.options[i].text = _friendgroupinfo[i].FriendsGroupName;
  189. }
  190. //创建好友分组的弹框
  191. _formel = U.UF.UI.confirm(_tempel, function () {
  192. U.MD.F.M.addFriendToDb(userinfo, cb, _tempfourel, _temponeel, typename, _memoName.value);
  193. });
  194. _formel.form.style.width = "400px";
  195. return _formel;
  196. }
  197. /**
  198. * 确定添加好友
  199. *
  200. * @param {object} 删除用户信息
  201. * @param {function} 删除用户信息
  202. */
  203. U.MD.F.M.addFriendToDb = function (userinfo, cb, selectel, loadingel, typename, _memoName) {
  204. var _friendgroupinfo = US.friend.allclass[selectel.selectedIndex], //获取用户选择的分组
  205. _groupid = _friendgroupinfo.FriendsGroupID, //好友分组id
  206. _friendid = Guid.newGuid(), //用户在分组里面的唯一识别id
  207. _messageid = Guid.newGuid(); //用户发送的消息的唯一识别id
  208. _descript = $(".U_MD_U_UV_IACRTR")[0].childNodes[0].value; //用户备注
  209. //添加好友分组的ajax
  210. //对方发送添加好友信息给你,同意后把用户直接加到好友分组里
  211. if (typename == "0") {
  212. U.A.Request(US.FRIEND, ["AgreeAddFriend", US.userInfo.userid, userInfo.userid, _friendid, _groupid, (userinfo.UserNickName || userinfo.UserName), userinfo.MessageContent.toUpperCase()],
  213. U.MD.F.M.asynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]); //添加好友到默认分组
  214. }
  215. //添加用户为好友
  216. else {
  217. U.A.Request(US.CD, ([US.DB, "UseStudio_Friends", "AddFriend", US.userInfo.userid, _friendid, userInfo.userid, _groupid, _messageid, (userinfo.UserNickName || userinfo.UserName), ("" || _descript)]), U.MD.F.M.asynAddFriendToDb, [loadingel, _groupid, userinfo, _friendgroupinfo, cb, _friendid]); //添加好友到默认分组
  218. }
  219. //提示
  220. //U.alert("正在添加中...");
  221. return false;
  222. }
  223. /**
  224. * 添加好友到分组异步
  225. *
  226. * @param {object} 添加成功后的信息
  227. */
  228. U.MD.F.M.asynAddFriendToDb = function (r) {
  229. var _context = r.context,
  230. _loadingel = _context[0], //loading元素
  231. _groupid = _context[1], //群id
  232. _userinfo = _context[2], //用户的信息
  233. _friendgroupinfo = _context[3], //
  234. _cb = _context[4],
  235. _friendid = _context[5];
  236. r = r.value;
  237. //同意添加对方为好友的时候处理
  238. if (r) {
  239. //设置添加好友
  240. U.MD.F.M.displayAddFriend(_userinfo, _friendid, _groupid, _friendgroupinfo, r);
  241. //添加好友的回调处理
  242. if (_cb) {
  243. _cb();
  244. }
  245. U.alert('添加好友成功,快和他发起聊天吧');
  246. }
  247. //添加对方为好友,给对方发送消息处理
  248. else {
  249. U.alert("您的请求已经发送,请等待对方的同意。");
  250. }
  251. //关闭loading的弹窗
  252. $(_loadingel).Parent({ usform: "true" }).remove();
  253. }
  254. /**
  255. * 添加好友成功后的处理
  256. *
  257. * @param {object} 添加成功后的信息
  258. */
  259. U.MD.F.M.displayAddFriend = function (userinfo, friendid, classid, friendgroupinfo, r) {
  260. var _childs,
  261. _groupel,
  262. //好友分组的信息
  263. _friendinfo = new U.MD.F.T.friendEntity(userinfo.UserIndividualitysignature, userInfo.userid, userinfo.UserImageHead,
  264. userinfo.UserThumbnailImageHead, userinfo.UserNickName || userinfo.UserName,
  265. userinfo.UserName, friendid, _descript, classid, 0);
  266. _friendinfo["IsLogin"] = r[1] == "True" ? 1 : 0; //设置用户在线
  267. US.friend.friends.unshift(_friendinfo); //添加好友到好友列表里
  268. //打印聊天显示窗体
  269. _groupel = $('#g8f128439-6323-47bb-bc68-86b97a3c4d11');
  270. // $('div[tid="069dba1f-f6a4-4629-ba97-0459d9b041d7"]')
  271. if (_groupel[0]) {
  272. _childs = $(_groupel).Child(); //0 好友分组信息 1好友信息
  273. //如果是第一次添加好友,那么提示好友的信息删除
  274. // if (US.friend.friends.length == 1) {
  275. // $("#U_MD_F_H_ZR")[0].innerText = "";
  276. // };
  277. //打印添加的好友信息
  278. U.MD.F.printFriendOrGroup(_childs[1], [_friendinfo], true); //打印好友
  279. //好友分组信息
  280. _childs[0].innerText = friendgroupinfo["FriendsGroupName"] + "(" + (U.Json.select(US.friend.friends, { "FriendsGroupID": classid }).length) + ")";
  281. };
  282. //添加成功后打开好友聊天对话
  283. U.MD.F.W.popupFriendsForm(_friendinfo);
  284. //重新刷新
  285. $($("#U_MD_F_H_ZLTA").Child()[0]).Child()[0].onclick();
  286. //右边的好友窗体也重新打印
  287. if (!US.friend.recentcontacts.length) {
  288. U.MD.F.printRightFormFriend(US.friend.friends, $("#U_MD_F_H_RC")[0]);
  289. }
  290. }
  291. //#endregion