portal html css js resource

articalIssue.js 15KB

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