socialforge/public/javascripts/wechat/project_discussion.js

105 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Created by root on 4/1/16.
*/
/**
* Created by root on 4/1/16.
*/
$(document).ready(function(){
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
var apiUrl = '/api/v1/';
var setReplyTemplate = function(data){
console.log(data);
var html=bt('t:homework-detail-reply',{reply: data});
$('#all_homework_reply').prepend(html);
};
var setTemplate = function(data){
console.log(data);
var html=bt('t:project-discussion',{discussion: data});
$('#p-discussion-container').prepend(html);
$('.post-reply-submit').click(function(){
replyInsert();
});
/*$('post-interactive-praise').click(function(){
praiseClick();
});*/
};
var loadDataFromServer = function(id){
//getOpenId(function(openid){
$.ajax({
url: apiUrl + 'messages/' + id,
dataType: 'json',
success: function(data){
setTemplate(data.data);
},
error: function(xhr,status,err){
console.log(err);
}
});
//})
};
var homeworkUrl = window.location.search;
var homeworkID = homeworkUrl.split("=")[1];
loadDataFromServer(homeworkID);
//点击回复按钮,插入回复内容
var replyInsert = function(){
var replyContent = $("#postInput").val();
if (!replyContent){
alert("请输入回复");
}else{
/*//将用户输入内容插入最后一条回复
$(".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>');
$(".post-reply-content:last").append(replyContent);
$(".post-reply-date:last").append(Date());*/
var postInput = $("#postInput").val();
$("#postInput").val("");
//回复数目+1
var replyNum = $(".post-interactive-reply").text().match(/\d+/g);
replyNum++;
$(".reply-num").text("(" + replyNum + ")");
//获取并传送回复用户数据
var userInfo = {
"type" : "Message",
"content" : postInput
};
$.ajax({
type: "POST", //提交方式
dataType: "json", //类型
url: apiUrl + 'new_comment/' + homeworkID, //提交的页面,方法名
data: userInfo, //参数如果没有可以为null
success: function (data) { //如果执行成功,那么执行此方法
setReplyTemplate(data.data); //用data.d来获取后台传过来的json语句或者是单纯的语句
},
error: function (err) { //如果执行不成功,那么执行此方法
alert("err:" + err);
}
});
}
}
//点赞效果
/*var praiseClick = function(){
var praiseNum = $(".post-interactive-praise").text().match(/\d+/g);
praiseNum++;
$(".praise-num").text("(" + praiseNum + ")");
}*/
});