Browse Source

Merge remote-tracking branch 'origin/dev' into dev

XMTT 7 years ago
parent
commit
f5bcb6f228
4 changed files with 273 additions and 5 deletions
  1. 265 0
      js/answerLeaveW.js
  2. 3 1
      js/inform.js
  3. 4 3
      js/qa-show.js
  4. 1 1
      qa-show.html

+ 265 - 0
js/answerLeaveW.js

@ -0,0 +1,265 @@
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.bindEvent();
22
		self.addHtml();
23
	}
24

25
	function lgin() {
26
		if($.cookie('userid') !="null") {
27
			return true;
28
		}
29
		quickLog();
30
		operatTab();
31
		closeLog();
32
		return false;
33
	}
34
	LeaveWord.prototype.addHtml=function() {
35
		$("body").append('<textarea class="txtArea" id="tt" style="position:absolute;top:0;left:-999px;"></textarea>')
36
	}
37
	LeaveWord.prototype.init = function(selecter,obj) {
38
		obj.rows=5;
39
		var id = $.cookie('userid');
40
		var self = this;
41
		ajaxRequist("/ajax/leavemsg/subject",obj, "GET", function(data) {
42
			if(!self.id) {
43
			var strer='<div class="ifLogin">' +
44
					    '<form class="ifLoginOn clearfix">' +
45
					    	'<div class="msgContbox">' +
46
					    		'<textarea class="msgCont" placeholder="请输入您的留言内容..."></textarea>' +
47
					    		'<span class="msgconNum"><em>0</em>/200</span>'+
48
					    	'</div>'+
49
					    	'<input type="button" class="frmconbtn btnModel floatR" disabled="" value="留言">' +
50
					    '</form>' +
51
				'</div>' +
52
				'<div class="form-item commentsArea">'+
53
					'<ul class="commentList">' +
54
					'</ul>' +
55
					'<button class="frmconbtn btnCancel displayNone">查看更多留言</button>' +
56
				'</div>'
57
				var $strer=$(strer);
58
				selecter.append(strer);
59
				$strer.find("input").data("ouse",obj);
60
				//self.LwordTotal()
61
				(data.length>4)?$strer.find(".btnCancel").removeClass("displayNone").data("obj",{
62
					sid:obj.sid,
63
					sType:4,
64
					time:data[data.length-1].createTime,
65
					id:data[data.length-1].id
66
				}):"";
67
			}else{
68
				(data.length>4)?selector.siblings("button").removeClass("displayNone").data("obj",{
69
					sid:obj.sid,
70
					sType:4,
71
					time:data[data.length-1].createTime,
72
					id:data[data.length-1].id
73
				}):selector.siblings("button").addClass("displayNone");
74
			}
75
			if(data.length == 0) {
76
				return;
77
			}
78
			if(selector.siblings()[0]=="button") {
79
				self.topHtml($strer.find("ul"),data);
80
			}else{
81
				self.topHtml(selector,data);
82
			}
83
			
84
		})
85
	}
86
	LeaveWord.prototype.topHtml=function(selector,data) {
87
		var self = this;
88
		for(var i = 0; i < data.length; i++) {
89
				var reply="";
90
				if(data[i].reciver) {
91
					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>'
92
				}
93
				var itemlist = '<li class="flexCenter">';
94
				itemlist += '<a href class="userhref"> <div class="madiaHead useHead useHeadMsg"></div></a>';
95
				itemlist += '<div class="madiaInfo">';
96
				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>';
97
				itemlist += '<p class="h2Font messageContent">'+data[i].cnt+'</p>';
98
				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>';
99
				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>';
100
				$itemlist = $(itemlist);
101
				selector.append($itemlist); 
102
				$itemlist.attr('data-obj',JSON.stringify(data[i]));
103
				if(id == data[i].sender) {
104
					$itemlist.find(".messageDel").removeClass("displayNone").end().find(".noMy").hide();
105
				}
106
				if(data[i].reciver) {
107
					self.userInfo(data[i].sender, $itemlist, 0);
108
					self.userInfo(data[i].reciver, $itemlist, 1)
109
				} else {
110
					self.userInfo(data[i].sender, $itemlist, 0);
111
				}
112
				if(data[i].agreeCount)
113
					self.referThup(data[i].id, $itemlist, data[i].agreeCount);
114
			}
115
	}
116
	LeaveWord.prototype.userInfo = function(uId, li, parNum) {
117
		ajaxRequist("/ajax/professor/editBaseInfo/" + uId, {}, "GET", function($data) {
118
			if(parNum == 0) {  
119
				if($data.hasHeadImage == 1) {
120
					li.find(".useHead")[0].style.backgroundImage = "url(../images/head/" + $data.id + "_l.jpg" + ")";
121
				}
122
				li.find("textarea").attr("placeholder","回复  "+$data.name+":")
123
			}
124
			var userType = autho($data.authType, $data.orgAuth, $data.authStatus);
125
			li.find(".messageName").eq(parNum).html($data.name).end().end().find(".authiconNew").eq(parNum).addClass(userType.sty).attr("title",userType.title);
126
		})
127
	}
128
	LeaveWord.prototype.size = function() {
129
		if(this.val().length > 200) {
130
			$.MsgBox.Alert('提示', '留言不得超过200个字');
131
			return false;
132
		}
133
		return true;
134
	}
135
	LeaveWord.prototype.topLw = function($this) {
136
		var self = this;
137
		if(!self.size.call($($this).siblings(".msgContbox").find("textarea")) ){
138
			return;
139
		}
140
		ajaxRequist("/ajax/leavemsg", {
141
			cnt: $($this).siblings(".msgContbox").find("textarea"),
142
			refId: $($this).data("ouse").sid,
143
			refType: $($this).data("ouse").stype,
144
			sender: $.cookie('userid'),
145
			uname: $.cookie('userName')
146
		}, "POST", function(data) {
147
			$($this).siblings(".msgContbox").find("textarea").val("");
148
			ajaxRequist("/ajax/leavemsg/qo", {id:data.data},"GET",function(data) {
149
				self.topHtml($($this).parents(".ifLogin").siblings(".commentsArea").find("ul"),[data])
150
			})
151
		})
152
	}
153
	LeaveWord.prototype.autoGrow=function(){
154
		document.getElementById("tt").style.width=this.scrollWidth+"px";
155
		document.getElementById("tt").value=this.value;
156
		this.style.height=document.getElementById("tt").scrollHeight+"px";
157
	}
158
	LeaveWord.prototype.bindEvent = function() {
159
		var self = this;
160
		$(".ifLogin").on('click',"input",function() {
161
			if(!lgin()) {
162
				return;
163
			}
164
			self.topLw($(this));
165
		});
166
		$("#curAnswers").on("click", "li", function(e) {
167
			if(!lgin()) {
168
				return;
169
			}
170
			var obj=JSON.parse($(this).attr("data-obj")),
171
			target=e.target;
172
			switch (target.className){
173
				case "dzthumb":self.thub.call(target, obj.id,obj.agreeCount);
174
					break;
175
				case "callBack":$(target).parents(".operateSpan").addClass("displayNone").siblings(".replyLeword").removeClass("displayNone");
176
					break;
177
				case "messageDel":self.LwordDel(target, obj);
178
					break;
179
				case "hReply btnModel":self.replyLword(target,obj)
180
					break;
181
				case "qCancel": $(target).parent().siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone")
182
					break;
183
				case "frmconbtn btnCancel":
184
				var $obj=$(this).data(obj);
185
				self.init($(this).siblings("ul"),{sid: $obj.sid,stype: $obj.stype,time: $obj.time,id: $obj.id});
186
			}
187
		});
188
		$("#curAnswerst").on("input",".msgCon",function(){
189
			if($.trim($(this).val()).length>0) {
190
					$(this).siblings(".msgconNum").removeAttr("disabled");
191
				}else{
192
					$(this).siblings(".msgconNum").attr("disabled","disabled");
193
				}
194
		})
195
		$("#curAnswers").on("input", "textarea", function(e) {
196
				if($.trim($(this).val()).length>0) {
197
					$(this).siblings().find(".btnModel").removeAttr("disabled");
198
					self.autoGrow.call(this);
199
				}else{
200
					$(this).siblings().find(".btnModel").attr("disabled","disabled");
201
				}
202
		})
203
	}
204
	LeaveWord.prototype.referThup = function(lid, li, num) {
205
		ajaxRequist("/ajax/leavemsg/agree", { 
206
			id: lid,
207
			uid: $.cookie('userid')
208
		}, "GET", function(data) {
209
			if(data) {
210
				li.find(".thNum").html("已赞" + num).end().find(".dzthumb").addClass("dzthumbed").css("cursor","auto");
211
			}
212
		})
213
	}
214
	LeaveWord.prototype.thub = function(lid,num) {
215
		var self = this;
216
		ajaxRequist("/ajax/leavemsg/agree", {
217
			id: lid,
218
			uid: $.cookie('userid'),
219
			uname: $.cookie('userName')
220
		}, "POST", function(data) {
221
			$(self).addClass('dzthumbed').siblings(".thNum").html("已赞"+(num+1))// + (Number(self.getAttribute("data-num")) + 1);
222
		})
223
	}
224
	LeaveWord.prototype.replyLword = function( $th,lid) {
225
		var self = this;
226
		if(!self.size.call($($th).parents(".pTxt").siblings("textarea")) ){
227
			return;
228
		}
229
		ajaxRequist("/ajax/leavemsg/reply", {
230
			cnt: $($th).parents(".pTxt").siblings("textarea").val(),
231
			id: lid.id,
232
			uid: $.cookie('userid'),
233
			uname: $.cookie('userName')
234
		}, "POST", function(data) {
235
			$($th).parents(".pTxt").siblings("textarea").val("").parents(".replyLeword").addClass("displayNone").siblings(".operateSpan").removeClass("displayNone")
236
			ajaxRequist("/ajax/leavemsg/qo", {id:data.data},"GET",function(data) {
237
				self.topHtml($($th).parents("ul"),[data])
238
			})
239
			self.LwordTotal($th,lid);
240
		})
241
	}
242
	LeaveWord.prototype.LwordDel = function($this, lid) {
243
		var self = this;
244
		ajaxRequist("/ajax/leavemsg/del", {
245
			id: lid.id
246
		}, "GET", function(data) {
247
			$($this).parents("li").remove();
248
			self.LwordTotal($this,lid);
249
		})
250
	}
251
	LeaveWord.prototype.LwordTotal = function($th,lid) {
252
		var self = this;
253
		ajaxRequist("/ajax/leavemsg/count", {
254
			sid: lid.sid,
255
			stype: lid.stype
256
		}, "get", function($data) {
257
			$($th).parents(".list-qa").find(".pageview").text($data);
258
		})
259
	}
260

261
	var module = {
262
		lWord: new LeaveWord()
263
	}
264
	window.module = module;
265
})(window)		

+ 3 - 1
js/inform.js

@ -117,7 +117,9 @@ $(function() {
117 117
					window.openURL("shtml/a/"+data.data.createTime.substr(0,8)+"/"+data.data.shareId+".html");
118 118
				}
119 119
			});
120
		} else if(dobj.opType == 3 || dobj.opType == 4 || dobj.opType == 5) {
120
		} else if(dobj.opType == 3 || dobj.opType == 4 ) {
121
			ourl = "qa-show.html?id=" + dobj.uid+"&topid="+dobj.pid;
122
		}else if(dobj.opType == 5){
121 123
			ourl = "qa-show.html?id=" + dobj.pid;
122 124
		} else if(dobj.opType == 6) {
123 125
			$.ajax({

+ 4 - 3
js/qa-show.js

@ -9,7 +9,7 @@ $(function() {
9 9
		weibopic = "http://" + hurl + "/images/logo180.png",
10 10
		weibotitle = "";
11 11
	var oanswer = document.getElementsByClassName("go-answer")[0];
12
	
12
	module.lWord;
13 13
	if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
14 14
	 	location.href="http://" + hurl + "/e/wen.html?id="+questionId;
15 15
	}
@ -344,7 +344,8 @@ $(function() {
344 344
				'<div class="flexCenter qa-owner"></div>' +
345 345
				'<p class="qa-con ellipsisSty-3">' + (dataStr.cnt).replace(/\n/g,"<br />") + '</p>' +
346 346
				'<div class="item_info"><span class="time">' + time + '</span></div>'+operatStr+'</div>'+
347
				'<div class="answerUpdate"></div>'
347
				'<div class="answerUpdate"></div>'+
348
				'<div class="answerWord"></div>'
348 349
				
349 350
			var $str = $(liStr)
350 351
			proinfo(dataStr.uid, $str);
@ -452,7 +453,7 @@ $(function() {
452 453
			$str.find(".leaveWo").on('click', function() {
453 454
				if(userid && userid != null && userid != "null") {
454 455
					alert("ppp")
455
					module.lWord(anid,4);
456
					module.lWord.init($(this).parents(".list-qa").find(".answerWord"),{sid:anid,stype:4});
456 457
				}else{
457 458
					quickLog();
458 459
					operatTab();

+ 1 - 1
qa-show.html

@ -201,7 +201,7 @@
201 201
<script type="text/javascript" src="js/weixinshare/qrcode.min.js"></script>
202 202
<script type="text/javascript" src="js/jquery.page.js"></script>
203 203
<script type="text/javascript" src="js/common.js"></script>
204
<script type="text/javascript" src="js/leaveWord.js"></script>
204
<script type="text/javascript" src="js/answerLeaveW.js"></script>
205 205
<script type="text/javascript" src="js/qa-show.js"></script>
206 206
<script type="text/javascript" src="js/quickLogin.js"></script>
207 207
<script type="text/javascript">