portal html css js resource

articalIssue.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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 < 5; 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. function getAttrId() {
  366. var arr=[];
  367. this.each(function(){
  368. arr.push( $(this).attr("data-id"));
  369. });
  370. return arr;
  371. }
  372. /*获取数据*/
  373. function getdata(publishTime) {
  374. expertli(); //相关专家
  375. resourcesli(); //相关咨询
  376. $data.orgId = orgId;
  377. if($("#companys li").length) {
  378. $data.orgs = getAttrId.call($("#companys li"));
  379. }
  380. $data.articleTitle = $("#newstitle").val();
  381. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  382. $data.articleImg = $("#uploader").attr("data-id");
  383. $data.articleContent = ue.getContent();
  384. $data.professors = experarray;
  385. $data.resources = resourcesarray;
  386. if($("#hidearticleId").val().length != 0) {
  387. $data.articleId = $("#hidearticleId").val();
  388. }
  389. if($(".form_datetime").val().length != 0) {
  390. $data.publishTime = publishTime;
  391. }
  392. console.log($data);
  393. }
  394. /*文章发布*/
  395. function newsAdd() {
  396. getdata();
  397. $.ajax({
  398. "url": "/ajax/article/save",
  399. "type": "post",
  400. "dataType": "json",
  401. "data": $data,
  402. "traditional": true, //传数组必须加这个
  403. "success": function(data) {
  404. console.log(data);
  405. if(data.success) {
  406. $("#hidearticleId").val(data.data);
  407. $.MsgBox.Alert("提示", "文章发表成功!", function articalList() {
  408. location.href = "cmp-articalList.html";
  409. });
  410. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  411. } else {
  412. if(data.code==90) {
  413. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  414. }else{
  415. $.MsgBox.Alert("提示", "文章发表失败!");
  416. }
  417. }
  418. },
  419. "error": function() {
  420. $.MsgBox.Alert('提示', '链接服务器超时')
  421. }
  422. });
  423. }
  424. /*文章定时发布*/
  425. function setTimeIssue(publishTime) {
  426. var opublishTime=publishTime+"01";
  427. getdata(opublishTime);
  428. $.ajax({
  429. "url": "/ajax/article/timing",
  430. "type": "post",
  431. "dataType": "json",
  432. "data": $data,
  433. "traditional": true, //传数组必须加这个
  434. "success": function(data) {
  435. console.log(data);
  436. if(data.success) {
  437. $("#hidearticleId").val(data.data);
  438. location.href = "cmp-articalList.html";
  439. } else {
  440. if(data.code==90) {
  441. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  442. }else{
  443. $.MsgBox.Alert("提示", "文章发表失败!");
  444. }
  445. }
  446. },
  447. "error": function() {
  448. $.MsgBox.Alert('提示', '链接服务器超时')
  449. }
  450. });
  451. }
  452. /*文章添加草稿和文章预览*/
  453. function draftAdd(num) {
  454. getdata();
  455. $.ajax({
  456. "url": "/ajax/article/draft",
  457. "type": "post",
  458. "dataType": "json",
  459. "data": $data,
  460. "traditional": true, //传数组必须加这个
  461. "success": function(data) {
  462. console.log(data);
  463. if(num == 1) {
  464. if(data.success) {
  465. $("#hidearticleId").val(data.data);
  466. articleId = data.data;
  467. $.MsgBox.Alert("提示", "文章已保存草稿。");
  468. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  469. $("#delete").removeClass("disableLi").addClass("odele");
  470. }else{
  471. if(data.code==90) {
  472. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  473. }else{
  474. $.MsgBox.Alert("提示", "文章发表失败!");
  475. }
  476. }
  477. }
  478. if(num == 2) {
  479. if(data.success) {
  480. $("#hidearticleId").val(data.data);
  481. articleId = data.data;
  482. $("#delete").removeClass("disableLi").addClass("odele");
  483. fa = true;
  484. }else{
  485. if(data.code==90) {
  486. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  487. }else{
  488. $.MsgBox.Alert("提示", "文章发表失败!");
  489. }
  490. }
  491. if(fa) {
  492. window.open("../articalPreview.html?articleId=" + articleId)
  493. }
  494. }
  495. },
  496. "error": function() {
  497. $.MsgBox.Alert('提示', '链接服务器超时')
  498. }
  499. });
  500. }
  501. function st6(osr) {
  502. var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10) + osr.substring(11, 13) + osr.substring(14, 16);
  503. return tim;
  504. }
  505. /*删除文章*/
  506. $(".operateBlock").on("click",".odele",function(){
  507. $.MsgBox.Confirm("提示","确认删除该文章?",newsDelet);
  508. })
  509. /*文章删除*/
  510. function newsDelet() {
  511. $.ajax({
  512. "url" : "/ajax/article/deleteArticle",
  513. "type" : "POST",
  514. "dataType" : "json",
  515. "data": {
  516. "articleId": articleId
  517. },
  518. "success" : function($data) {
  519. if ($data.success) {
  520. location.href = "cmp-articalList.html";
  521. }
  522. },
  523. "error":function(){
  524. $.MsgBox.Alert('提示','链接服务器超时')
  525. }
  526. })
  527. }
  528. relatCompanies("#company");
  529. /*添加相关企业*/
  530. function relatCompanies(sel) {
  531. $(sel).bind({
  532. paste: function(e) {
  533. var pastedText;
  534. if (window.clipboardData  &&  window.clipboardData.getData)  {  // IE
  535.             
  536. pastedText  = $(this).val() +  window.clipboardData.getData('Text');          
  537. else  {            
  538. pastedText  = $(this).val() +  e.originalEvent.clipboardData.getData('Text'); //e.clipboardData.getData('text/plain');
  539.           
  540. }
  541. $(this).val(pastedText);
  542. e.preventDefault();
  543. },
  544. cut: function(e) {
  545. var $this = $(this);
  546. },
  547. blur: function() {
  548. var $this = $(this);
  549. setTimeout(function() {
  550. $this.siblings(".form-drop").hide();
  551. }, 500)
  552. },
  553. focus: function() {
  554. $(this).siblings(".form-drop").show();
  555. },
  556. keyup: function(e) {
  557. if($(this).val().trim()) {
  558. var lNum = $.trim($(this).val()).length;
  559. if(0 < lNum) {
  560. var $this = $(this)
  561. $("#companylist").parent().show();
  562. console.log($(this).val())
  563. $.ajax({
  564. "url": "/ajax/org/qr",
  565. "type": "GET",
  566. "data":{
  567. kw: $(this).val(),
  568. limit:3
  569. },
  570. "success": function(data) {
  571. console.log(data);
  572. if(data.success) {
  573. if(data.data.length == 0) {
  574. $this.siblings(".form-drop").addClass("displayNone");
  575. $this.siblings(".form-drop").find("ul").html("");
  576. } else {
  577. $this.siblings(".form-drop").removeClass("displayNone");
  578. var oSr = "";
  579. for(var i = 0; i < data.data.length; i++) {
  580. var busName=(data.data[i].forShort)?data.data[i].forShort:data.data[i].name;
  581. oSr += '<li style="min-height:40px;position:static;"data-id="'+data.data[i].id+'">' + busName + '</li>';
  582. }
  583. $this.siblings(".form-drop").find("ul").html(oSr);
  584. }
  585. } else {
  586. $this.siblings(".form-drop").addClass("displayNone");
  587. $this.siblings(".form-drop").find("ul").html("");
  588. }
  589. },
  590. dataType: "json",
  591. 'error': function() {
  592. $.MsgBox.Alert('提示', '服务器连接超时!');
  593. }
  594. });
  595. }
  596. } else {
  597. $(this).siblings(".form-drop").addClass("displayNone");
  598. $(this).siblings(".form-drop").find("ul").html("");
  599. }
  600. }
  601. })
  602. $("#company").siblings(".form-drop").on("click", "li", function() {
  603. var oValue = $(this).text();
  604. var oJudge = $(this).parents(".form-drop").siblings(".form-result").find("ul li");
  605. for(var i = 0; i < oJudge.length; i++) {
  606. if(oValue == oJudge[i].innerText) {
  607. $.MsgBox.Alert('提示', '该企业已选择.');
  608. return;
  609. }
  610. }
  611. $(this).parents(".form-drop").siblings(".form-result").find("ul").append('<li style="min-height:40px;" data-id="'+$(this).attr("data-id")+'">' + oValue + '<div class="deleteThis" style="right:0px;"></div></li>');
  612. $(this).parents(".form-drop").siblings("input").val("");
  613. if(oJudge.length == 4) {
  614. $(this).parents(".form-drop").siblings("input").val("");
  615. $("#company").hide();
  616. }
  617. $(this).parent("ul").html("")
  618. })
  619. }
  620. });