portal html css js resource

articalIssue.js 15KB

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