portal html css js resource

articalIssue.js 13KB

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