portal html css js resource

informLeaveW.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. (function(window) {
  2. function ajaxRequist(url, obj, type, fn) {
  3. $.ajax({
  4. url: url,
  5. data: obj,
  6. dataType: 'json', //服务器返回json格式数据
  7. type: type, //支持'GET'和'POST'
  8. traditional: true,
  9. success: function(data) {
  10. if(data.success) {
  11. fn(data.data)
  12. }
  13. },
  14. error: function(xhr, type, errorThrown) {
  15. $.MsgBox.Alert('提示', '服务器请求失败');
  16. }
  17. });
  18. }
  19. var LeaveWord = function() {
  20. var self = this;
  21. self.addHtml();
  22. self.bindEvent();
  23. }
  24. function lgin() {
  25. if($.cookie('userid')) {
  26. return true;
  27. }
  28. location.href = "login.html";
  29. return false;
  30. }
  31. LeaveWord.prototype.addHtml = function() {
  32. $("body").append('<textarea class="txtArea" id="tt" style="position:absolute;top:0;left:-999px;"></textarea>')
  33. var str='<div class="blackcover resAreaCover displayNone"><div class="resAreaBox form-item"><div class="researchArea" id="subArea" style="text-align:center;">留言详情</div><div class="form-item" style="padding:0px 30px;"><ul class="commentList"></ul></div><span class="workclose" id="workclose"></span></div></div>'
  34. $("body").prepend(str);
  35. }
  36. LeaveWord.prototype.init = function(obj) {
  37. var id = $.cookie('userid');
  38. var self = this;
  39. this.id=obj.id;
  40. console.log(self)
  41. ajaxRequist("/ajax/leavemsg/dialog", obj, "GET", function(data) {
  42. if(data.length == 0) {
  43. return;
  44. }
  45. $(".commentList").html("");
  46. for(var i = 0; i < data.length; i++) {
  47. var reply = "";
  48. if(data[i].reciver) {
  49. reply = '<span style="margin:0px 10px;">回复 </span><a href="userInforShow.html?professorId=' + data[i].reciver + '" class="userhref"><span class="h1Font messageName">张某某</span></a><em class="authiconNew" title="科袖认证专家"></em>'
  50. }
  51. if(data[i].state =="0") {
  52. data[i].cnt="该留言已被其本人删除。";
  53. }
  54. var itemlist = '<li class="flexCenter">';
  55. itemlist += '<a href class="userhref"> <div class="madiaHead useHead useHeadMsg"></div></a>';
  56. itemlist += '<div class="madiaInfo">';
  57. itemlist += '<p><a href="userInforShow.html?professorId=' + data[i].sender + '" class="userhref"><span class="h1Font messageName">张某某</span></a><em class="authiconNew" title="科袖认证专家"></em>' + reply + '<span class="commenttime" style="float:right;">' + commenTime(data[i].createTime) + '</span></p>';
  58. itemlist += '<p class="h2Font messageContent">' + data[i].cnt + '</p>';
  59. itemlist += '<div class="operateSpan"><em class="noMy"><span class="dzthumb"></span><span class="thNum">赞0</span><span class="callBack">回复</span></em><span class="messageDel displayNone">删除</span></div>';
  60. itemlist += '<div class="displayNone replyLeword"><textarea class="txtArea"></textarea><p class="pTxt"><span class="qCancel">取消</span><button class="hReply btnModel" disabled>回复</button></p></div></div></li>';
  61. $itemlist = $(itemlist);
  62. $(".commentList").append($itemlist);
  63. $itemlist.attr('data-obj', JSON.stringify(data[i]));
  64. if(id == data[i].sender) {
  65. $itemlist.find(".messageDel").removeClass("displayNone").end().find(".noMy").hide();
  66. }
  67. if(data[i].state =="0") {
  68. $itemlist.find(".operateSpan").addClass("displayNone");
  69. }
  70. if(data[i].reciver) {
  71. self.userInfo(data[i].sender, $itemlist, 0);
  72. self.userInfo(data[i].reciver, $itemlist, 1)
  73. } else {
  74. self.userInfo(data[i].sender, $itemlist, 0);
  75. }
  76. if(data[i].agreeCount)
  77. self.referThup(data[i].id, $itemlist, data[i].agreeCount);
  78. }
  79. })
  80. }
  81. LeaveWord.prototype.userInfo = function(uId, li, parNum) {
  82. ajaxRequist("/ajax/professor/editBaseInfo/" + uId, {}, "GET", function($data) {
  83. if(parNum == 0) {
  84. if($data.hasHeadImage == 1) {
  85. li.find(".useHead")[0].style.backgroundImage = "url(../images/head/" + $data.id + "_l.jpg" + ")";
  86. }
  87. li.find("textarea").attr("placeholder", "回复 " + $data.name + ":")
  88. }
  89. var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
  90. li.find(".messageName").eq(parNum).html($data.name).end().end().find(".authiconNew").eq(parNum).addClass(userType.sty).attr("title", userType.title);
  91. })
  92. }
  93. LeaveWord.prototype.size = function() {
  94. if(this.val().length > 200) {
  95. $.MsgBox.Alert('提示', '留言不得超过200个字');
  96. return false;
  97. }
  98. return true;
  99. }
  100. LeaveWord.prototype.autoGrow = function() {
  101. document.getElementById("tt").style.width = this.scrollWidth + "px";
  102. document.getElementById("tt").value = this.value;
  103. this.style.height = document.getElementById("tt").scrollHeight + "px";
  104. }
  105. LeaveWord.prototype.bindEvent = function() {
  106. var self = this;
  107. $(".commentList").on("click", "li", function(e) {
  108. if(!lgin()) {
  109. return;
  110. }
  111. var obj = JSON.parse($(this).attr("data-obj")),
  112. target = e.target;
  113. switch(target.className) {
  114. case "dzthumb":
  115. self.thub.call(target, obj.id, obj.agreeCount);
  116. break;
  117. case "callBack":
  118. $(target).parents(".operateSpan").addClass("displayNone").siblings(".replyLeword").removeClass("displayNone");
  119. break;
  120. case "messageDel":
  121. self.LwordDel(target, obj.id);
  122. break;
  123. case "hReply btnModel":
  124. self.replyLword(target, obj.id)
  125. break;
  126. case "qCancel":
  127. $(target).parent().siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone")
  128. break;
  129. }
  130. });
  131. $(".msgCont").on("input", function() {
  132. if($.trim($(this).val()).length > 0) {
  133. $("#meSendtt").removeAttr("disabled");
  134. } else {
  135. $("#meSendtt").attr("disabled", "disabled");
  136. }
  137. })
  138. $(".commentList").on("input", "textarea", function(e) {
  139. if($.trim($(this).val()).length > 0) {
  140. $(this).siblings().find(".btnModel").removeAttr("disabled");
  141. self.autoGrow.call(this);
  142. } else {
  143. $(this).siblings().find(".btnModel").attr("disabled", "disabled");
  144. }
  145. })
  146. $("#workclose").click(function(){
  147. $(".blackcover").addClass("displayNone").find("ul").html("");
  148. })
  149. }
  150. LeaveWord.prototype.referThup = function(lid, li, num) {
  151. ajaxRequist("/ajax/leavemsg/agree", {
  152. id: lid,
  153. uid: $.cookie('userid')
  154. }, "GET", function(data) {
  155. if(data) {
  156. li.find(".thNum").html("已赞" + num).end().find(".dzthumb").addClass("dzthumbed").css("cursor", "auto");
  157. }
  158. })
  159. }
  160. LeaveWord.prototype.thub = function(lid, num) {
  161. var self = this;
  162. ajaxRequist("/ajax/leavemsg/agree", {
  163. id: lid,
  164. uid: $.cookie('userid'),
  165. uname: $.cookie('userName')
  166. }, "POST", function(data) {
  167. $(self).addClass('dzthumbed').siblings(".thNum").html("已赞" + (num + 1)) // + (Number(self.getAttribute("data-num")) + 1);
  168. })
  169. }
  170. LeaveWord.prototype.replyLword = function($th, lid) {
  171. var self = this;
  172. if(!self.size.call($($th).parents(".pTxt").siblings("textarea"))) {
  173. return;
  174. }
  175. ajaxRequist("/ajax/leavemsg/reply", {
  176. cnt: $($th).parents(".pTxt").siblings("textarea").val(),
  177. id: lid,
  178. uid: $.cookie('userid'),
  179. uname: $.cookie('userName')
  180. }, "POST", function(data) {
  181. $($th).parents(".pTxt").siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone")
  182. self.init({
  183. id: self.id
  184. });
  185. })
  186. }
  187. LeaveWord.prototype.LwordDel = function($this, lid) {
  188. var self = this;
  189. ajaxRequist("/ajax/leavemsg/del", {
  190. id: lid
  191. }, "GET", function(data) {
  192. $($this).parents("li").remove();
  193. })
  194. }
  195. var module = {
  196. lWord: new LeaveWord()
  197. }
  198. window.module = module;
  199. })(window)