portal html css js resource

qa-show.js 30KB

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