portal html css js resource

articalIssue.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. $(function() {
  2. loginStatus(); //判断个人是否登录
  3. valUser();
  4. var experarray = [];
  5. var resourcesarray = [];
  6. var $data = {};
  7. var articleId;
  8. var fa = false;
  9. var userid = $.cookie("userid");
  10. var hbur,hburEnd;
  11. var pr,prEnd;
  12. var re,reEnd;
  13. //校验标题
  14. $("#newstitle").on({
  15. focus: function() {
  16. $(this).prev().find("span").text("50字以内");
  17. },
  18. blur: function() {
  19. $(this).prev().find("span").text("");
  20. },
  21. keyup: function() {
  22. if($(this).val().length > 50) {
  23. $(this).val($(this).val().substr(0, 50));
  24. }
  25. }
  26. })
  27. //校验关键字
  28. $("#KeyWord").on({
  29. focus: function() {
  30. $("#keyPrompt").text("最多可添加5个关键词,每个关键词15字以内");
  31. },
  32. blur: function() {
  33. $("#keyPrompt").text("");
  34. },
  35. keyup: function() {
  36. var ti=$(this).val();
  37. hbur=ti;
  38. if(ti==""){
  39. $(".frmadd").addClass("displayNone");
  40. $(".keydrop ul").html("");
  41. $(".keydrop").addClass("displayNone");
  42. return;
  43. }else{
  44. $(".frmadd").removeClass("displayNone");
  45. }
  46. if($(this).val().length > 15) {
  47. $(this).val($(this).val().substr(0, 15));
  48. }
  49. setTimeout(function(){
  50. if( ti===hbur && ti!== hburEnd) {
  51. KeyWordList(ti);
  52. }
  53. },500)
  54. }
  55. })
  56. //添加关键字
  57. $("#addkeyWord").on("click", function() {
  58. var keyWord = $("#KeyWord").val();
  59. keyWordlen(keyWord);
  60. $(".frmadd").addClass("displayNone");
  61. $(".keydrop ul").html("");
  62. $(".keydrop").addClass("displayNone");
  63. })
  64. //点击搜出的关键字添加
  65. $(".keydrop").on("click", "p", function() {
  66. var keyWord = $(this).text();
  67. $(".frmadd").addClass("displayNone");
  68. keyWordlen(keyWord)
  69. $(".keydrop ul").html("");
  70. $(".keydrop").addClass("displayNone");
  71. })
  72. //删除关键字
  73. $("#keyWordlist").on("click", ".closeThis", function() {
  74. $(this).parent().remove();
  75. var plength = $(".keyResult li p").length;
  76. if(plength < 5) {
  77. $("#KeyWord").removeClass("displayNone");
  78. }
  79. $(".keydrop ul").html("");
  80. $(".keydrop").addClass("displayNone");
  81. })
  82. //组合关键字
  83. function captiureSubInd(subIndu) {
  84. var industrys = $("#" + subIndu + "");
  85. var industryAll = "";
  86. if(industrys.size() > 0) {
  87. for(var i = 0; i < industrys.size(); i++) {
  88. industryAll += industrys[i].innerText;
  89. industryAll += ',';
  90. };
  91. industryAll = industryAll.substring(0, industryAll.length - 1);
  92. }
  93. return industryAll;
  94. }
  95. function keyWordlen(keyWord) {
  96. $("#KeyWord").val("");
  97. var plength = $(".keyResult li p");
  98. for(var i = 0; i < plength.length; i++) {
  99. if(plength[i].innerText == keyWord) {
  100. $("#keyPrompt").text("关键词已存在");
  101. return;
  102. }
  103. }
  104. if(plength.length > 3) {
  105. $("#KeyWord").addClass("displayNone");
  106. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>" + keyWord + "</p><div class='closeThis'></div></li>");
  107. } else {
  108. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>" + keyWord + "</p><div class='closeThis'></div></li>");
  109. }
  110. }
  111. function KeyWordList(seValue) {
  112. hburEnd=seValue;
  113. $.ajax({
  114. "url": "/ajax/dataDict/qaHotKey",
  115. "type": "get",
  116. "data": {
  117. "key": $("#KeyWord").val()
  118. },
  119. "success": function(data) {
  120. console.log(data);
  121. if(data.success) {
  122. if(hburEnd == seValue){
  123. var itemlist = '';
  124. $("#keydropList").html("");
  125. for(var i = 0; i < Math.min(data.data.length,5); i++) {
  126. var itemlist = '<li><p class="h2Font"></p></li>';
  127. $itemlist = $(itemlist);
  128. $("#keydropList").append($itemlist);
  129. $itemlist.find(".h2Font").text(data.data[i].caption);
  130. }
  131. $(".keydrop").removeClass("displayNone");
  132. }
  133. } else {
  134. //$(".keydrop").addClass("displayNone");
  135. //$(".keydrop ul").html("");
  136. }
  137. },
  138. "error": function() {
  139. $.MsgBox.Alert('提示', '链接服务器超时')
  140. }
  141. });
  142. }
  143. //校验右侧专家和资源
  144. $("#checkZj").on("focus", function() {
  145. $(this).prev().find("span").text("最多选择5位专家");
  146. })
  147. $("#checkZy").on("focus", function() {
  148. $(this).prev().find("span").text("最多选择5个资源");
  149. })
  150. $("#checkZj,#checkZy").on("blur", function() {
  151. $(this).prev().find("span").text("");
  152. })
  153. $("#checkZj").on("keyup", function() {
  154. var _this = this;
  155. var ti=$(this).val();
  156. pr=ti;
  157. if($(this).val()=="") {
  158. return;
  159. }
  160. setTimeout(function(){
  161. if( ti===pr && ti!== prEnd) {
  162. checkZj(_this,ti);
  163. }
  164. },500)
  165. })
  166. $("#checkZy").on("keyup", function() {
  167. var ti=$(this).val();
  168. re=ti;
  169. if($(this).val()=="") {
  170. return;
  171. }
  172. var _this = this;
  173. setTimeout(function(){
  174. if( ti===re && ti!== reEnd) {
  175. checkZy(_this,ti);
  176. }
  177. },500)
  178. })
  179. $("#expertlist").on("click", "li", function() {
  180. var _this = this;
  181. expertlist(_this, "该专家已选择");
  182. });
  183. $("#resouselist").on("click", "li", function() {
  184. var _this = this;
  185. expertlist(_this, "该资源已选择");
  186. });
  187. //点击右侧搜索出的专家和资源列表
  188. function expertlist(_this, title) {
  189. var liId = $(_this).html();
  190. var plength = $(_this).parents(".otherBlock").find(".addexpert li");
  191. for(var i = 0; i < plength.length; i++) {
  192. if(plength[i].innerHTML == liId) {
  193. $(_this).parents(".otherBlock").find(".aboutTit span").text(title);
  194. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  195. $(_this).parents(".otherBlock").find("input").val("");
  196. return;
  197. }
  198. }
  199. if(plength.length > 3) {
  200. $(_this).parents(".otherBlock").find("input").hide();
  201. $(_this).parents(".otherBlock").find(".addexpert").append($(_this).clone());
  202. $(_this).parents(".otherBlock").find("input").val("");
  203. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  204. } else {
  205. $(_this).parents(".otherBlock").find(".addexpert").append($(_this).clone());
  206. $(_this).parents(".otherBlock").find("input").val("");
  207. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  208. }
  209. }
  210. //删除右侧搜索出的专家和资源
  211. $(".addexpert").on("click", ".deleteThis", function() {
  212. var plength = $(this).parent().parent().find("li").length;
  213. if(plength < 6) {
  214. $(this).parents(".otherBlock").find("input").show();
  215. }
  216. $(this).parent().remove();
  217. })
  218. function checkZj(_this,prd) {
  219. prEnd=prd;
  220. $.ajax({
  221. "url": "/ajax/professor/qaByName",
  222. "type": "get",
  223. "data": {
  224. "name": $("#checkZj").val(),
  225. "total": 3
  226. },
  227. "success": function(data) {
  228. console.log(data);
  229. if(data.success) {
  230. if(data.data != "") {
  231. if(prEnd == prd){
  232. $(_this).next().removeClass("displayNone");
  233. var itemlist = '';
  234. $("#expertlist").html("");
  235. for(var i = 0; i < data.data.length; i++) {
  236. var itemlist = '<li id="usid" class="flexCenter">';
  237. itemlist += '<div class="madiaHead useHead" id="userimg"></div>';
  238. itemlist += '<div class="madiaInfo">';
  239. itemlist += '<p class="ellipsisSty"><span class="h1Font" id="name"></span><span class="h2Font" style="margin-left:10px;" id="title"></span></p>';
  240. itemlist += '<p class="h2Font ellipsisSty" id="orgName"></p>';
  241. itemlist += '</div><div class="deleteThis"></div></li>';
  242. $itemlist = $(itemlist);
  243. $("#expertlist").append($itemlist);
  244. var datalist = data.data[i];
  245. $itemlist.attr("data-id", datalist.id);
  246. $itemlist.find("#name").text(datalist.name);
  247. $itemlist.find("#title").text(datalist.title);
  248. $itemlist.find("#orgName").text(datalist.orgName);
  249. if(datalist.hasHeadImage == 1) {
  250. $itemlist.find("#userimg").attr("style", "background-image: url(/images/head/" + datalist.id + "_l.jpg);");
  251. }
  252. }
  253. }
  254. } else {
  255. $(_this).next().addClass("displayNone");
  256. }
  257. } else {
  258. $(_this).next().addClass("displayNone");
  259. }
  260. },
  261. "error": function() {
  262. $.MsgBox.Alert('提示', '链接服务器超时')
  263. }
  264. });
  265. }
  266. function checkZy(_this,prd) {
  267. reEnd=prd;
  268. $.ajax({
  269. "url": "/ajax/resource/qaByName",
  270. "type": "get",
  271. "data": {
  272. "resourceName": $("#checkZy").val(),
  273. "rows": 3
  274. },
  275. "success": function(data) {
  276. console.log(data);
  277. if(data.success) {
  278. if(data.data != "") {
  279. if(reEnd==prd) {
  280. $(_this).next().removeClass("displayNone");
  281. var itemlist = '';
  282. $("#resouselist").html("");
  283. for(var i = 0; i < data.data.length; i++) {
  284. var itemlist = '<li id="usid" class="flexCenter">';
  285. itemlist += '<div class="madiaHead resouseHead" id="userimg"></div>';
  286. itemlist += '<div class="madiaInfo">';
  287. itemlist += '<p class="h1Font ellipsisSty" id="resourceName"></p>';
  288. itemlist += '<p class="h2Font ellipsisSty" id="name"></p>';
  289. itemlist += '</div><div class="deleteThis"></div></li>';
  290. $itemlist = $(itemlist);
  291. $("#resouselist").append($itemlist);
  292. var datalist = data.data[i];
  293. $itemlist.attr("data-id", datalist.resourceId);
  294. $itemlist.find("#resourceName").text(datalist.resourceName);
  295. if(datalist.resourceType==1){
  296. $itemlist.find("#name").text(datalist.professor.name);
  297. }else{
  298. $itemlist.find("#name").text(datalist.organization.name);
  299. }
  300. if(datalist.images.length > 0) {
  301. $itemlist.find("#userimg").attr("style", "background-image: url(/data/resource/" + datalist.images[0].imageSrc + ");");
  302. }
  303. }
  304. }
  305. } else {
  306. $(_this).next().addClass("displayNone");
  307. }
  308. } else {
  309. $(_this).next().addClass("displayNone");
  310. }
  311. },
  312. "error": function() {
  313. $.MsgBox.Alert('提示', '链接服务器超时')
  314. }
  315. });
  316. }
  317. var titleflase = false;
  318. var imgflase = false;
  319. //交验图片和标题不能为空
  320. function noTitleImg() {
  321. var ImageKey = $("#uploader").attr("data-id");
  322. var newstitle = $("#newstitle").val();
  323. if(ImageKey == "") {
  324. //$(".imgtis").text("请上传封面图片");
  325. $.MsgBox.Alert('提示', '请上传封面图片');
  326. return;
  327. } else {
  328. $(".imgtis").text("");
  329. imgflase = true;
  330. }
  331. if(newstitle == "") {
  332. $.MsgBox.Alert('提示', '请输入文章标题')
  333. //$("#aboutTit span").text("请输入文章标题");
  334. return;
  335. } else {
  336. $("#aboutTit span").text("");
  337. titleflase = true;
  338. }
  339. }
  340. //获取相关专家
  341. function expertli() {
  342. experarray=[];
  343. $("#expertli li").each(function(i) {
  344. var liid = $(this).attr("data-id");
  345. experarray.push(liid);
  346. });
  347. return $.unique(experarray);
  348. }
  349. //获取相关资源
  350. function resourcesli() {
  351. resourcesarray=[];
  352. $("#resources li").each(function(i) {
  353. var liid = $(this).attr("data-id");
  354. resourcesarray.push(liid);
  355. });
  356. return $.unique(resourcesarray);
  357. }
  358. //文章发布
  359. $("#release").on("click", function() {
  360. if($(this).hasClass("disableLi")){
  361. return;
  362. }
  363. noTitleImg();
  364. if(imgflase && titleflase) {
  365. $.MsgBox.Confirm("提示", "确认发布该文章?", newsAdd);
  366. }
  367. })
  368. //定时文章发布
  369. $("#setTimeIssue").on("click", function() {
  370. if($(this).hasClass("disableLi")){
  371. return;
  372. }
  373. noTitleImg();
  374. if(imgflase && titleflase) {
  375. $(".blackcover2").fadeIn();
  376. $(".modelContain").show();
  377. $("body").addClass("modelOpen");
  378. $(".mb_btnOk").on("click", function() {
  379. var publishTime = $(".form_datetime").val();
  380. console.log(st6(publishTime));
  381. setTimeIssue(st6(publishTime));
  382. })
  383. }
  384. })
  385. //文章存草稿
  386. $("#draft").on("click", function() {
  387. if($(this).hasClass("disableLi")){
  388. return;
  389. }
  390. noTitleImg();
  391. if(imgflase && titleflase) {
  392. draftAdd(1);
  393. }
  394. })
  395. //文章预览
  396. $("#preview").on("click", function() {
  397. if($(this).hasClass("disableLi")){
  398. return;
  399. }
  400. noTitleImg();
  401. if(imgflase && titleflase) {
  402. draftAdd(2);
  403. }
  404. })
  405. /*获取数据*/
  406. function getdata(publishTime) {
  407. expertli(); //相关专家
  408. resourcesli(); //相关咨询
  409. $data.professorId = userid;
  410. $data.articleTitle = $("#newstitle").val();
  411. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  412. $data.articleImg = $("#uploader").attr("data-id");
  413. $data.articleContent = ue.getContent();
  414. $data.professors = experarray;
  415. $data.resources = resourcesarray;
  416. $data.colNum=1;
  417. if($("#hidearticleId").val().length != 0) {
  418. $data.articleId = $("#hidearticleId").val();
  419. }
  420. if($(".form_datetime").val().length != 0) {
  421. $data.publishTime = publishTime;
  422. }
  423. console.log($data);
  424. }
  425. /*文章发布*/
  426. function newsAdd() {
  427. $(".operateBlock").find("li").addClass("disableLi");
  428. getdata();
  429. $.ajax({
  430. "url": "/ajax/article/save",
  431. "type": "post",
  432. "dataType": "json",
  433. "data": $data,
  434. "traditional": true, //传数组必须加这个
  435. "complete":function(){
  436. $(".operateBlock").find("li").removeClass("disableLi");
  437. },
  438. "success": function(data) {
  439. console.log(data);
  440. if(data.success) {
  441. $("#hidearticleId").val(data.data);
  442. $.MsgBox.Alert("提示", "文章发表成功!", function articalList() {
  443. location.href = "articalList.html";
  444. });
  445. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  446. } else {
  447. if(data.code==90) {
  448. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  449. }else{
  450. $.MsgBox.Alert("提示", "文章发表失败!");
  451. }
  452. }
  453. },
  454. "error": function() {
  455. $.MsgBox.Alert('提示', '链接服务器超时')
  456. }
  457. });
  458. }
  459. /*文章定时发布*/
  460. function setTimeIssue(publishTime) {
  461. var opublishTime=publishTime+"01";
  462. getdata(opublishTime);
  463. $(".operateBlock").find("li").addClass("disableLi");
  464. $.ajax({
  465. "url": "/ajax/article/timing",
  466. "type": "post",
  467. "dataType": "json",
  468. "data": $data,
  469. "traditional": true, //传数组必须加这个
  470. "complete":function(){
  471. $(".operateBlock").find("li").removeClass("disableLi");
  472. },
  473. "success": function(data) {
  474. if(data.success) {
  475. $("#hidearticleId").val(data.data);
  476. location.href = "articalList.html";
  477. } else {
  478. if(data.code==90) {
  479. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  480. }else{
  481. $.MsgBox.Alert("提示", "文章发表失败!");
  482. }
  483. }
  484. },
  485. "error": function() {
  486. $.MsgBox.Alert('提示', '链接服务器超时')
  487. }
  488. });
  489. }
  490. /*文章添加草稿和文章预览*/
  491. function draftAdd(num) {
  492. $(".operateBlock").find("li").addClass("disableLi");
  493. getdata();
  494. $.ajax({
  495. "url": "/ajax/article/draft",
  496. "type": "post",
  497. "dataType": "json",
  498. "data": $data,
  499. "traditional": true, //传数组必须加这个
  500. complete:function(){
  501. $(".operateBlock").find("li").removeClass("disableLi");
  502. },
  503. "success": function(data) {
  504. console.log(data);
  505. if(num == 1) {
  506. if(data.success) {
  507. $("#hidearticleId").val(data.data);
  508. articleId = data.data;
  509. $.MsgBox.Alert("提示", "文章已保存草稿。");
  510. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  511. $("#delete").removeClass("disableLi").addClass("odele");
  512. }else{
  513. if(data.code==90) {
  514. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  515. }else{
  516. $.MsgBox.Alert("提示", "文章发表失败!");
  517. }
  518. }
  519. }
  520. if(num == 2) {
  521. if(data.success) {
  522. $("#hidearticleId").val(data.data);
  523. articleId = data.data;
  524. $("#delete").removeClass("disableLi").addClass("odele");
  525. fa = true;
  526. }else{
  527. if(data.code==90) {
  528. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  529. }else{
  530. $.MsgBox.Alert("提示", "文章发表失败!");
  531. }
  532. }
  533. if(fa) {
  534. window.open("articalPreview.html?articleId=" + articleId)
  535. }
  536. }
  537. },
  538. "error": function() {
  539. $.MsgBox.Alert('提示', '链接服务器超时')
  540. }
  541. });
  542. }
  543. function st6(osr) {
  544. var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10) + osr.substring(11, 13) + osr.substring(14, 16);
  545. return tim;
  546. }
  547. /*删除文章*/
  548. $(".operateBlock").on("click",".odele",function(){
  549. $.MsgBox.Confirm("提示","确认删除该文章?",newsDelet);
  550. })
  551. /*文章删除*/
  552. function newsDelet() {
  553. $.ajax({
  554. "url" : "/ajax/article/deleteArticle",
  555. "type" : "POST",
  556. "dataType" : "json",
  557. "data": {
  558. "articleId": articleId
  559. },
  560. "success" : function($data) {
  561. if ($data.success) {
  562. location.href = "articalList.html";
  563. }
  564. },
  565. "error":function(){
  566. $.MsgBox.Alert('提示','链接服务器超时')
  567. }
  568. })
  569. }
  570. });