From 8c7de04dbf1cd60640e67a66348cdfb86c184f5a Mon Sep 17 00:00:00 2001 From: txz Date: Tue, 5 Apr 2016 10:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=97=AE=E7=AD=94=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/wechat/activities.html | 2 +- public/assets/wechat/course_discussion.html | 5 +- public/assets/wechat/project_discussion.html | 51 +++++---- .../javascripts/wechat/project_discussion.js | 102 ++++++++++++++++++ 4 files changed, 138 insertions(+), 22 deletions(-) diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index 68e8519aa..51bdc474f 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -148,7 +148,7 @@
-
class="c-grey"> 回复 ()
+
回复 ()
赞 ()
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index b5d56cd7e..af95df634 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -1,7 +1,7 @@ - 课程讨论区 + 课程问答区 @@ -19,13 +19,12 @@ + + - + diff --git a/public/javascripts/wechat/project_discussion.js b/public/javascripts/wechat/project_discussion.js index 0ba69c153..94cdcea10 100644 --- a/public/javascripts/wechat/project_discussion.js +++ b/public/javascripts/wechat/project_discussion.js @@ -1,3 +1,105 @@ /** * Created by root on 4/1/16. */ +/** + * Created by root on 4/1/16. + */ +$(document).ready(function(){ + + var bt=baidu.template; + bt.LEFT_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('
回复
'); + $(".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 + ")"); + }*/ + + +}); \ No newline at end of file