portal html css js resource

qa-show.js 16KB

    $(function() { loginStatus();//判断个人是否登录 var userid = $.cookie("userid"), username = $.cookie("userName") var questionId = GetQueryString("id"); var hurl = window.location.host, weibourl = window.location.href weibopic = "http://" + hurl + "/images/logo180.png", weibotitle = ""; var oanswer = document.getElementsByClassName("go-answer")[0]; if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){ location.href="http://" + hurl + "/e/wen.html?id="+questionId; } var rows = 20, ifAl=1,//是否是首次加载 dataO = { time: "", id: "", score:"" }; var oAjax = function(url, dataS, otype, oFun) { $.ajax({ url:url, dataType: 'json', type: otype, data: dataS, traditional: true, success: function(res) { if(res.success) { oFun(res) } } }); }, waitingA=function(){ oAjax("/ajax/question", { "rows": rows },"get", function(res){ var $info = res.data; if($info.length>0){ $("#waitingA").parents(".conItem").removeClass("displayNone") var oLeng=$info.length<5?$info.length:5; for(var i = 0; i < oLeng; i++) { var itemlist = '<li class="flexCenter"><a class="urlgo" target="_blank" href="qa-show.html?id='+$info[i].id+'">'; itemlist += '<p class="h2Font ellipsisSty-2"><em class="circlePre"></em>'+$info[i].title+'</p>'; itemlist += '</a></li>'; $itemlist = $(itemlist); $("#waitingA").append($itemlist); } } }) }, getConmain = function() { oAjax('/ajax/question/qo', { "id": questionId }, "get", function(res) { var $da = res.data weibotitle = $da.title; document.getElementById("questionId").setAttribute("data-id", $da.id); document.getElementById("questionTit").innerHTML = $da.title; document.getElementById("pageview").innerHTML = $da.pageViews; document.getElementById("replyCount").innerHTML = $da.replyCount; if($da.cnt) { document.getElementById("questionCnt").innerHTML =($da.cnt).replace(/\n/g,"<br />"); } attendCount(); if($da.keys != undefined && $da.keys.length != 0) { var subs = new Array(); if($da.keys.indexOf(',')) { subs = $da.keys.split(','); } else { subs[0] = $da.keys; } var pstr = "" if(subs.length > 0) { for(var i = 0; i < subs.length; i++) { pstr += '<li><span class="h2Font">' + subs[i] + '</span></li>' }; document.getElementsByClassName("tagList")[0].innerHTML = pstr; } else { document.getElementsByClassName("tagList")[0].style.display = "none"; } } if($da.img) { var subs = new Array(); if($da.img.indexOf(',')) { subs = $da.img.split(','); } else { subs[0] = $da.img; } weibopic="http://" + hurl + "/data/question"+subs[0].replace(/.jpg/,"_s.jpg") var pstr = "" if(subs.length > 0) { for(var i = 0; i < subs.length; i++) { var imgu= "/data/question"+subs[i] pstr += '<li><span class="imgspan" style="background-image: url('+imgu+');"></span></li>' }; document.getElementsByClassName("list_image")[0].innerHTML = pstr; } else { document.getElementsByClassName("list_image")[0].style.display = "none"; } } $("#weibo").attr("href","http://service.weibo.com/share/share.php?appkey=3677230589&title="+encodeURIComponent(weibotitle)+"&url="+encodeURIComponent(weibourl)+"&pic="+encodeURIComponent(weibopic)+"&content=utf-8"+"&ralateUid=6242830109&searchPic=false&style=simple"); }) }, attendCount=function() { oAjax("/ajax/watch/countProfessor", { id:questionId, type:"8" }, "get", function(data) { if(data.success) { if(data.data > 0) { document.getElementById("attenCountQ").innerHTML =data.data; }else{ document.getElementById("attenCountQ").innerHTML =""; } } }) }, pageViews=function() { oAjax('/ajax/question/pageViews', { qid:questionId }, "POST", function(data) { if(data.success) { } }) }, anExist = function() { oAjax("/ajax/question/answer", { "qid": questionId, "uid": userid, }, "get", function(res) { if(res.data) { if(res.data.state=="1"){ oanswer.setAttribute("data-can", "0"); //回答过 oanswer.classList.add("answered"); oanswer.innerText = "我已回答" }else{ oanswer.setAttribute("data-anid",res.data.id); oanswer.setAttribute("data-can", "2"); //回答过但已删除 oanswer.classList.add("answerDel"); oanswer.innerText = "撤销删除" } } else { oanswer.setAttribute("data-can", "1"); } }) }, answerList = function() { var byway = document.querySelector('.list-hold-count>ul').querySelector("li.active").getAttribute("data-type"); var typeurl,dataStr={}; if(byway == 1) { typeurl = "/ajax/question/answer/qes/byScore" dataStr={ "qid": questionId, "score": dataO.score, "id": dataO.id, "rows": rows } } else if(byway == 2) { typeurl = "/ajax/question/answer/qes/byTime" dataStr={ "qid": questionId, "time": dataO.time, "id": dataO.id, "rows": rows } } oAjax(typeurl,dataStr, "get", function(res){ var aimId="curAnswers",newStr="暂无回答" var $info = res.data; if($info.length > 0) { if(byway == 1) { dataO.score = $info[$info.length - 1].score; dataO.id = $info[$info.length - 1].id; }else if(byway == 2) { dataO.time = $info[$info.length - 1].createTime; dataO.id = $info[$info.length - 1].id; } for(var i = 0; i < $info.length; i++) { var liStr = document.createElement("li"); document.getElementById(aimId).appendChild(liStr); answerModule($info[i], liStr); } } var liLen=document.getElementById(aimId).querySelectorAll("li").length; removeAfter(aimId); if($info.length == 0 && liLen == 0 ){ insertAfter(newStr,aimId); } }) }, insertAfter = function (newStr, targetE) { var parent = document.getElementById(targetE).parentNode; var kong = document.createElement("div"); kong.className = "con-kong"; kong.innerHTML = newStr; if (parent.firstChild.className == "con-kong") { return } else { parent.insertBefore(kong,parent.firstChild); } }, removeAfter = function (targetE) { var parent = document.getElementById(targetE).parentNode; if (parent.firstChild.className == "con-kong") { parent.removeChild(parent.firstChild); } else { return } }, answerModule = function(dataStr, liStr) { var time='' if(userid==dataStr.uid){ time="修改于 "+commenTime(dataStr.modifyTime) }else{ time="发布于 "+commenTime(dataStr.createTime) } liStr.className="list-qa" liStr.setAttribute("data-id", dataStr.id); var operatStr='<div class="list_hander clearfix">'+ '<div class="holdSpan floatL">'+ '<div class="zan"><em class="hold-icon icon-zan"></em><span class="agreeCount"></span></div>'+ '<div class="cai"><em class="hold-icon icon-cai"></em></div>'+ '</div>'+ '<div class="operateBlock bottomShow floatL">'+ '<ul class="clearfix">'+ '<li><span>留言</span><span class="leaveMsgCount"></span><em class="operateicon operateicon2 icon-leavemsg"></em></li>'+ '<li class="attention"><span>收藏</span><em class="operateicon operateicon2 icon-collect collectBtn"></em></li>'+ '<li>'+ '<span>分享到</span>'+ '<a class="weiboA" href="" target="_blank"><em class="operateicon operateicon2 icon-sina"></em></a>'+ '<em class="operateicon operateicon2 icon-wechat shareWeixin">'+ '<div class="shareCode clearfix">'+ '<div class="floatL qrcodeQA"></div>'+ '<div class="shareWord floatR">'+ '<p>打开微信“扫一扫”,<br/>打开网页后点击屏幕右上角“分享”按钮</p>'+ '</div>'+ '</div>'+ '</em>'+ '</li>'+ '</ul>'+ '</div>'+ '<div class="operateBlock tip-offs floatR"><span>举报</span></div>'+ '</div>' liStr.innerHTML = '<div class="madiaInfo">' + '<div class="flexCenter qa-owner"></div>' + '<p class="qa-con ellipsisSty-3">' + (dataStr.cnt).replace(/\n/g,"<br />") + '</p>' + '<div class="item_info"><span class="time">' + time + '</span></div>'+operatStr+'</div>' var $str = $(liStr) proinfo(dataStr.uid, $str); leaveMsgCount(dataStr.id, $str); answerAgreeNum(dataStr.id, $str); if(userid && userid != null && userid != "null") { isAgree(dataStr.id, $str) ifcollectionAbout(dataStr.id,$str.find(".collectBtn"),9); } answerBindE(dataStr.id, $str) }, answerAgreeNum=function(anid,$str){ oAjax("/ajax/question/answer", { id:anid }, "get", function(data) { if(data.success) { if(data.data.agree > 0) { $str.find(".agreeCount").html(data.data.agree); } } }) }, answerBindE=function(anid,$str){ //收藏 $str.find(".collectBtn").on('click', function() { if(userid && userid != null && userid != "null") { if($(this).is('.icon-collected')){ cancelCollectionAbout(anid,$(this),8) } else { collectionAbout(anid,$(this),8); } }else{ quickLog(); operatTab(); closeLog(); } }); //点赞回答 $str.find(".zan").on("click",function(){ if(userid && userid != null && userid != "null") { if($(this).is('.active')){ oAjax('/ajax/question/answer/agree/cancle', { "id": anid, "uid":userid, "uname":username }, "POST", function(res) { $str.find(".zan").removeClass("active") }) }else{ oAjax('/ajax/question/answer/agree', { "id": anid, "uid":userid, "uname":username }, "POST", function(res) { $str.find(".zan").addClass("active") $str.find(".cai").removeClass("active") }) } answerAgreeNum(anid, $(this).parents(".list-qa")); }else{ quickLog(); operatTab(); closeLog(); } }) //踩回答 $str.find(".cai").on("click",function(){ if(userid && userid != null && userid != "null") { if($(this).is('.active')){ oAjax('/ajax/question/answer/oppose/cancle', { "id":anid, "uid":userid, "uname":username }, "POST", function(res) { $str.find(".cai").removeClass("active") }) }else{ oAjax('/ajax/question/answer/oppose', { "id":anid, "uid":userid, "uname":username }, "POST", function(res) { $str.find(".cai").addClass("active") $str.find(".zan").removeClass("active") }) } answerAgreeNum(anid, $(this).parents(".list-qa")); }else{ quickLog(); operatTab(); closeLog(); } }) //微信分享 $str.find('.shareWeixin').on("mouseenter",function(){ $(this).find('.shareCode').stop(true,false).fadeIn(); }).on("mouseleave",function(){ $(this).find('.shareCode').stop(true,false).fadeOut(); }); var Qcu=$str.find(".qrcodeQA"); for(var i=0;i<Qcu.length;i++){ var qrcode= new QRCode(Qcu[i], { width : 100, height : 100 }); var elurl = "http://" + hurl + "/e/da.html?id="+anid; qrcode.makeCode(elurl); } //微博分享 $str.find(".weiboA").attr("href","http://service.weibo.com/share/share.php?appkey=3677230589&title="+encodeURIComponent(weibotitle)+"&url="+encodeURIComponent(weibourl)+"&pic="+encodeURIComponent(weibopic)+"&content=utf-8"+"&ralateUid=6242830109&searchPic=false&style=simple"); }, leaveMsgCount=function(id, $str) { oAjax("/ajax/leavemsg/count", { sid:id, stype: "4" }, "get", function(data) { if(data.success) { if(data.data > 0) { $str.find(".leaveMsgCount").html(data.data); } } }) }, proinfo = function(pid, $str) { oAjax("/ajax/professor/baseInfo/" + pid, {}, "get", function(res) { var dataStr = res.data var baImg = "../images/default-photo.jpg"; if(dataStr.hasHeadImage == 1) { baImg = "/images/head/" + dataStr.id + "_l.jpg"; } var userType = autho(dataStr.authType, dataStr.orgAuth, dataStr.authStatus); var os = ""; if(dataStr.title) { if(dataStr.orgName) { os = dataStr.title + "," + dataStr.orgName; } else { os = dataStr.title; } } else { if(dataStr.office) { if(dataStr.orgName) { os = dataStr.office + "," + dataStr.orgName; } else { os = dataStr.office; } } else { if(dataStr.orgName) { os = dataStr.orgName; } } } var str = '<div class="owner-head useHead" style="background-image:url(' + baImg + ')"></div>' + '<div class="owner-info">' + '<div class="owner-name">' + dataStr.name + '<em class="authiconNew ' + userType.sty + '" title="' + userType.title + '"></em></div>' + '<div class="owner-tit ellipsisSty h2Font">' + os + '</div>' + '</div>'+ '<div class="goSpan"><span class="attenSpan">关注</span></div>' $str.find(".qa-owner").html(str); if(dataStr.id!=userid){ ifcollectionAbout(dataStr.id,$str.find(".attenSpan"),1); }else{ $str.find(".attenSpan").hide() } }); }, isAgree=function(id,$str){ oAjax('/ajax/question/answer/agree', { "aid": id, "uid":userid }, "get", function(res) { if(res.success){ console.log(res) if(res.data==null){ }else if(res.data.flag){ $str.find(".zan").addClass("active") }else{ $str.find(".cai").addClass("active") } } }) } pageViews(); getConmain(); waitingA(); answerList(); if(userid && userid != null && userid != "null") { anExist(); //判断是否回答过该问题 ifcollectionAbout(questionId, $("#attention"), 8); } $(".list-hold-count>ul").on('click', 'li', function(e) { var sortlist = document.querySelector('.list-hold-count>ul').querySelectorAll("li"); for(var i = 0; i < sortlist.length; i++) { sortlist[i].classList.remove('active'); } this.classList.add('active'); byway = this.getAttribute("data-type"); document.getElementById("curAnswers").innerHTML = ""; dataO = {time: "",id: "",score:""} answerList() }); $("#attention").on('click', function() { if(userid && userid != null && userid != "null") { if($(this).is('.icon-collected')){ cancelCollectionAbout(questionId,$(this),8) } else { collectionAbout(questionId,$(this),8); } attendCount() }else{ quickLog(); operatTab(); closeLog(); } }); $(".go-answer").on('click', function() { var can = this.getAttribute("data-can"); if(userid && userid != null && userid != "null") { if(can=="1") { alert("回答") } else if(can=="2") { var anid= this.getAttribute("data-anid"); oAjax("/ajax/question/answer/unDel", { "qid": questionId, "id": anid, }, "get", function(res) { if(res.data=="1") { oanswer.setAttribute("data-can", "0"); //回答过 oanswer.classList.add("answered"); oanswer.innerText = "我已回答" } }) }else{ return } } else { quickLog(); operatTab(); closeLog(); } }) $(".invite-answer").on('click', function() { if(userid && userid != null && userid != "null") { plus.nativeUI.showWaiting(); plus.webview.create("../html/qa-request-da.html", 'qa-request-da.html', {}, { "quid": questionId }); } else { isLogin(); } }) //纠错反馈 $(".correctSubmit").on("click",function(){ var cntCon=$(this).siblings(".correctCon").val(); var cntUser=""; if(userid && userid != null && userid != "null") { cntUser = userid; } if(cntCon.length>500){ $.MsgBox.Alert('提示', '纠错反馈内容不得超过500个字'); return; }else{ $.ajax({ "url": "/ajax/feedback/error/professor", "type": "POST", "dataType": "json", "async": true, "data": { "id": questionId, "cnt":cntCon, "user":cntUser }, "success": function(data) { if(data.success) { backSuccessed(); } }, "error": function() { $.MsgBox.Alert('提示', '链接服务器超时') } }); } }) })