portal html css js resource

articalIssue.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. $itemlist.find("#name").text(datalist.professor.name);
  223. if(datalist.images.length > 0) {
  224. $itemlist.find("#userimg").attr("style", "background-image: url(/data/resource/" + datalist.images[0].imageSrc + ");");
  225. }
  226. }
  227. } else {
  228. $(_this).next().addClass("displayNone");
  229. }
  230. } else {
  231. $(_this).next().addClass("displayNone");
  232. }
  233. },
  234. "error": function() {
  235. $.MsgBox.Alert('提示', '链接服务器超时')
  236. }
  237. });
  238. }
  239. function KeyWordList() {
  240. $.ajax({
  241. "url": "/ajax/dataDict/qaHotKey",
  242. "type": "get",
  243. "data": {
  244. "key": $("#KeyWord").val()
  245. },
  246. "success": function(data) {
  247. console.log(data);
  248. if(data.success) {
  249. if(data.data != "") {
  250. var itemlist = '';
  251. $("#keydropList").html("");
  252. for(var i = 0; i < data.data.length; i++) {
  253. var itemlist = '<li><p class="h2Font"></p></li>';
  254. $itemlist = $(itemlist);
  255. $("#keydropList").append($itemlist);
  256. $itemlist.find(".h2Font").text(data.data[i].caption);
  257. }
  258. } else {
  259. $(".keydrop").addClass("displayNone");
  260. }
  261. } else {
  262. $(".keydrop").addClass("displayNone");
  263. }
  264. },
  265. "error": function() {
  266. $.MsgBox.Alert('提示', '链接服务器超时')
  267. }
  268. });
  269. }
  270. var titleflase = false;
  271. var imgflase = false;
  272. //交验图片和标题不能为空
  273. function noTitleImg() {
  274. var ImageKey = $("#uploader").attr("data-id");
  275. var newstitle = $("#newstitle").val();
  276. if(ImageKey == "") {
  277. $(".imgtis").text("请上传封面图片");
  278. } else {
  279. $(".imgtis").text("");
  280. imgflase = true;
  281. }
  282. if(newstitle == "") {
  283. $("#aboutTit span").text("请输入文章标题");
  284. } else {
  285. $("#aboutTit span").text("");
  286. titleflase = true;
  287. }
  288. }
  289. //获取相关专家
  290. function expertli() {
  291. $("#expertli li").each(function(i) {
  292. var liid = $(this).attr("data-id");
  293. experarray.push(liid);
  294. });
  295. return $.unique(experarray);
  296. }
  297. //获取相关资源
  298. function resourcesli() {
  299. $("#resources li").each(function(i) {
  300. var liid = $(this).attr("data-id");
  301. resourcesarray.push(liid);
  302. });
  303. return $.unique(resourcesarray);
  304. }
  305. //文章发布
  306. $("#release").on("click", function() {
  307. noTitleImg();
  308. if(imgflase && titleflase) {
  309. $.MsgBox.Confirm("提示", "确认发布该文章?", newsAdd);
  310. }
  311. })
  312. //定时文章发布
  313. $("#setTimeIssue").on("click", function() {
  314. noTitleImg();
  315. if(imgflase && titleflase) {
  316. $(".blackcover2").fadeIn();
  317. $(".modelContain").show();
  318. $("body").addClass("modelOpen");
  319. $(".mb_btnOk").on("click", function() {
  320. var publishTime = $(".form_datetime").val();
  321. console.log(st6(publishTime));
  322. setTimeIssue(st6(publishTime));
  323. })
  324. }
  325. })
  326. //文章存草稿
  327. $("#draft").on("click", function() {
  328. noTitleImg();
  329. if(imgflase && titleflase) {
  330. draftAdd(1);
  331. }
  332. })
  333. //文章预览
  334. $("#preview").on("click", function() {
  335. noTitleImg();
  336. if(imgflase && titleflase) {
  337. draftAdd(2);
  338. }
  339. })
  340. /*获取数据*/
  341. function getdata(publishTime) {
  342. expertli(); //相关专家
  343. resourcesli(); //相关咨询
  344. $data.professorId = userid;
  345. $data.articleTitle = $("#newstitle").val();
  346. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  347. $data.articleImg = $("#uploader").attr("data-id");
  348. $data.articleContent = ue.getContent();
  349. $data.professors = experarray;
  350. $data.resources = resourcesarray;
  351. if($("#hidearticleId").val().length != 0) {
  352. $data.articleId = $("#hidearticleId").val();
  353. }
  354. if($(".form_datetime").val().length != 0) {
  355. $data.publishTime = publishTime;
  356. }
  357. console.log($data);
  358. }
  359. /*文章发布*/
  360. function newsAdd() {
  361. getdata();
  362. $.ajax({
  363. "url": "/ajax/article/save",
  364. "type": "post",
  365. "dataType": "json",
  366. "data": $data,
  367. "traditional": true, //传数组必须加这个
  368. "success": function(data) {
  369. console.log(data);
  370. if(data.success) {
  371. $("#hidearticleId").val(data.data);
  372. $.MsgBox.Alert("提示", "文章发表成功!", function articalList() {
  373. location.href = "articalList.html";
  374. });
  375. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  376. } else {
  377. $.MsgBox.Alert("提示", "文章发表失败!");
  378. }
  379. },
  380. "error": function() {
  381. $.MsgBox.Alert('提示', '链接服务器超时')
  382. }
  383. });
  384. }
  385. /*文章定时发布*/
  386. function setTimeIssue(publishTime) {
  387. getdata(publishTime);
  388. $.ajax({
  389. "url": "/ajax/article/timing",
  390. "type": "post",
  391. "dataType": "json",
  392. "data": $data,
  393. "traditional": true, //传数组必须加这个
  394. "success": function(data) {
  395. console.log(data);
  396. if(data.success) {
  397. $("#hidearticleId").val(data.data);
  398. location.href = "articalList.html";
  399. } else {
  400. $.MsgBox.Alert("提示", "文章发表失败!");
  401. }
  402. },
  403. "error": function() {
  404. $.MsgBox.Alert('提示', '链接服务器超时')
  405. }
  406. });
  407. }
  408. /*文章添加草稿和文章预览*/
  409. function draftAdd(num) {
  410. getdata();
  411. $.ajax({
  412. "url": "/ajax/article/draft",
  413. "type": "post",
  414. "dataType": "json",
  415. "data": $data,
  416. "traditional": true, //传数组必须加这个
  417. "success": function(data) {
  418. console.log(data);
  419. if(num == 1) {
  420. if(data.success) {
  421. $("#hidearticleId").val(data.data);
  422. $.MsgBox.Alert("提示", "文章已保存草稿。");
  423. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  424. }
  425. }
  426. if(num == 2) {
  427. if(data.success) {
  428. $("#hidearticleId").val(data.data);
  429. articleId = data.data;
  430. fa = true;
  431. }
  432. if(fa) {
  433. window.open("articalPreview.html?articleId=" + articleId)
  434. }
  435. }
  436. },
  437. "error": function() {
  438. $.MsgBox.Alert('提示', '链接服务器超时')
  439. }
  440. });
  441. }
  442. function st6(osr) {
  443. var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10) + osr.substring(11, 13) + osr.substring(14, 16);
  444. return tim;
  445. }
  446. });