portal html css js resource

articalIssue.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. $(function() {
  2. var experarray = [];
  3. var resourcesarray = [];
  4. var $data = {};
  5. var articleId;
  6. var fa = false;
  7. var orgId = $.cookie("orgId");
  8. if(orgId == "" || orgId == null || orgId == "null"){
  9. location.href = "cmp-settled-log.html";
  10. }
  11. //校验标题
  12. $("#newstitle").on({
  13. focus: function() {
  14. $(this).prev().find("span").text("50字以内");
  15. },
  16. blur: function() {
  17. $(this).prev().find("span").text("");
  18. },
  19. keyup: function() {
  20. if($(this).val().length > 50) {
  21. $(this).val($(this).val().substr(0, 50));
  22. }
  23. }
  24. })
  25. //校验关键字
  26. $("#KeyWord").on({
  27. focus: function() {
  28. $("#keyPrompt").text("最多可添加5个关键词,每个关键词10字以内");
  29. },
  30. blur: function() {
  31. $("#keyPrompt").text("");
  32. },
  33. keyup: function() {
  34. if($(this).val()==""){
  35. $(".frmadd").addClass("displayNone");
  36. $(".keydrop ul").html("");
  37. $(".keydrop").addClass("displayNone");
  38. }else{
  39. $(".frmadd").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. $(".keydrop").removeClass("displayNone");
  275. } else {
  276. $(".keydrop").addClass("displayNone");
  277. $(".keydrop ul").html("");
  278. }
  279. } else {
  280. $(".keydrop").addClass("displayNone");
  281. $(".keydrop ul").html("");
  282. }
  283. },
  284. "error": function() {
  285. $.MsgBox.Alert('提示', '链接服务器超时')
  286. }
  287. });
  288. }
  289. var titleflase = false;
  290. var imgflase = false;
  291. //交验图片和标题不能为空
  292. function noTitleImg() {
  293. var ImageKey = $("#uploader").attr("data-id");
  294. var newstitle = $("#newstitle").val();
  295. if(ImageKey == "") {
  296. //$(".imgtis").text("请上传封面图片");
  297. $.MsgBox.Alert('提示', '请上传封面图片');
  298. return;
  299. } else {
  300. $(".imgtis").text("");
  301. imgflase = true;
  302. }
  303. if(newstitle == "") {
  304. //$("#aboutTit span").text("请输入文章标题");
  305. $.MsgBox.Alert('提示', '请输入文章标题');
  306. return;
  307. } else {
  308. $("#aboutTit span").text("");
  309. titleflase = true;
  310. }
  311. }
  312. //获取相关专家
  313. function expertli() {
  314. experarray=[];
  315. $("#expertli li").each(function(i) {
  316. var liid = $(this).attr("data-id");
  317. experarray.push(liid);
  318. });
  319. return $.unique(experarray);
  320. }
  321. //获取相关资源
  322. function resourcesli() {
  323. resourcesarray=[];
  324. $("#resources li").each(function(i) {
  325. var liid = $(this).attr("data-id");
  326. resourcesarray.push(liid);
  327. });
  328. return $.unique(resourcesarray);
  329. }
  330. //文章发布
  331. $("#release").on("click", function() {
  332. noTitleImg();
  333. if(imgflase && titleflase) {
  334. $.MsgBox.Confirm("提示", "确认发布该文章?", newsAdd);
  335. }
  336. })
  337. //定时文章发布
  338. $("#setTimeIssue").on("click", function() {
  339. noTitleImg();
  340. if(imgflase && titleflase) {
  341. $(".blackcover2").fadeIn();
  342. $(".modelContain").show();
  343. $("body").addClass("modelOpen");
  344. $(".mb_btnOk").on("click", function() {
  345. var publishTime = $(".form_datetime").val();
  346. console.log(st6(publishTime));
  347. setTimeIssue(st6(publishTime));
  348. })
  349. }
  350. })
  351. //文章存草稿
  352. $("#draft").on("click", function() {
  353. noTitleImg();
  354. if(imgflase && titleflase) {
  355. draftAdd(1);
  356. }
  357. })
  358. //文章预览
  359. $("#preview").on("click", function() {
  360. noTitleImg();
  361. if(imgflase && titleflase) {
  362. draftAdd(2);
  363. }
  364. })
  365. /*获取数据*/
  366. function getdata(publishTime) {
  367. expertli(); //相关专家
  368. resourcesli(); //相关咨询
  369. $data.orgId = orgId;
  370. $data.articleTitle = $("#newstitle").val();
  371. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  372. $data.articleImg = $("#uploader").attr("data-id");
  373. $data.articleContent = ue.getContent();
  374. $data.professors = experarray;
  375. $data.resources = resourcesarray;
  376. if($("#hidearticleId").val().length != 0) {
  377. $data.articleId = $("#hidearticleId").val();
  378. }
  379. if($(".form_datetime").val().length != 0) {
  380. $data.publishTime = publishTime;
  381. }
  382. console.log($data);
  383. }
  384. /*文章发布*/
  385. function newsAdd() {
  386. getdata();
  387. $.ajax({
  388. "url": "/ajax/article/save",
  389. "type": "post",
  390. "dataType": "json",
  391. "data": $data,
  392. "traditional": true, //传数组必须加这个
  393. "success": function(data) {
  394. console.log(data);
  395. if(data.success) {
  396. $("#hidearticleId").val(data.data);
  397. $.MsgBox.Alert("提示", "文章发表成功!", function articalList() {
  398. location.href = "cmp-articalList.html";
  399. });
  400. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  401. } else {
  402. if(data.code==90) {
  403. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  404. }else{
  405. $.MsgBox.Alert("提示", "文章发表失败!");
  406. }
  407. }
  408. },
  409. "error": function() {
  410. $.MsgBox.Alert('提示', '链接服务器超时')
  411. }
  412. });
  413. }
  414. /*文章定时发布*/
  415. function setTimeIssue(publishTime) {
  416. var opublishTime=publishTime+"01";
  417. getdata(opublishTime);
  418. $.ajax({
  419. "url": "/ajax/article/timing",
  420. "type": "post",
  421. "dataType": "json",
  422. "data": $data,
  423. "traditional": true, //传数组必须加这个
  424. "success": function(data) {
  425. console.log(data);
  426. if(data.success) {
  427. $("#hidearticleId").val(data.data);
  428. location.href = "cmp-articalList.html";
  429. } else {
  430. if(data.code==90) {
  431. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  432. }else{
  433. $.MsgBox.Alert("提示", "文章发表失败!");
  434. }
  435. }
  436. },
  437. "error": function() {
  438. $.MsgBox.Alert('提示', '链接服务器超时')
  439. }
  440. });
  441. }
  442. /*文章添加草稿和文章预览*/
  443. function draftAdd(num) {
  444. getdata();
  445. $.ajax({
  446. "url": "/ajax/article/draft",
  447. "type": "post",
  448. "dataType": "json",
  449. "data": $data,
  450. "traditional": true, //传数组必须加这个
  451. "success": function(data) {
  452. console.log(data);
  453. if(num == 1) {
  454. if(data.success) {
  455. $("#hidearticleId").val(data.data);
  456. articleId = data.data;
  457. $.MsgBox.Alert("提示", "文章已保存草稿。");
  458. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  459. $("#delete").removeClass("disableLi").addClass("odele");
  460. }else{
  461. if(data.code==90) {
  462. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  463. }else{
  464. $.MsgBox.Alert("提示", "文章发表失败!");
  465. }
  466. }
  467. }
  468. if(num == 2) {
  469. if(data.success) {
  470. $("#hidearticleId").val(data.data);
  471. articleId = data.data;
  472. $("#delete").removeClass("disableLi").addClass("odele");
  473. fa = true;
  474. }else{
  475. if(data.code==90) {
  476. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  477. }else{
  478. $.MsgBox.Alert("提示", "文章发表失败!");
  479. }
  480. }
  481. if(fa) {
  482. window.open("../articalPreview.html?articleId=" + articleId)
  483. }
  484. }
  485. },
  486. "error": function() {
  487. $.MsgBox.Alert('提示', '链接服务器超时')
  488. }
  489. });
  490. }
  491. function st6(osr) {
  492. var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10) + osr.substring(11, 13) + osr.substring(14, 16);
  493. return tim;
  494. }
  495. /*删除文章*/
  496. $(".operateBlock").on("click",".odele",function(){
  497. $.MsgBox.Confirm("提示","确认删除该文章?",newsDelet);
  498. })
  499. /*文章删除*/
  500. function newsDelet() {
  501. $.ajax({
  502. "url" : "/ajax/article/deleteArticle",
  503. "type" : "POST",
  504. "dataType" : "json",
  505. "data": {
  506. "articleId": articleId
  507. },
  508. "success" : function($data) {
  509. if ($data.success) {
  510. location.href = "cmp-articalList.html";
  511. }
  512. },
  513. "error":function(){
  514. $.MsgBox.Alert('提示','链接服务器超时')
  515. }
  516. })
  517. }
  518. });