portal html css js resource

articalIssue.js 13KB

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