portal html css js resource

qa-show.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. $(function() {
  2. loginStatus();//判断个人是否登录
  3. $("#feedback").hide();
  4. var userid = $.cookie("userid"),
  5. username = $.cookie("userName")
  6. var questionId = GetQueryString("id"),
  7. topAnswerId = GetQueryString("topid");
  8. var hurl = window.location.host,
  9. weibourl = window.location.href
  10. weibopic = "http://" + hurl + "/images/logo180.png",
  11. weibotitle = "";
  12. var oanswer = document.getElementsByClassName("go-answer")[0];
  13. module.lWord;
  14. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
  15. location.href="http://" + hurl + "/e/wen.html?id="+questionId;
  16. }
  17. var rows = 2,
  18. dataO = {
  19. time: "",
  20. id: "",
  21. score:""
  22. };
  23. var rowsR = 10,
  24. pageNum=1,
  25. dataC = {
  26. count: "",
  27. pid: ""
  28. }
  29. var dataT={
  30. id: "",
  31. score:""
  32. }
  33. var oAjax = function(url, dataS, otype, oFun,beforeFun,completeFun) {
  34. $.ajax({
  35. url:url,
  36. dataType: 'json',
  37. type: otype,
  38. data: dataS,
  39. traditional: true,
  40. beforeSend: beforeFun,
  41. success: function(res) {
  42. if(res.success) {
  43. oFun(res)
  44. }
  45. },
  46. complete:completeFun
  47. });
  48. },
  49. waitingA=function(){
  50. oAjax("/ajax/question", {
  51. "rows": rows
  52. },"get", function(res){
  53. var $info = res.data;
  54. if($info.length>0){
  55. $("#waitingA").parents(".conItem").removeClass("displayNone")
  56. var oLeng=$info.length<5?$info.length:5;
  57. for(var i = 0; i < oLeng; i++) {
  58. var itemlist = '<li class="flexCenter"><a class="urlgo" target="_blank" href="qa-show.html?id='+$info[i].id+'">';
  59. itemlist += '<p class="h2Font ellipsisSty-2"><em class="circlePre"></em>'+$info[i].title+'</p>';
  60. itemlist += '</a></li>';
  61. $itemlist = $(itemlist);
  62. $("#waitingA").append($itemlist);
  63. }
  64. }
  65. })
  66. },
  67. getConmain = function() {
  68. oAjax('/ajax/question/qo', {
  69. "id": questionId
  70. }, "get", function(res) {
  71. var $da = res.data
  72. weibotitle = $da.title;
  73. document.getElementById("questionId").setAttribute("data-id", $da.id);
  74. document.getElementById("questionTit").innerHTML = $da.title;
  75. document.getElementById("pageview").innerHTML = $da.pageViews;
  76. document.getElementById("replyCount").innerHTML = $da.replyCount;
  77. if($da.cnt) {
  78. document.getElementById("questionCnt").innerHTML =($da.cnt).replace(/\n/g,"<br />");
  79. }
  80. attendCount();
  81. if($da.keys != undefined && $da.keys.length != 0) {
  82. var subs = new Array();
  83. if($da.keys.indexOf(',')) {
  84. subs = $da.keys.split(',');
  85. } else {
  86. subs[0] = $da.keys;
  87. }
  88. var pstr = ""
  89. if(subs.length > 0) {
  90. for(var i = 0; i < subs.length; i++) {
  91. pstr += '<li><span class="h2Font">' + subs[i] + '</span></li>'
  92. };
  93. document.getElementsByClassName("tagList")[0].innerHTML = pstr;
  94. } else {
  95. document.getElementsByClassName("tagList")[0].style.display = "none";
  96. }
  97. }
  98. if($da.img) {
  99. var subs = new Array();
  100. if($da.img.indexOf(',')) {
  101. subs = $da.img.split(',');
  102. } else {
  103. subs[0] = $da.img;
  104. }
  105. weibopic="http://" + hurl + "/data/question"+subs[0].replace(/.jpg/,"_s.jpg")
  106. var pstr = ""
  107. if(subs.length > 0) {
  108. for(var i = 0; i < subs.length; i++) {
  109. var imgu= "/data/question"+subs[i]
  110. pstr += '<li><span class="imgspan" style="background-image: url('+imgu+');"><img src="'+imgu+'" data-preview-src="" /></span></li>'
  111. };
  112. document.getElementsByClassName("list_image")[0].style.display = "block";
  113. document.getElementsByClassName("list_image")[0].innerHTML = pstr;
  114. }
  115. $('.list_image img').zoomify();
  116. }
  117. $("#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");
  118. })
  119. },
  120. attendCount=function() {
  121. oAjax("/ajax/watch/countProfessor", {
  122. id:questionId,
  123. type:"8"
  124. }, "get", function(data) {
  125. if(data.success) {
  126. if(data.data > 0) {
  127. document.getElementById("attenCountQ").innerHTML =data.data;
  128. }else{
  129. document.getElementById("attenCountQ").innerHTML ="";
  130. }
  131. }
  132. })
  133. },
  134. pageViews=function() {
  135. oAjax('/ajax/question/pageViews', {
  136. qid:questionId
  137. }, "POST", function(data) {
  138. if(data.success) {
  139. }
  140. })
  141. },
  142. anExist = function() {
  143. oAjax("/ajax/question/answer", {
  144. "qid": questionId,
  145. "uid": userid,
  146. }, "get", function(res) {
  147. if(res.data) {
  148. if(res.data.state=="1"){
  149. oanswer.setAttribute("data-can", "0"); //回答过
  150. oanswer.classList.add("answered");
  151. oanswer.innerText = "我已回答"
  152. }else{
  153. oanswer.setAttribute("data-anid",res.data.id);
  154. oanswer.setAttribute("data-can", "2"); //回答过但已删除
  155. oanswer.classList.add("answerDel");
  156. oanswer.innerText = "撤销删除"
  157. }
  158. } else {
  159. oanswer.setAttribute("data-can", "1");
  160. }
  161. })
  162. },
  163. answerList = function() {
  164. var byway = document.querySelector('.list-hold-count>ul').querySelector("li.active").getAttribute("data-type");
  165. var typeurl,dataStr={};
  166. if(byway == 1) {
  167. typeurl = "/ajax/question/answer/qes/byScore"
  168. dataStr={
  169. "qid": questionId,
  170. "score": dataO.score,
  171. "id": dataO.id,
  172. "rows": rows
  173. }
  174. } else if(byway == 2) {
  175. typeurl = "/ajax/question/answer/qes/byTime"
  176. dataStr={
  177. "qid": questionId,
  178. "time": dataO.time,
  179. "id": dataO.id,
  180. "rows": rows
  181. }
  182. }
  183. oAjax(typeurl,dataStr, "get", function(res){
  184. var aimId="curAnswers",newStr="还没有人回答该问题,<span class='nowAn'>点击这里马上抢答</span>"
  185. var $info = res.data;
  186. if($info.length > 0) {
  187. if(byway == 1) {
  188. dataO.score = $info[$info.length - 1].score;
  189. dataO.id = $info[$info.length - 1].id;
  190. }else if(byway == 2) {
  191. dataO.time = $info[$info.length - 1].createTime;
  192. dataO.id = $info[$info.length - 1].id;
  193. }
  194. for(var i = 0; i < $info.length; i++) {
  195. var liStr = document.createElement("li");
  196. document.getElementById(aimId).appendChild(liStr);
  197. answerModule($info[i], liStr);
  198. }
  199. }
  200. var liLen=document.getElementById(aimId).querySelectorAll("li").length;
  201. removeAfter(aimId);
  202. if($info.length == 0 && liLen == 0 ){
  203. insertAfter(newStr,aimId);
  204. }
  205. $("#curAnswers").parent().find(".js-load-more").on("click",function(){
  206. answerList()
  207. })
  208. if ($info.length < rows) {
  209. $("#curAnswers").parent().find(".js-load-more").unbind("click");
  210. $("#curAnswers").parent().find(".js-load-more").hide();
  211. }
  212. //点击马上抢答
  213. $("#curAnswers").parent().find(".nowAn").on('click', function() {
  214. if(userid && userid != null && userid != "null") {
  215. goAnswerFn($(".answerQu"))
  216. }else{
  217. quickLog();
  218. operatTab();
  219. closeLog();
  220. }
  221. });
  222. },function(){
  223. $("#curAnswers").parent().find(".js-load-more").attr("disabled",true);
  224. $("#curAnswers").parent().find(".js-load-more").addClass("active");
  225. },function(){
  226. $("#curAnswers").parent().find(".js-load-more").removeAttr("disabled");
  227. $("#curAnswers").parent().find(".js-load-more").removeClass("active");
  228. })
  229. },
  230. answerTop=function(answerId){
  231. oAjax('/ajax/question/answer', {
  232. "id": answerId
  233. }, "get", function(res) {
  234. var $da = res.data
  235. var liStr = document.createElement("li");
  236. document.getElementById("topAnshow").appendChild(liStr);
  237. answerModule($da, liStr);
  238. })
  239. },
  240. answerThisShow=function(){
  241. var typeurl = "/ajax/question/answer/qes/byScore",
  242. dataStr={
  243. "qid": questionId,
  244. "score": dataT.score,
  245. "id": dataT.id,
  246. "rows": rows
  247. }
  248. oAjax(typeurl,dataStr, "get", function(res){
  249. console.log(res)
  250. var $info = res.data;
  251. if($info.length > 0) {
  252. if($info.length>1){
  253. $(".otherAn").removeClass("displayNone")
  254. }
  255. dataT.score = $info[$info.length - 1].score;
  256. dataT.id = $info[$info.length - 1].id;
  257. for(var i = 0; i < $info.length; i++) {
  258. if($info[i].id==topAnswerId){
  259. }else{
  260. var liStr = document.createElement("li");
  261. document.getElementById("otherAnshow").appendChild(liStr);
  262. answerModule($info[i], liStr);
  263. }
  264. }
  265. }
  266. $("#otherAnshow").parent().find(".js-load-more").on("click",function(){
  267. answerThisShow()
  268. })
  269. if ($info.length < rows) {
  270. $("#otherAnshow").parent().find(".js-load-more").unbind("click");
  271. $("#otherAnshow").parent().find(".js-load-more").hide();
  272. }
  273. },function(){
  274. $("#otherAnshow").parent().find(".js-load-more").attr("disabled",true);
  275. $("#otherAnshow").parent().find(".js-load-more").addClass("active");
  276. },function(){
  277. $("#otherAnshow").parent().find(".js-load-more").removeAttr("disabled");
  278. $("#otherAnshow").parent().find(".js-load-more").removeClass("active");
  279. })
  280. },
  281. insertAfter = function (newStr, targetE) {
  282. var parent = document.getElementById(targetE).parentNode;
  283. var kong = document.createElement("div");
  284. kong.className = "con-kong";
  285. kong.innerHTML = newStr;
  286. if (parent.firstChild.className == "con-kong") {
  287. return
  288. } else {
  289. parent.insertBefore(kong,parent.firstChild);
  290. }
  291. },
  292. removeAfter = function (targetE) {
  293. var parent = document.getElementById(targetE).parentNode;
  294. if (parent.firstChild.className == "con-kong") {
  295. parent.removeChild(parent.firstChild);
  296. } else {
  297. return
  298. }
  299. },
  300. answerModule = function(dataStr, liStr) {
  301. var time="发布于 "+commenTime(dataStr.createTime)
  302. var opertStr='<span class="jubao">举报</span>'
  303. var zancai='<div class="zan canZan"><em class="hold-icon icon-zan"></em><span class="agreeCount"></span></div>'+
  304. '<div class="cai canCai"><em class="hold-icon icon-cai"></em></div>'
  305. if(dataStr.uid==userid){
  306. var ballot=""
  307. if(dataStr.ballot>0){
  308. ballot=dataStr.ballot
  309. }
  310. opertStr='<span class="xiugai">修改</span><span class="shanchu">删除</span>'
  311. time="修改于 "+commenTime(dataStr.modifyTime)
  312. zancai='<div class="zan noZan"><em class="hold-icon icon-zan"></em><span class="agreeCount"></span></div>'+
  313. '<div class="cai noCai"><em class="hold-icon icon-cai"></em> <span>'+ballot+'</span></div>'
  314. }
  315. liStr.className="list-qa"
  316. liStr.setAttribute("data-id", dataStr.id);
  317. var operatStr='<div class="list_hander clearfix" data-type="2">'+
  318. '<div class="holdSpan floatL">'+zancai+
  319. '</div>'+
  320. '<div class="operateBlock bottomShow floatL">'+
  321. '<ul class="clearfix">'+
  322. '<li><span>留言</span><span class="leaveMsgCount"></span><em class="operateicon operateicon2 icon-leavemsg leaveWo"></em></li>'+
  323. '<li class="attention"><span>收藏</span><em class="operateicon operateicon2 icon-collect collectBtn"></em></li>'+
  324. '<li>'+
  325. '<span>分享到</span>'+
  326. '<a class="weiboA" href="" target="_blank"><em class="operateicon operateicon2 icon-sina"></em></a>'+
  327. '<em class="operateicon operateicon2 icon-wechat shareWeixin">'+
  328. '<div class="shareCode clearfix">'+
  329. '<div class="floatL qrcodeQA"></div>'+
  330. '<div class="shareWord floatR">'+
  331. '<p>打开微信“扫一扫”,<br/>打开网页后点击屏幕右上角“分享”按钮</p>'+
  332. '</div>'+
  333. '</div>'+
  334. '</em>'+
  335. '</li>'+
  336. '</ul>'+
  337. '</div>'+
  338. '<div class="operateBlock tip-offs floatR">'+opertStr+'</div>'+
  339. '</div>'
  340. liStr.innerHTML = '<div class="madiaInfo answerInfo"><a target="_blank" href="/qa-show.html?id='+dataStr.qid+'&topid='+dataStr.id+'">' +
  341. '<div class="flexCenter qa-owner"></div>' +
  342. '<p class="qa-con ellipsisSty-3">' + (dataStr.cnt).replace(/\n/g,"<br />") + '</p></a>' +
  343. '<div class="item_info"><span class="time">' + time + '</span></div>'+
  344. operatStr+
  345. '</div>'+
  346. '<div class="answerUpdate"></div>'+
  347. '<div class="answerWord"></div>'
  348. var $str = $(liStr)
  349. proinfo(dataStr.uid, $str);
  350. leaveMsgCount(dataStr.id, $str);
  351. answerAgreeNum(dataStr.id, $str);
  352. if(userid && userid != null && userid != "null") {
  353. isAgree(dataStr.id, $str)
  354. ifcollectionAbout(dataStr.id,$str.find(".collectBtn"),9);
  355. }
  356. answerBindE(dataStr.id, $str)
  357. },
  358. goAnswerFn=function(objN,anid,text,aflag){
  359. var dataStr={},typeUrl="",tip="";
  360. var str='<div class="madiaInfo"><div class="flexCenter qa-owner"></div></div>'+
  361. '<div class="msgContbox"><textarea class="frmcontype msgCont quCNT" placeholder="请填写回答内容..."></textarea></div>'+
  362. '<div class="buttonbox">'+
  363. '<button type="button" class="frmcontype btnModel fontLink">取消</button>'+
  364. '<button type="button" class="frmcontype btnModel saveGo">保存</button>'+
  365. '</div>'
  366. objN.html(str);
  367. proinfo(userid,objN);
  368. if(aflag){
  369. objN.show();
  370. objN.find(".quCNT").val(text)
  371. objN.parents(".list-qa").find(".answerInfo").hide()
  372. }else{
  373. objN.slideDown(300);
  374. }
  375. objN.find(".buttonbox").on("click",".saveGo",function(){
  376. var conV=objN.find(".quCNT").val();
  377. if(conV.length<10) {
  378. $.MsgBox.Alert("提示", "回答不得少于10个字");
  379. return;
  380. }
  381. if(aflag){
  382. typeUrl='/ajax/question/answer/modify'
  383. dataStr={
  384. "id": anid,
  385. "cnt": conV,
  386. "uid": userid,
  387. "uname": username
  388. }
  389. tip="回答修改成功"
  390. }else{
  391. typeUrl='/ajax/question/answer'
  392. dataStr={
  393. "qid": questionId,
  394. "cnt": conV,
  395. "uid": userid,
  396. "uname": username
  397. }
  398. tip="回答发布成功"
  399. }
  400. oAjax(typeUrl,dataStr, "post", function(res) {
  401. if(aflag){
  402. objN.hide()
  403. objN.parents(".list-qa").find(".answerInfo").show()
  404. }else{
  405. objN.slideUp(300);
  406. }
  407. objN.html("");
  408. $.MsgBox.Alert("提示", tip);
  409. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  410. window.location.reload();
  411. })
  412. })
  413. objN.find(".buttonbox").on("click",".fontLink",function(){
  414. if(aflag){
  415. objN.hide()
  416. objN.parents(".list-qa").find(".answerInfo").show()
  417. }else{
  418. objN.slideUp(300);
  419. }
  420. objN.html("");
  421. })
  422. },
  423. answerAgreeNum=function(anid,$str){
  424. oAjax("/ajax/question/answer", {
  425. id:anid
  426. }, "get", function(data) {
  427. if(data.success) {
  428. if(data.data.agree > 0) {
  429. $str.find(".agreeCount").css("margin-left","6px")
  430. $str.find(".agreeCount").html(data.data.agree);
  431. }
  432. }
  433. })
  434. },
  435. answerBindE=function(anid,$str){
  436. //收藏
  437. $str.find(".collectBtn").on('click', function() {
  438. if(userid && userid != null && userid != "null") {
  439. if($(this).is('.icon-collected')){
  440. cancelCollectionAbout(anid,$(this),8)
  441. } else {
  442. collectionAbout(anid,$(this),8);
  443. }
  444. }else{
  445. quickLog();
  446. operatTab();
  447. closeLog();
  448. }
  449. });
  450. //留言
  451. $str.find(".leaveWo").on('click', function() {
  452. $(".list-qa").find(".answerWord").html("");
  453. if(userid && userid != null && userid != "null") {
  454. module.lWord.init($(this).parents(".list-qa").find(".answerWord"),{sid:anid,stype:4});
  455. }else{
  456. quickLog();
  457. operatTab();
  458. closeLog();
  459. }
  460. });
  461. //点赞回答
  462. $str.find(".zan").on("click",function(){
  463. if(userid && userid != null && userid != "null") {
  464. if($(this).is('.active')){
  465. oAjax('/ajax/question/answer/agree/cancle', {
  466. "id": anid,
  467. "uid":userid,
  468. "uname":username
  469. }, "POST", function(res) {
  470. $str.find(".zan").removeClass("active")
  471. })
  472. }else{
  473. oAjax('/ajax/question/answer/agree', {
  474. "id": anid,
  475. "uid":userid,
  476. "uname":username
  477. }, "POST", function(res) {
  478. $str.find(".canZan").addClass("active")
  479. $str.find(".canCai").removeClass("active")
  480. })
  481. }
  482. answerAgreeNum(anid, $(this).parents(".list-qa"));
  483. }else{
  484. quickLog();
  485. operatTab();
  486. closeLog();
  487. }
  488. })
  489. //踩回答
  490. $str.find(".canCai").on("click",function(){
  491. if(userid && userid != null && userid != "null") {
  492. if($(this).is('.active')){
  493. oAjax('/ajax/question/answer/oppose/cancle', {
  494. "id":anid,
  495. "uid":userid,
  496. "uname":username
  497. }, "POST", function(res) {
  498. $str.find(".canCai").removeClass("active")
  499. })
  500. }else{
  501. oAjax('/ajax/question/answer/oppose', {
  502. "id":anid,
  503. "uid":userid,
  504. "uname":username
  505. }, "POST", function(res) {
  506. $str.find(".canCai").addClass("active")
  507. $str.find(".canZan").removeClass("active")
  508. })
  509. }
  510. answerAgreeNum(anid, $(this).parents(".list-qa"));
  511. }else{
  512. quickLog();
  513. operatTab();
  514. closeLog();
  515. }
  516. })
  517. //删除
  518. $str.find(".tip-offs").on("click",".shanchu",function(){
  519. $.MsgBox.Confirm("提示", "确认删除该回答?",function(){
  520. oAjax('/ajax/question/answer/delete', {
  521. "id":anid,
  522. "qid":questionId,
  523. }, "get", function(res) {
  524. $.MsgBox.Alert("提示", "该回答已删除");
  525. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  526. window.location.reload();
  527. })
  528. })
  529. })
  530. //修改
  531. $str.find(".tip-offs").on("click",".xiugai",function(){
  532. var objStr=$(this).parents(".list-qa").find(".answerUpdate");
  533. var objTex=$(this).parents(".list-qa").find(".qa-con").html().replace(/<br\s*\/?\s*>/ig, '\n');
  534. goAnswerFn(objStr,anid,objTex,1)
  535. })
  536. //举报
  537. $str.find(".tip-offs").on("click",".jubao",function(){
  538. $("#correctBlock").fadeIn();
  539. $(".correctSubmit").attr("data-type","answer")
  540. $(".correctSubmit").attr("data-tyId",anid)
  541. })
  542. //微信分享
  543. $str.find('.shareWeixin').on("mouseenter",function(){
  544. $(this).find('.shareCode').stop(true,false).fadeIn();
  545. }).on("mouseleave",function(){
  546. $(this).find('.shareCode').stop(true,false).fadeOut();
  547. });
  548. var Qcu=$str.find(".qrcodeQA");
  549. for(var i=0;i<Qcu.length;i++){
  550. var qrcode= new QRCode(Qcu[i], {
  551. width : 100,
  552. height : 100
  553. });
  554. var elurl = "http://" + hurl + "/e/da.html?id="+anid;
  555. qrcode.makeCode(elurl);
  556. }
  557. //微博分享
  558. $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");
  559. },
  560. leaveMsgCount=function(id, $str) {
  561. oAjax("/ajax/leavemsg/count", {
  562. sid:id,
  563. stype: "4"
  564. }, "get", function(data) {
  565. if(data.success) {
  566. if(data.data > 0) {
  567. $str.find(".leaveMsgCount").html(data.data);
  568. }
  569. }
  570. })
  571. },
  572. proinfo = function(pid, $str,Fflag) {
  573. oAjax("/ajax/professor/baseInfo/" + pid, {}, "get", function(res) {
  574. var dataStr = res.data
  575. var baImg = "../images/default-photo.jpg";
  576. if(dataStr.hasHeadImage == 1) {
  577. baImg = "/images/head/" + dataStr.id + "_l.jpg";
  578. }
  579. var userType = autho(dataStr.authType, dataStr.orgAuth, dataStr.authStatus);
  580. var os = "";
  581. var spanStr="";
  582. if(Fflag){
  583. spanStr='<span class="yaoqing">邀请回答</span>'
  584. }else{
  585. spanStr='<span class="attenSpan">关注</span>'
  586. }
  587. if(dataStr.title) {
  588. if(dataStr.orgName) {
  589. os = dataStr.title + "," + dataStr.orgName;
  590. } else {
  591. os = dataStr.title;
  592. }
  593. } else {
  594. if(dataStr.office) {
  595. if(dataStr.orgName) {
  596. os = dataStr.office + "," + dataStr.orgName;
  597. } else {
  598. os = dataStr.office;
  599. }
  600. } else {
  601. if(dataStr.orgName) {
  602. os = dataStr.orgName;
  603. }
  604. }
  605. }
  606. var str = '<div class="owner-head useHead" style="background-image:url(' + baImg + ')"></div>' +
  607. '<div class="owner-info">' +
  608. '<div class="owner-name">' + dataStr.name + '<em class="authiconNew ' + userType.sty + '" title="' + userType.title + '"></em></div>' +
  609. '<div class="owner-tit ellipsisSty h2Font">' + os + '</div>' +
  610. '</div>'+
  611. '<div class="goSpan">'+spanStr+'</div>'
  612. $str.find(".qa-owner").html(str);
  613. if(dataStr.id!=userid){
  614. ifcollectionAbout(dataStr.id,$str.find(".attenSpan"),1);
  615. }else{
  616. $str.find(".attenSpan").hide()
  617. }
  618. if(Fflag){
  619. inviteStatus(dataStr.id, $str);
  620. }
  621. });
  622. },
  623. isAgree=function(id,$str){
  624. oAjax('/ajax/question/answer/agree', {
  625. "aid": id,
  626. "uid":userid
  627. }, "get", function(res) {
  628. if(res.success){
  629. console.log(res)
  630. if(res.data==null){
  631. }else if(res.data.flag){
  632. $str.find(".canZan").addClass("active")
  633. }else{
  634. $str.find(".canCai").addClass("active")
  635. }
  636. }
  637. })
  638. },
  639. requestA=function(){
  640. oAjax("/ajax/question/commendatoryPro", {
  641. "id": questionId,
  642. "uid": userid,
  643. "rows": rowsR,
  644. "pid": dataC.pid,
  645. "count": dataC.count
  646. }, "get",function(res){
  647. console.log(res)
  648. var aimId="requestA",newStr="抱歉,没有搜到可以邀请的人<br>您可以通过分享该问题的方式获得更多答案"
  649. var $info = res.data;
  650. if($info.length > 0) {
  651. dataC.count = $info[$info.length - 1].kws;
  652. dataC.pid = $info[$info.length - 1].id;
  653. for(var i = 0; i < $info.length; i++) {
  654. var liStr = document.createElement("li");
  655. liStr.setAttribute("data-id", $info[i].id);
  656. liStr.innerHTML = '<div class="flexCenter qa-owner"></div>'
  657. document.getElementById(aimId).appendChild(liStr);
  658. var $str = $(liStr)
  659. proinfo($info[i].id, $str,1);
  660. }
  661. }
  662. var liLen=document.getElementById(aimId).querySelectorAll("li").length;
  663. removeAfter(aimId);
  664. if($info.length == 0 && liLen == 0 ){
  665. insertAfter(newStr,aimId);
  666. }
  667. $("#requestA").parent().find(".js-load-more").on("click",function(){
  668. requestA()
  669. })
  670. if ($info.length < rowsR) {
  671. $("#requestA").parent().find(".js-load-more").unbind("click");
  672. $("#requestA").parent().find(".js-load-more").hide();
  673. }
  674. },function(){
  675. $("#requestA").parent().find(".js-load-more").attr("disabled",true);
  676. $("#requestA").parent().find(".js-load-more").addClass("active");
  677. },function(){
  678. $("#requestA").parent().find(".js-load-more").removeAttr("disabled");
  679. $("#requestA").parent().find(".js-load-more").removeClass("active");
  680. })
  681. },
  682. inviteStatus = function(id, $str) {
  683. oAjax("/ajax/question/invite", {
  684. "qid": questionId,
  685. "pid": id,
  686. "uid": userid,
  687. }, "get", function(res) {
  688. console.log(res)
  689. if(res.data.length>0){
  690. $str.find(".yaoqing").addClass("yiyaoqing");
  691. $str.find(".yaoqing").html("已邀请");
  692. $str.find(".yaoqing").attr("data-type","");
  693. }else{
  694. $str.find(".yaoqing").text("邀请回答")
  695. $str.find(".yaoqing").attr("data-type","1");
  696. }
  697. });
  698. },
  699. searchPage = function(searchval,isbind) {
  700. var aimId="requestA",newStr="抱歉,没有搜到可以邀请的人<br>您可以通过分享该问题的方式获得更多答案"
  701. oAjax("/ajax/professor/pqBaseInfo", {
  702. "key": searchval,
  703. "pageSize": rowsR,
  704. "pageNo": pageNum++
  705. }, "get", function(res){
  706. console.log(res)
  707. var $info = res.data.data;
  708. if($info.length > 0) {
  709. for(var i = 0; i < $info.length; i++) {
  710. if($info[i].id==userid){
  711. }else{
  712. var liStr = document.createElement("li");
  713. liStr.innerHTML = '<div class="flexCenter qa-owner"></div>'
  714. liStr.setAttribute("data-id", $info[i].id);
  715. document.getElementById(aimId).appendChild(liStr);
  716. var $str = $(liStr)
  717. proinfo($info[i].id, $str,1);
  718. inviteStatus($info[i].id, $str);
  719. }
  720. }
  721. }
  722. if(isbind){
  723. $("#requestA").parent().find(".js-load-more").on("click", function () {
  724. searchPage(searchval);
  725. });
  726. }
  727. var liLen=document.getElementById(aimId).querySelectorAll("li").length;
  728. removeAfter(aimId);
  729. if($info.length == 0 && liLen == 0 ){
  730. insertAfter(newStr,aimId);
  731. }
  732. if (pageNum > Math.ceil(res.data.total / rowsR)) {
  733. $("#requestA").parent().find(".js-load-more").unbind("click");
  734. $("#requestA").parent().find(".js-load-more").hide();
  735. }
  736. },function(){
  737. $("#requestA").parent().find(".js-load-more").attr("disabled",true);
  738. $("#requestA").parent().find(".js-load-more").addClass("active");
  739. },function(){
  740. $("#requestA").parent().find(".js-load-more").removeAttr("disabled");
  741. $("#requestA").parent().find(".js-load-more").removeClass("active");
  742. })
  743. }
  744. pageViews();
  745. getConmain();
  746. waitingA();
  747. if(topAnswerId){
  748. $(".show-list-allAn").addClass("displayNone")
  749. $(".show-list-thisAn").removeClass("displayNone")
  750. answerTop(topAnswerId)
  751. answerThisShow();
  752. }else{
  753. $(".show-list-allAn").removeClass("displayNone")
  754. $(".show-list-thisAn").addClass("displayNone")
  755. answerList();
  756. }
  757. if(userid && userid != null && userid != "null") {
  758. anExist(); //判断是否回答过该问题
  759. ifcollectionAbout(questionId, $("#attention"), 8);
  760. }
  761. $(".list-hold-count>ul").on('click', 'li', function(e) {
  762. var sortlist = document.querySelector('.list-hold-count>ul').querySelectorAll("li");
  763. for(var i = 0; i < sortlist.length; i++) {
  764. sortlist[i].classList.remove('active');
  765. }
  766. this.classList.add('active');
  767. byway = this.getAttribute("data-type");
  768. document.getElementById("curAnswers").innerHTML = "";
  769. $("#curAnswers").parent().find(".js-load-more").unbind("click");
  770. $("#curAnswers").parent().find(".js-load-more").show();
  771. dataO = {time: "",id: "",score:""}
  772. answerList()
  773. });
  774. $("#attention").on('click', function() {
  775. if(userid && userid != null && userid != "null") {
  776. if($(this).is('.icon-collected')){
  777. cancelCollectionAbout(questionId,$(this),8)
  778. } else {
  779. collectionAbout(questionId,$(this),8);
  780. }
  781. attendCount()
  782. }else{
  783. quickLog();
  784. operatTab();
  785. closeLog();
  786. }
  787. });
  788. $(".go-answer").on('click', function() {
  789. var can = this.getAttribute("data-can");
  790. if(userid && userid != null && userid != "null") {
  791. if(can=="1") {
  792. goAnswerFn($(".answerQu"))
  793. } else if(can=="2") {
  794. var anid= this.getAttribute("data-anid");
  795. oAjax("/ajax/question/answer/unDel", {
  796. "qid": questionId,
  797. "id": anid,
  798. }, "get", function(res) {
  799. if(res.data=="1") {
  800. oanswer.setAttribute("data-can", "0"); //回答过
  801. oanswer.classList.add("answered");
  802. oanswer.innerText = "我已回答"
  803. }
  804. window.location.reload();
  805. })
  806. }else{
  807. return
  808. }
  809. } else {
  810. quickLog();
  811. operatTab();
  812. closeLog();
  813. }
  814. })
  815. $(".invite-answer").on('click', function() {
  816. if(userid && userid != null && userid != "null") {
  817. var objN=$(".request-qa")
  818. objN.slideToggle(300);
  819. document.getElementById("searchAval").value=""
  820. document.getElementById("requestA").innerHTML = ""
  821. dataC = {count: "",pid: ""}
  822. $("#requestA").parent().find(".js-load-more").unbind("click");
  823. $("#requestA").parent().find(".js-load-more").show();
  824. requestA()
  825. } else {
  826. quickLog();
  827. operatTab();
  828. closeLog();
  829. }
  830. })
  831. $("#requestA").on("click", ".yaoqing", function() {
  832. var id = $(this).parents("li").attr("data-id");
  833. var type = $(this).attr("data-type");
  834. var that=$(this)
  835. if(type) {
  836. oAjax("/ajax/question/invite", {
  837. "qid": questionId,
  838. "pid": id,
  839. "uid": userid,
  840. "uname": username,
  841. }, "post", function(res) {
  842. that.attr("data-type", "");
  843. that.addClass("yiyaoqing");
  844. that.text("已邀请");
  845. $.MsgBox.Alert("提示", "邀请成功");
  846. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  847. })
  848. }
  849. })
  850. $("#searchAbtn").on("click", function() {
  851. document.getElementById("requestA").innerHTML = ""
  852. pageNum=1
  853. var searchval = document.getElementById("searchAval").value;
  854. searchPage(searchval,1)
  855. $("#requestA").parent().find(".js-load-more").unbind("click");
  856. $("#requestA").parent().find(".js-load-more").show();
  857. });
  858. $("#jubao").on("click",function(){
  859. $("#correctBlock").fadeIn();
  860. $(".correctSubmit").attr("data-type","question")
  861. $(".correctSubmit").attr("data-tyId",questionId)
  862. })
  863. $(".correctSubmit").on("click",function(){
  864. var type=$(this).attr("data-type"),
  865. tyId=$(this).attr("data-tyId")
  866. if(type=="answer"){
  867. tyurl='/ajax/feedback/error/answer'
  868. }else if(type=="question"){
  869. tyurl='/ajax/feedback/error/question'
  870. }
  871. var cntUser=""
  872. var cntCon=$(".correctCon").val();
  873. if(userid && userid != null && userid != "null") {
  874. cntUser = userid;
  875. }
  876. if(cntCon.length>500){
  877. $.MsgBox.Alert('提示', '纠错反馈内容不得超过500个字');
  878. return;
  879. }
  880. oAjax(tyurl,{
  881. "id": tyId,
  882. "cnt":cntCon,
  883. "user":cntUser
  884. }, "post", backSuccessed)
  885. })
  886. })