askpage.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. var edi="";
  2. var nei="";
  3. var adm="";
  4. var edi_ans="";
  5. var setint;
  6. var test_edi=new Array();
  7. $(function() {
  8. $("#large").click(function() {
  9. if(typeof( edi) =="string"){
  10. edi = new UE.ui.Editor();
  11. edi.render('content');
  12. }
  13. $('#reply_answer').toggle(1000);
  14. $('#large').hide();
  15. });
  16. $("#answerclose").click(function() {
  17. $('#reply_answer').hide(1000);
  18. $('#large').show();
  19. });
  20. $("#additionalclose").click(function() {
  21. $('#additional_content').slideUp("normal");
  22. });
  23. $("#edit_questionclose").click(function() {
  24. $('#edit_question_content').hide(1000);
  25. });
  26. $("input[id^='edit_answerclose_']").click(function() {
  27. var aid=parseInt($(this).attr('data'));
  28. $('#edit_answer_content_'+aid).toggle(1000);
  29. });
  30. //追问
  31. $("a[id^='to_ask_']").click(function() {
  32. var id=parseInt($(this).attr('data'));
  33. $('#to_ask_info_'+id).show();
  34. $('#to_ask_'+id).hide();
  35. });
  36. $("a[id^='btn_gray_']").click(function() {
  37. var id=parseInt($(this).attr('data'));
  38. $('#to_ask_'+id).show();
  39. $('#to_ask_info_'+id).hide();
  40. });
  41. $("a[id^='answer_btn_gray_']").click(function() {
  42. var id=parseInt($(this).attr('data'));
  43. $('#answer_again_info_'+id).hide();
  44. $('#answer_again_'+id).show();
  45. });
  46. $("a[id^='answer_again_']").click(function() {
  47. var id=parseInt($(this).attr('data'));
  48. $('#answer_again_info_'+id).show(1000);
  49. $('#answer_again_'+id).hide();
  50. });
  51. $("#to_ask_submit").click(function() {
  52. var content=$("#tag").val();
  53. if(content==""){
  54. alert("请输入内容");
  55. return false;
  56. }
  57. });
  58. $("#doanswer").click(function (){
  59. if(!edi.hasContents()){ //此处以非空为例
  60. alert("请输入内容");
  61. return false;
  62. }else{
  63. $('#doanswer').hide();
  64. $('#loading').html('<div ><img src="http://zhzdwd.com/global/css/loadIco.gif">加载中...请稍候!</div>');
  65. return true;
  66. }
  67. });
  68. /**
  69. * 设置为最佳答案
  70. */
  71. $("a[id^='best_button_']").click(function() {
  72. var id=parseInt($(this).attr('data'));
  73. easyDialog.open({
  74. container : {
  75. header : '设置答案为最佳',
  76. content :'对回答者的感言:<input type="text" name="comment_text" id="comment_text" value="谢谢你的解答!" />',
  77. yesFn : function(){
  78. $("#comment").attr("value",$("#comment_text").val());
  79. $("#best_answer_form_"+id).submit();
  80. },
  81. noFn : true
  82. }
  83. });
  84. });
  85. /**
  86. * 补充问题
  87. */
  88. $("#additional_button").click(function() {
  89. if(typeof( nei) =="string"){
  90. nei = new UE.ui.Editor();
  91. nei.render('supply_text');
  92. }
  93. $('#additional_content').slideDown("normal");
  94. });
  95. $("#additional").click(function() {
  96. var qid=$("#qid").val();
  97. if(!nei.hasContents()){ //此处以非空为例
  98. alert("请输入内容");
  99. return false;
  100. }
  101. var content=nei.getContent();
  102. var html='<div class="pgBoxExtra"><p class="extraTitle">问题补充&nbsp;&nbsp;刚刚</p><p></p><p>'+content+'</p><p></p></div>';
  103. $("#supply_pg").html(html);
  104. var url="/ajax/supply/doadd";
  105. $.ajax({
  106. url:url,
  107. type: "post",
  108. cache: false,
  109. dataType: "json",
  110. data: {
  111. qid:qid,
  112. supply:content
  113. },
  114. global: true,
  115. success: function(data){
  116. $('#supply_pg').toggle(1000);
  117. $("#additional_button").remove();
  118. $("#additional_content").remove();
  119. $("#supply_disclick").html('补充问题');
  120. },
  121. error:function(err){
  122. // document.getElementById('i_commont').innerHTML = err.responseText;
  123. }
  124. });
  125. });
  126. /**
  127. * 增加悬赏值
  128. */
  129. $("#up_price").click(function() {
  130. var price=parseInt($("#up_price").attr('data'));
  131. //检出是否是数字
  132. if(price<=0){
  133. easyDialog.open({
  134. container : {
  135. content : '您的财富值不足,2秒后关闭...'
  136. },
  137. autoClose : 2000
  138. });
  139. return false;
  140. }
  141. var arr=new Array();
  142. var p=1;
  143. for(var i=5;i<=price;i=i+5){
  144. var str="<option value='"+i+"'>"+i+"</option>";
  145. arr.push(str);
  146. if(i>=50)break;
  147. }
  148. var option = arr.join("");
  149. easyDialog.open({
  150. container : {
  151. header : '悬赏值',
  152. content :'<p>请选择金额:<span id="error" style="color:red"></span></p><select id="add_price">'+option+'</select>元&nbsp;&nbsp;(您当前余额:<b class="colOrange">¥'+price+'</b>元)</br><a href="/home_recharge">充值</a>',
  153. yesFn : upprice,
  154. noFn : true
  155. }
  156. });
  157. });
  158. var upprice=function(){
  159. var qid=$("#qid").val();
  160. $("#up_price").attr('data');
  161. var y_price=parseInt($("#askReward").html());
  162. var add_price=parseInt($("#add_price").find("option:selected").text());
  163. var price=$("#up_price").attr('data');
  164. if(add_price>price){
  165. alert("财富值不够");
  166. return false;
  167. }
  168. var url="/ajax/price/up";
  169. $.ajax({
  170. url:url,
  171. type: "post",
  172. cache: false,
  173. dataType: "json",
  174. data: {
  175. qid:qid,
  176. price:price,
  177. add_price:add_price
  178. },
  179. global: true,
  180. success: function(data){
  181. $("#askReward").html(y_price+add_price);
  182. $("#up_price").attr('data',price-add_price);
  183. easyDialog.open({
  184. container : {
  185. content : '增加财富值成功'
  186. },
  187. autoClose : 1500,
  188. overlay : false
  189. });
  190. },
  191. error:function(err){
  192. easyDialog.open({
  193. container : {
  194. content : '请输入正确的参数'
  195. },
  196. autoClose : 2000,
  197. overlay : false
  198. });
  199. }
  200. });
  201. }
  202. /**
  203. * 关闭问题
  204. */
  205. $("a[id^='close_queston_']").click(function() {
  206. easyDialog.open({
  207. container : {
  208. header : '无满意答案',
  209. content : '是否关闭问题?',
  210. yesFn : close_queston,
  211. noFn : true
  212. },
  213. overlay : false
  214. });
  215. });
  216. var close_queston=function(){
  217. var qid=parseInt($("#close_queston_u").attr('data'));
  218. if( isNaN(qid)){
  219. easyDialog.open({
  220. container : {
  221. content : '请输入正确的参数'
  222. },
  223. autoClose : 1500,
  224. overlay : false
  225. });
  226. return false;
  227. }
  228. self.location='/question/close/'+qid;
  229. }
  230. /**
  231. * 编辑问题
  232. */
  233. $("#edit_question").click(function() {
  234. if(typeof( adm) =="string"){
  235. adm = new UE.ui.Editor();
  236. adm.render('content_text');
  237. }
  238. $('#edit_question_content').show(1000);
  239. setint = setInterval("if($('#supply_text')){adm.setContent($('#que_content').html());setint=window.clearInterval(setint);}",100);
  240. });
  241. $("#edit_question_action").click(function() {
  242. if(!adm.hasContents()){
  243. alert("请输入内容");
  244. return false;
  245. }
  246. var content_text=adm.getContent();
  247. var qid=parseInt($("#edit_question").attr('data'));
  248. var url="/ajax/question/edit";
  249. $.ajax({
  250. url:url,
  251. type: "post",
  252. cache: false,
  253. dataType: "json",
  254. data: {
  255. qid:qid,
  256. content:content_text
  257. },
  258. global: true,
  259. success: function(data){
  260. $("#que_content").hide();
  261. $("#que_content").html(content_text);
  262. $("#edit_question_content").hide();
  263. $("#que_content").show(500);
  264. },
  265. error:function(err){
  266. }
  267. });
  268. });
  269. /**
  270. * 删除问题
  271. */
  272. $("#delete_queston").click(function() {
  273. easyDialog.open({
  274. container : {
  275. header : '删除问题',
  276. content : '是否删除问题?',
  277. yesFn : delete_queston,
  278. noFn : true
  279. },
  280. overlay : false
  281. });
  282. });
  283. var delete_queston=function(){
  284. var qid=parseInt($("#delete_queston").attr('data'));
  285. if( isNaN(qid)){
  286. easyDialog.open({
  287. container : {
  288. content : '请输入正确的参数'
  289. },
  290. autoClose : 1500,
  291. overlay : false
  292. });
  293. return false;
  294. }
  295. self.location='/question/delete/'+qid;
  296. }
  297. /**
  298. * 删除回答
  299. */
  300. $("a[id^='delete_answer_']").click(function() {
  301. var aids=$(this).attr('data');
  302. var a = aids.split("_");
  303. var aid=parseInt(a[0]);
  304. var qid=parseInt(a[1]);
  305. easyDialog.open({
  306. container : {
  307. header : '删除回答',
  308. content : '是否删除回答?',
  309. yesFn : function(){
  310. if( isNaN(aid)){
  311. easyDialog.open({
  312. container : {
  313. content : '请输入正确的参数'
  314. },
  315. autoClose : 1500,
  316. overlay : false
  317. });
  318. return false;
  319. }
  320. self.location='/answer/delete/'+aid+'/'+qid;
  321. },
  322. noFn : true
  323. },
  324. overlay : false
  325. });
  326. });
  327. var delete_answer=function(){
  328. if( isNaN(aid)){
  329. easyDialog.open({
  330. container : {
  331. content : '请输入正确的参数'
  332. },
  333. autoClose : 1500,
  334. overlay : false
  335. });
  336. return false;
  337. }
  338. self.location='/answer/delete/'+aid+'/'+qid;
  339. }
  340. /**
  341. * 编辑回答
  342. */
  343. $("a[id^='edit_answer_']").click(function() {
  344. var aid=parseInt($(this).attr('data'));
  345. var content=$("#ans_content_"+aid).html();
  346. if(typeof( edi_ans) =="string"){
  347. edi_ans = new UE.ui.Editor();
  348. edi_ans.render('edit_answer_text');
  349. }
  350. $('#edit_answer_content_'+aid).toggle(1000);
  351. setint = setInterval("if($('#edit_answer_text')){edi_ans.setContent($('#ans_content_"+aid+"').html());setint=window.clearInterval(setint);}",100);
  352. });
  353. $("input[id^='edit_answeraction_']").click(function() {
  354. if(!edi_ans.hasContents()){
  355. alert("请输入内容");
  356. return false;
  357. }
  358. console.log('d');
  359. var aid=parseInt($(this).attr('data'));
  360. var content_text=edi_ans.getContent();
  361. var url="/ajax/answer/edit";
  362. $.ajax({
  363. url:url,
  364. type: "post",
  365. cache: false,
  366. dataType: "json",
  367. data: {
  368. aid:aid,
  369. content:content_text
  370. },
  371. global: true,
  372. success: function(data){
  373. $("#ans_content_"+aid).hide();
  374. $("#ans_content_"+aid).html(content_text);
  375. $("#edit_answer_content_"+aid).hide();
  376. $("#ans_content_"+aid).show(500);
  377. },
  378. error:function(err){
  379. easyDialog.open({
  380. container : { content : '请输入正确的参数'},
  381. autoClose : 1500,
  382. overlay : false
  383. });
  384. }
  385. });
  386. });
  387. /**
  388. * 管理员设置答案为最佳
  389. */
  390. $("a[id^='admin_best_answer']").click(function() {
  391. var id=parseInt($(this).attr('data'));
  392. easyDialog.open({
  393. container : {
  394. header : '设置为最佳答案',
  395. content : '是否将此答案设置为最佳?',
  396. yesFn : function(){
  397. $("#comment").attr("value",$("#comment_text").val());
  398. $("#best_answer_form_"+id).submit();
  399. },
  400. noFn : true
  401. },
  402. overlay : false
  403. });
  404. });
  405. /**
  406. * 赞同回答
  407. */
  408. $("div[id^='agree_']").click(function() {
  409. var url="/ajax/answer/support";
  410. var aid=$(this).attr('data');
  411. $.ajax({
  412. url:url,
  413. type: "post",
  414. cache: false,
  415. dataType: "json",
  416. data: {
  417. aid:aid
  418. },
  419. global: true,
  420. success: function(data){
  421. easyDialog.open({
  422. container : { content : '设置成功'},
  423. autoClose : 1500,
  424. overlay : false
  425. });
  426. var Num=parseInt($("#agreeNum_"+aid).html());
  427. $("#agreeThis_"+aid).remove();
  428. $("#agreeThisDis_"+aid).html('<div class="agreeBtn"><b class="agreeTips">已赞同</b><b class="agreeNum">'+(Num+1)+'</b></div>');
  429. },
  430. error:function(err){
  431. easyDialog.open({
  432. container : { content : '请输入正确的参数'},
  433. autoClose : 1500,
  434. overlay : false
  435. });
  436. }
  437. });
  438. });
  439. /**
  440. * 提交追问
  441. */
  442. $("a[id^='to_ask_submit_']").click(function() {
  443. var aid=$(this).attr('data');
  444. if(!test_edi[aid].hasContents()){ //此处以非空为例
  445. easyDialog.open({
  446. container : { content : '请输入内容'},
  447. autoClose : 1000,
  448. overlay : false
  449. });
  450. return false;
  451. }else{
  452. test_edi[aid].sync();
  453. document.getElementById("toaskform_"+aid).submit();
  454. }
  455. });
  456. })