2016-04-01 20:53:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* Created by root on 4/1/16.
|
|
|
|
|
*/
|
2016-03-31 20:43:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* Created by root on 3/31/16.
|
|
|
|
|
*/
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
|
|
|
|
|
|
var bt=baidu.template;
|
|
|
|
|
bt.LEFT_DELIMITER='<!';
|
|
|
|
|
bt.RIGHT_DELIMITER='!>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var apiUrl = '/api/v1/';
|
|
|
|
|
|
2016-04-01 23:22:39 +08:00
|
|
|
|
var setReplyTemplate = function(data){
|
|
|
|
|
console.log(data);
|
2016-04-01 23:48:29 +08:00
|
|
|
|
var html=bt('t:issue-detail-reply',{issue_reply: data});
|
2016-04-01 23:22:39 +08:00
|
|
|
|
$('#all_issue_reply').prepend(html);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-03-31 20:43:06 +08:00
|
|
|
|
var setTemplate = function(data){
|
|
|
|
|
console.log(data);
|
2016-04-01 20:53:21 +08:00
|
|
|
|
var html=bt('t:issue-detail',{issues: data});
|
|
|
|
|
$('#issue-container').prepend(html);
|
2016-03-31 20:43:06 +08:00
|
|
|
|
$('.post-reply-submit').click(function(){
|
2016-04-01 23:22:39 +08:00
|
|
|
|
IssueReplyInsert();
|
2016-03-31 20:43:06 +08:00
|
|
|
|
});
|
2016-04-01 22:35:44 +08:00
|
|
|
|
/*$('post-interactive-praise').click(function(){
|
2016-04-01 14:58:41 +08:00
|
|
|
|
praiseClick();
|
2016-04-01 22:35:44 +08:00
|
|
|
|
});*/
|
2016-03-31 20:43:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var loadDataFromServer = function(id){
|
|
|
|
|
//getOpenId(function(openid){
|
|
|
|
|
$.ajax({
|
2016-04-01 20:53:21 +08:00
|
|
|
|
url: apiUrl + 'issues/' + id,
|
2016-03-31 20:43:06 +08:00
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function(data){
|
|
|
|
|
setTemplate(data.data);
|
|
|
|
|
},
|
|
|
|
|
error: function(xhr,status,err){
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-01 23:48:29 +08:00
|
|
|
|
var IssueUrl = window.location.search;
|
|
|
|
|
var IssueID = IssueUrl.split("=")[1];
|
2016-04-01 14:58:41 +08:00
|
|
|
|
|
2016-04-01 23:48:29 +08:00
|
|
|
|
loadDataFromServer(IssueID);
|
2016-03-31 20:43:06 +08:00
|
|
|
|
|
|
|
|
|
//点击回复按钮,插入回复内容
|
2016-04-01 23:22:39 +08:00
|
|
|
|
var IssueReplyInsert = function(){
|
2016-03-31 20:43:06 +08:00
|
|
|
|
var replyContent = $("#postInput").val();
|
|
|
|
|
if (!replyContent){
|
|
|
|
|
alert("请输入回复");
|
|
|
|
|
}else{
|
2016-04-01 14:58:41 +08:00
|
|
|
|
|
|
|
|
|
//将用户输入内容插入最后一条回复
|
2016-04-01 23:22:39 +08:00
|
|
|
|
/*$(".post-reply-wrap:last").after('<div class="post-reply-wrap border-bottom"><div class="post-reply-row"><div class="post-reply-avatar fl"><img src="images/post-avatar.jpg" width="45" height="45" /></div><div class="ml55"><div class="post-reply-user hidden">Mrs. Ashford</div><div class="post-reply-content c-grey2 mb10"></div><div class="post-reply-date fl"></div><div class="post-reply-trigger fr undis">回复</div></div><div class="cl"></div></div> </div>');
|
2016-03-31 20:43:06 +08:00
|
|
|
|
$(".post-reply-content:last").append(replyContent);
|
2016-04-01 23:22:39 +08:00
|
|
|
|
$(".post-reply-date:last").append(Date());*/
|
2016-04-01 14:58:41 +08:00
|
|
|
|
var postInput = $("#postInput").val();
|
|
|
|
|
$("#postInput").val("");
|
|
|
|
|
//回复数目+1
|
|
|
|
|
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
|
|
|
|
|
replyNum++;
|
|
|
|
|
$(".reply-num").text("(" + replyNum + ")");
|
|
|
|
|
|
2016-04-02 08:13:52 +08:00
|
|
|
|
getOpenId(function(openid) {
|
|
|
|
|
//获取并传送回复用户数据
|
|
|
|
|
var userInfo = {
|
|
|
|
|
"type": "Issue",
|
|
|
|
|
"content": postInput,
|
|
|
|
|
openid: openid,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST", //提交方式
|
|
|
|
|
dataType: "json", //类型
|
|
|
|
|
url: apiUrl + 'new_comment/' + IssueID, //提交的页面,方法名
|
|
|
|
|
data: userInfo, //参数,如果没有,可以为null
|
|
|
|
|
success: function (data) { //如果执行成功,那么执行此方法
|
|
|
|
|
setReplyTemplate(data.data);
|
|
|
|
|
},
|
|
|
|
|
error: function (err) { //如果执行不成功,那么执行此方法
|
|
|
|
|
alert("err:" + err);
|
|
|
|
|
}
|
|
|
|
|
})
|
2016-04-01 14:58:41 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-01 22:35:44 +08:00
|
|
|
|
};
|
2016-03-31 20:43:06 +08:00
|
|
|
|
|
2016-04-01 14:58:41 +08:00
|
|
|
|
//点赞效果
|
2016-04-01 22:35:44 +08:00
|
|
|
|
/*var praiseClick = function(){
|
2016-04-01 14:58:41 +08:00
|
|
|
|
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
|
|
|
|
|
praiseNum++;
|
|
|
|
|
$(".praise-num").text("(" + praiseNum + ")");
|
2016-04-01 23:21:18 +08:00
|
|
|
|
};*/
|
2016-04-01 14:58:41 +08:00
|
|
|
|
|
|
|
|
|
|
2016-03-31 20:43:06 +08:00
|
|
|
|
});
|