portal html css js resource

articalIssue.js 15KB

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