portal html css js resource

informLeaveW.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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"><div class="researchArea" id="subArea" style="text-align:center;">留言详情</div><div class="form-item" style="padding:0px 30px 30px;"><ul class="commentList" style="min-height: 100px;"></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. $(".commentList").html("").append("<div class='con-kong displayNone'>暂无留言</div>");
  45. }
  46. $(".commentList").html("");
  47. for(var i = 0; i < data.length; i++) {
  48. var reply = "";
  49. if(data[i].reciver) {
  50. reply = '<span class="huifu">回复 </span><a href="userInforShow.html?professorId=' + data[i].reciver + '" class="userhref"><span class="h2Font messageName">张某某</span><em class="authiconNew" title="科袖认证专家"></em></a>'
  51. }
  52. if(data[i].state =="0") {
  53. data[i].cnt="<span style='color:#888'>该留言已被其本人删除。</span>";
  54. }
  55. var itemlist = '<li class="li-item">';
  56. itemlist += '<a class="madiaHead useHead useHeadMsg userhref" href="userInforShow.html?professorId=' + data[i].sender + '"></a>';
  57. itemlist += '<div class="madiaInfo">';
  58. itemlist += '<p><a href="userInforShow.html?professorId=' + data[i].sender + '" class="userhref"><span class="h2Font messageName">张某某</span><em class="authiconNew" title="科袖认证专家"></em></a>' + reply + '<span class="commenttime" style="float:right;">' + commenTime(data[i].createTime) + '</span></p>';
  59. itemlist += '<p class="h2Font messageContent">' + data[i].cnt + '</p>';
  60. itemlist += '<div class="operateSpan">'
  61. itemlist += '<span class="dzthumb dzthumbCan"><em class="hold-icon icon-zan"></em><em class="agreeCount" style="margin-left: 6px;">'+data[i].agreeCount+'</em></span>'
  62. itemlist += '<span class="callBack">回复</span>'
  63. itemlist += '<span class="messageDel displayNone">删除</span></div>';
  64. 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>';
  65. $itemlist = $(itemlist);
  66. $(".commentList").append($itemlist);
  67. $itemlist.attr('data-obj',JSON.stringify(data[i]));
  68. if(id == data[i].sender) {
  69. $itemlist.find(".dzthumb").removeClass("dzthumbCan");
  70. $itemlist.find(".messageDel").removeClass("displayNone").end().find(".callBack").hide();
  71. }
  72. if(data[i].state =="0") {
  73. $itemlist.find(".dzthumb").removeClass("dzthumbCan");
  74. //$itemlist.find(".commenttime").addClass("displayNone")
  75. $itemlist.find(".operateSpan").remove()
  76. }
  77. if(data[i].reciver) {
  78. self.userInfo(data[i].sender, $itemlist, 0);
  79. self.userInfo(data[i].reciver, $itemlist, 1)
  80. } else {
  81. self.userInfo(data[i].sender, $itemlist, 0);
  82. }
  83. if(data[i].agreeCount)
  84. self.referThup(data[i].id, $itemlist, data[i].agreeCount);
  85. }
  86. })
  87. }
  88. LeaveWord.prototype.userInfo = function(uId, li, parNum) {
  89. ajaxRequist("/ajax/professor/editBaseInfo/" + uId, {}, "GET", function($data) {
  90. if(parNum == 0) {
  91. if($data.hasHeadImage == 1) {
  92. li.find(".useHead")[0].style.backgroundImage = "url(../images/head/" + $data.id + "_l.jpg" + ")";
  93. }
  94. li.find("textarea").attr("placeholder", "回复 " + $data.name + ":")
  95. }
  96. var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
  97. li.find(".messageName").eq(parNum).html($data.name).end().end().find(".authiconNew").eq(parNum).addClass(userType.sty).attr("title", userType.title);
  98. })
  99. }
  100. LeaveWord.prototype.size = function() {
  101. if(this.val().length > 200) {
  102. $.MsgBox.Alert('提示', '留言不得超过200个字');
  103. return false;
  104. }
  105. return true;
  106. }
  107. LeaveWord.prototype.autoGrow = function() {
  108. document.getElementById("tt").style.width = this.scrollWidth + "px";
  109. document.getElementById("tt").value = this.value;
  110. this.style.height = this.scrollHeight + "px";
  111. }
  112. LeaveWord.prototype.bindEvent = function() {
  113. var self = this;
  114. $(".commentList").on("click", "li", function(e) {
  115. if(!lgin()) {
  116. return;
  117. }
  118. var obj=JSON.parse($(this).attr("data-obj")),
  119. target=e.target;
  120. switch (target.className){
  121. case "dzthumb dzthumbCan":self.thub.call(target, obj.id,obj.agreeCount);
  122. break;
  123. case "callBack":self.LwordBack(target, obj);
  124. break;
  125. case "messageDel":self.LwordDel(target, obj.id);
  126. break;
  127. case "hReply btnModel":self.replyLword(target,obj.id)
  128. break;
  129. case "qCancel": $(target).parent().siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone");$(target).parent().siblings("textarea").style.height='38px';
  130. break;
  131. }
  132. });
  133. $(".msgCont").on("input", function() {
  134. if($.trim($(this).val()).length > 0) {
  135. $("#meSendtt").removeAttr("disabled");
  136. } else {
  137. $("#meSendtt").attr("disabled", "disabled");
  138. }
  139. })
  140. $(".commentList").on("input", "textarea", function(e) {
  141. if($.trim($(this).val()).length > 0) {
  142. $(this).siblings().find(".btnModel").removeAttr("disabled");
  143. self.autoGrow.call(this);
  144. } else {
  145. $(this).siblings().find(".btnModel").attr("disabled", "disabled");
  146. }
  147. })
  148. $("#workclose").click(function(){
  149. $(".blackcover").addClass("displayNone").find("ul").html("");
  150. })
  151. }
  152. LeaveWord.prototype.referThup = function(lid, li, num) {
  153. ajaxRequist("/ajax/leavemsg/agree", {
  154. id: lid,
  155. uid: $.cookie('userid')
  156. }, "GET", function(data) {
  157. if(data) {
  158. li.find(".dzthumbCan").addClass("dzthumbed");
  159. //li.find(".thNum").html("已赞" + num).end().find(".dzthumbCan").addClass("dzthumbed").css("cursor", "auto");
  160. }
  161. })
  162. }
  163. LeaveWord.prototype.thub = function(lid, num) {
  164. var self = this;
  165. ajaxRequist("/ajax/leavemsg/agree", {
  166. id: lid,
  167. uid: $.cookie('userid'),
  168. uname: $.cookie('userName')
  169. }, "POST", function(data) {
  170. $(self).addClass('dzthumbed').find(".agreeCount").html(num+1)
  171. //$(self).addClass('dzthumbed').siblings(".thNum").html("已赞" + (num + 1)) // + (Number(self.getAttribute("data-num")) + 1);
  172. })
  173. }
  174. LeaveWord.prototype.replyLword = function($th, lid) {
  175. var self = this;
  176. if(!self.size.call($($th).parents(".pTxt").siblings("textarea"))) {
  177. return;
  178. }
  179. $.ajax({
  180. url:"/ajax/leavemsg/reply",
  181. data: {
  182. cnt: $($th).parents(".pTxt").siblings("textarea").val(),
  183. id: lid,
  184. uid: $.cookie('userid'),
  185. uname: $.cookie('userName')
  186. },
  187. dataType: 'json',
  188. type: "POST",
  189. beforeSend: function() {
  190. $($th).attr("disabled","true");
  191. },
  192. complete:function () {
  193. },
  194. traditional: true,
  195. success: function (data) {
  196. if (data.success) {
  197. $($th).parents(".pTxt").siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone")
  198. self.init({
  199. id: self.id
  200. });
  201. }
  202. }
  203. });
  204. }
  205. LeaveWord.prototype.LwordDel = function($this, lid) {
  206. var self = this;
  207. ajaxRequist("/ajax/leavemsg/del", {
  208. id: lid
  209. }, "GET", function(data) {
  210. $($this).parents(".li-item").remove();
  211. })
  212. }
  213. LeaveWord.prototype.LwordBack = function($this, lid) {
  214. $(".replyLeword").each(function(item){
  215. $(".replyLeword").eq(item).addClass("displayNone").siblings(".operateSpan").removeClass("displayNone");
  216. })
  217. $($this).parents(".operateSpan").addClass("displayNone").siblings(".replyLeword").removeClass("displayNone")
  218. }
  219. var module = {
  220. lWord: new LeaveWord()
  221. }
  222. window.module = module;
  223. })(window)