portal html css js resource

articalModify.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. $(function() {
  2. loginStatus();//判断个人是否登录
  3. var articleId = GetQueryString("articleId");
  4. var experarray = [];
  5. var resourcesarray = [];
  6. articleshow();
  7. relevantExperts();
  8. //校验标题
  9. $("#newstitle").on("focus",function(){
  10. $(this).prev().find("span").text("30字以内");
  11. })
  12. $("#newstitle").on("blur",function(){
  13. $(this).prev().find("span").text("");
  14. })
  15. $("#newstitle").on("keyup",function(){
  16. var inputval = $(this).val();
  17. var inputlen = inputval.replace(/[^\u0000-\u00ff]/g, "aa").length;
  18. if(inputlen > 60){
  19. var value = inputval.substring(0,60);
  20. $(this).val(value);
  21. }
  22. })
  23. //校验关键字
  24. $("#KeyWord").on("focus",function(){
  25. $("#keyPrompt").text("最多可添加5个关键词、每个关键词最多10个字");
  26. })
  27. $("#KeyWord").on("blur",function(){
  28. $("#keyPrompt").text("");
  29. })
  30. $("#KeyWord").on("keyup",function(){
  31. $(".frmadd,.keydrop").removeClass("displayNone");
  32. var inputval = $(this).val();
  33. var inputlen = inputval.replace(/[^\u0000-\u00ff]/g, "aa").length;
  34. if(inputlen > 20){
  35. var value = inputval.substring(0,20);
  36. $(this).val(value);
  37. }
  38. })
  39. //添加关键字
  40. $("#addkeyWord").on("click",function(){
  41. var keyWord =$("#KeyWord").val();
  42. keyWordlen(keyWord);
  43. $(".frmadd,.keydrop").addClass("displayNone");
  44. })
  45. //点击搜出的关键字添加
  46. $(".keydrop").on("click","p",function(){
  47. var keyWord =$(this).text();
  48. $(".frmadd,.keydrop").addClass("displayNone");
  49. keyWordlen(keyWord)
  50. })
  51. //删除关键字
  52. $("#keyWordlist").on("click",".closeThis",function(){
  53. $(this).parent().remove();
  54. var plength =$(".keyResult li p").length;
  55. if(plength < 5){
  56. $("#KeyWord").show();
  57. }
  58. })
  59. //组合关键字
  60. function captiureSubInd(subIndu) {
  61. var industrys = $("#" + subIndu + "");
  62. var industryAll = "";
  63. if(industrys.size() > 0) {
  64. for(var i = 0; i < industrys.size(); i++) {
  65. industryAll += industrys[i].innerText;
  66. industryAll += ',';
  67. };
  68. industryAll = industryAll.substring(0, industryAll.length - 1);
  69. }
  70. return industryAll;
  71. }
  72. //拆解关键字
  73. function industryShow(data,industryList){
  74. if(data != undefined && data.length != 0 ){
  75. var subs = new Array();
  76. if(data.indexOf(',')){
  77. subs = data.split(',');
  78. }else{
  79. subs[0] = data;
  80. }
  81. if(subs.length>0){
  82. for (var i = 0; i < subs.length; i++)
  83. {
  84. $("#"+industryList+"").append('<li class="delkeylist"><p class="h2Font">'+ subs[i] +'</p><div class="closeThis"></div></li>');
  85. };
  86. }
  87. }
  88. }
  89. function keyWordlen(keyWord){
  90. $("#KeyWord").val("");
  91. var plength = $(".keyResult li p");
  92. for(var i=0;i<plength.length;i++){
  93. if(plength[i].innerText==keyWord){
  94. $("#keyPrompt").text("关键词已存在");
  95. return;
  96. }
  97. }
  98. if(plength.length > 3) {
  99. $("#KeyWord").hide();
  100. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>"+ keyWord +"</p><div class='closeThis'></div></li>");
  101. }else{
  102. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>"+ keyWord +"</p><div class='closeThis'></div></li>");
  103. }
  104. }
  105. //校验右侧专家和资源
  106. $("#checkZj").on("focus",function(){
  107. $(this).prev().find("span").text("最多选择3位专家");
  108. })
  109. $("#checkZy").on("focus",function(){
  110. $(this).prev().find("span").text("最多选择3个资源");
  111. })
  112. $("#checkZj,#checkZy").on("blur",function(){
  113. $(this).prev().find("span").text("");
  114. })
  115. $("#checkZj").on("keyup",function(){
  116. var _this=this;
  117. checkZj(_this);
  118. })
  119. $("#checkZy").on("keyup",function(){
  120. $(this).next().removeClass("displayNone");
  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">';
  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. //初始化数据
  207. function articleshow(){
  208. $.ajax({
  209. "url" : "/ajax/article/query",
  210. "type" : "GET" ,
  211. "dataType" : "json",
  212. "data" :{"articleId":articleId},
  213. "success" : function(data) {
  214. console.log(data)
  215. if (data.success){
  216. $("#newstitle").val(data.data.articleTitle);
  217. if(data.data.articleImg){
  218. $("#uploader").attr("style", "background-image: url(/data/article/" + data.data.articleImg + ");");
  219. $(".upFront").hide();
  220. $(".upBackbtn").show();
  221. }
  222. ue.ready(function() {
  223. if(data.data.articleContent==undefined){
  224. var datadescp ="";
  225. }else{
  226. var datadescp = data.data.articleContent;
  227. }
  228. ue.setContent(datadescp);
  229. });
  230. industryShow(data.data.subject,"keyWordlist");
  231. }
  232. },
  233. "error":function(){
  234. $.MsgBox.Alert('提示','链接服务器超时')
  235. }
  236. });
  237. }
  238. //相关专家
  239. function relevantExperts(){
  240. $.ajax({
  241. "url": "/ajax/article/ralatePro",
  242. "type": "get",
  243. "dataType" : "json",
  244. "data" :{"articleId":articleId},
  245. "success": function(data) {
  246. if(data.success && data.data) {
  247. for(var i = 0; i < data.data.length; i++) {
  248. var professorId = data.data[i].professorId;
  249. relevantExpertsList(professorId)
  250. }
  251. }
  252. },
  253. "error": function() {
  254. $.MsgBox.Alert('提示', '链接服务器超时')
  255. }
  256. });
  257. }
  258. //相关专家信息
  259. function relevantExpertsList(professorId){
  260. $.ajax({
  261. "url" : "/ajax/professor/info/"+professorId,
  262. "type" : "GET" ,
  263. "dataType" : "json",
  264. "success" : function(data) {
  265. if (data.success && data.data){
  266. var itemlist = '';
  267. $("#expertli").html("");
  268. var itemlist = '<li id="usid">';
  269. itemlist += '<div class="madiaHead useHead" id="userimg"></div>';
  270. itemlist += '<div class="madiaInfo">';
  271. itemlist += '<p class="ellipsisSty"><span class="h1Font" id="name"></span><span class="h2Font" style="margin-left:10px;" id="title"></span></p>';
  272. itemlist += '<p class="h2Font ellipsisSty" id="orgName"></p>';
  273. itemlist += '</div><div class="deleteThis"></div></li>';
  274. $itemlist = $(itemlist);
  275. $("#expertli").append($itemlist);
  276. var datalist = data.data;
  277. $itemlist.attr("data-id",datalist.id);
  278. $itemlist.find("#name").text(datalist.name);
  279. $itemlist.find("#title").text(datalist.title);
  280. $itemlist.find("#orgName").text(datalist.orgName);
  281. if(datalist.hasHeadImage==1) {
  282. $itemlist.find("#userimg").attr("style", "background-image: url(/images/head/" + datalist.id + "_l.jpg);");
  283. }
  284. }
  285. },
  286. "error":function(){
  287. $.MsgBox.Alert('提示','链接服务器超时')
  288. }
  289. });
  290. }
  291. var titleflase = false;
  292. //交验图片和标题不能为空
  293. function noTitleImg(){
  294. //var ImageKey = $("#uploader").attr("data-id");
  295. var newstitle = $("#newstitle").val();
  296. /*if(ImageKey==""){
  297. $(".imgtis").text("请上传封面图片");
  298. }else{
  299. $(".imgtis").text("");
  300. imgflase = true;
  301. }*/
  302. if(newstitle==""){
  303. $("#aboutTit span").text("请输入文章标题");
  304. }else{
  305. $("#aboutTit span").text("");
  306. titleflase = true;
  307. }
  308. alert(titleflase)
  309. }
  310. //获取相关专家
  311. function expertli(){
  312. $("#expertli li").each(function(i){
  313. var liid = $(this).attr("data-id");
  314. experarray.push(liid);
  315. });
  316. return experarray;
  317. }
  318. //获取相关专家
  319. function resourcesli(){
  320. $("#resources li").each(function(i){
  321. var liid = $(this).attr("data-id");
  322. resourcesarray.push(liid);
  323. });
  324. return resourcesarray;
  325. }
  326. //文章发布
  327. $("#release").on("click",function(){
  328. noTitleImg();
  329. if(titleflase){
  330. $.MsgBox.Confirm("提示","确认发布该文章?",newsAdd);
  331. }
  332. })
  333. //文章存草稿
  334. $("#draft").on("click",function(){
  335. noTitleImg();
  336. if(titleflase){
  337. draftAdd(1);
  338. }
  339. })
  340. //文章预览
  341. $("#preview").on("click",function(){
  342. noTitleImg();
  343. if(titleflase){
  344. draftAdd(2);
  345. }
  346. })
  347. /*文章添加*/
  348. function newsAdd(){
  349. expertli();//相关专家
  350. resourcesli();//相关咨询
  351. var $data = {};
  352. $data.articleId = articleId;
  353. $data.professorId = userid;
  354. $data.articleTitle = $("#newstitle").val();
  355. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  356. $data.articleImg = $("#uploader").attr("data-id");
  357. $data.articleContent = ue.getContent();
  358. $data.professors = experarray;
  359. $data.resources = resourcesarray;
  360. console.log($data);
  361. $.ajax({
  362. "url" : "/ajax/article/save",
  363. "type" : "post" ,
  364. "dataType" : "json",
  365. "data" :$data,
  366. "traditional": true, //传数组必须加这个
  367. "success" : function(data) {
  368. console.log(data);
  369. if (data.success){
  370. articleId = data.data;
  371. $.MsgBox.Alert("提示","文章发表成功!",function articalList(){
  372. location.href = "articalList.html";
  373. });
  374. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  375. } else {
  376. $.MsgBox.Alert("提示","文章发表失败!");
  377. }
  378. },
  379. "error":function(){
  380. $.MsgBox.Alert('提示','链接服务器超时')
  381. }
  382. });
  383. }
  384. /*文章添加草稿和文章预览*/
  385. function draftAdd(num){
  386. expertli();//相关专家
  387. resourcesli();//相关咨询
  388. var $data = {};
  389. $data.articleId = articleId;
  390. $data.professorId = userid;
  391. $data.articleTitle = $("#newstitle").val();
  392. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  393. $data.articleImg = $("#uploader").attr("data-id");
  394. $data.articleContent = ue.getContent();
  395. $data.professors = experarray;
  396. $data.resources = resourcesarray;
  397. console.log($data);
  398. $.ajax({
  399. "url" : "/ajax/article/draft",
  400. "type" : "post" ,
  401. "dataType" : "json",
  402. "data" :$data,
  403. "traditional": true, //传数组必须加这个
  404. "success" : function(data) {
  405. console.log(data);
  406. if(num==1){
  407. if (data.success){
  408. articleId = data.data;
  409. $.MsgBox.Alert("提示","文章已保存草稿。");
  410. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  411. articleshow();
  412. }
  413. }
  414. if(num==2){
  415. if (data.success){
  416. articleId = data.data;
  417. window.open("articalPreview.html?articleId="+ articleId)
  418. }
  419. }
  420. },
  421. "error":function(){
  422. $.MsgBox.Alert('提示','链接服务器超时')
  423. }
  424. });
  425. }
  426. });