portal html css js resource

articalIssue.js 16KB

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