portal html css js resource

articalIssue.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. $(function() {
  2. loginStatus();//判断个人是否登录
  3. var experarray = [];
  4. var resourcesarray = [];
  5. //校验标题
  6. $("#newstitle").on("focus",function(){
  7. $(this).prev().find("span").text("30字以内");
  8. })
  9. $("#newstitle").on("blur",function(){
  10. $(this).prev().find("span").text("");
  11. })
  12. $("#newstitle").on("keyup",function(){
  13. var inputval = $(this).val();
  14. var inputlen = inputval.replace(/[^\u0000-\u00ff]/g, "aa").length;
  15. if(inputlen > 60){
  16. var value = inputval.substring(0,60);
  17. $(this).val(value);
  18. }
  19. })
  20. //校验关键字
  21. $("#KeyWord").on("focus",function(){
  22. $("#keyPrompt").text("最多可添加5个关键词、每个关键词最多10个字");
  23. })
  24. $("#KeyWord").on("blur",function(){
  25. $("#keyPrompt").text("");
  26. })
  27. $("#KeyWord").on("keyup",function(){
  28. $(".frmadd,.keydrop").removeClass("displayNone");
  29. var inputval = $(this).val();
  30. var inputlen = inputval.replace(/[^\u0000-\u00ff]/g, "aa").length;
  31. if(inputlen > 20){
  32. var value = inputval.substring(0,20);
  33. $(this).val(value);
  34. }
  35. })
  36. //添加关键字
  37. $("#addkeyWord").on("click",function(){
  38. var keyWord =$("#KeyWord").val();
  39. keyWordlen(keyWord);
  40. $(".frmadd,.keydrop").addClass("displayNone");
  41. })
  42. //点击搜出的关键字添加
  43. $(".keydrop").on("click","p",function(){
  44. var keyWord =$(this).text();
  45. $(".frmadd,.keydrop").addClass("displayNone");
  46. keyWordlen(keyWord)
  47. })
  48. //删除关键字
  49. $("#keyWordlist").on("click",".closeThis",function(){
  50. $(this).parent().remove();
  51. var plength =$(".keyResult li p").length;
  52. if(plength < 5){
  53. $("#KeyWord").show();
  54. }
  55. })
  56. //组合关键字
  57. function captiureSubInd(subIndu) {
  58. var industrys = $("#" + subIndu + "");
  59. var industryAll = "";
  60. if(industrys.size() > 0) {
  61. for(var i = 0; i < industrys.size(); i++) {
  62. industryAll += industrys[i].innerText;
  63. industryAll += ',';
  64. };
  65. industryAll = industryAll.substring(0, industryAll.length - 1);
  66. }
  67. return industryAll;
  68. }
  69. function keyWordlen(keyWord){
  70. $("#KeyWord").val("");
  71. var plength = $(".keyResult li p");
  72. for(var i=0;i<plength.length;i++){
  73. if(plength[i].innerText==keyWord){
  74. $("#keyPrompt").text("关键词已存在");
  75. return;
  76. }
  77. }
  78. if(plength.length > 3) {
  79. $("#KeyWord").hide();
  80. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>"+ keyWord +"</p><div class='closeThis'></div></li>");
  81. }else{
  82. $("#keyWordlist").append("<li class='delkeylist'><p class='h2Font'>"+ keyWord +"</p><div class='closeThis'></div></li>");
  83. }
  84. }
  85. //校验右侧专家和资源
  86. $("#checkZj").on("focus",function(){
  87. $(this).prev().find("span").text("最多选择3位专家");
  88. })
  89. $("#checkZy").on("focus",function(){
  90. $(this).prev().find("span").text("最多选择3个资源");
  91. })
  92. $("#checkZj,#checkZy").on("blur",function(){
  93. $(this).prev().find("span").text("");
  94. })
  95. $("#checkZj").on("keyup",function(){
  96. var _this=this;
  97. checkZj(_this);
  98. })
  99. $("#checkZy").on("keyup",function(){
  100. $(this).next().removeClass("displayNone");
  101. })
  102. $("#expertlist").on("click","li",function(){
  103. var _this = this;
  104. expertlist(_this,"该专家已选择");
  105. });
  106. $("#resouselist").on("click","li",function(){
  107. var _this = this;
  108. expertlist(_this,"该资源已选择");
  109. });
  110. //点击右侧搜索出的专家和资源列表
  111. function expertlist(_this,title){
  112. var liId = $(_this).html();
  113. var plength = $(_this).parents(".otherBlock").find(".addexpert li");
  114. for(var i=0;i<plength.length;i++){
  115. if(plength[i].innerHTML==liId){
  116. $(_this).parents(".otherBlock").find(".aboutTit span").text(title);
  117. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  118. $(_this).parents(".otherBlock").find("input").val("");
  119. return;
  120. }
  121. }
  122. if(plength.length > 3) {
  123. $(_this).parents(".otherBlock").find("input").hide();
  124. $(_this).parents(".otherBlock").find(".addexpert").append($(_this).clone());
  125. $(_this).parents(".otherBlock").find("input").val("");
  126. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  127. }else{
  128. $(_this).parents(".otherBlock").find(".addexpert").append($(_this).clone());
  129. $(_this).parents(".otherBlock").find("input").val("");
  130. $(_this).parents(".otherBlock").find(".form-drop").addClass("displayNone");
  131. }
  132. }
  133. //删除右侧搜索出的专家和资源
  134. $(".addexpert").on("click",".deleteThis",function(){
  135. var plength = $(this).parent().parent().find("li").length;
  136. if(plength < 6){
  137. $(this).parents(".otherBlock").find("input").show();
  138. }
  139. $(this).parent().remove();
  140. })
  141. function checkZj(_this){
  142. $.ajax({
  143. "url": "/ajax/professor/qaByName",
  144. "type": "get",
  145. "data": {
  146. "name": $("#checkZj").val(),
  147. "total":3
  148. },
  149. "success": function(data) {
  150. console.log(data);
  151. if(data.success ) {
  152. if(data.data != ""){
  153. $(_this).next().removeClass("displayNone");
  154. var itemlist = '';
  155. $("#expertlist").html("");
  156. for(var i = 0; i < data.data.length; i++) {
  157. var itemlist = '<li id="usid">';
  158. itemlist += '<div class="madiaHead useHead" id="userimg"></div>';
  159. itemlist += '<div class="madiaInfo">';
  160. itemlist += '<p class="ellipsisSty"><span class="h1Font" id="name"></span><span class="h2Font" style="margin-left:10px;" id="title"></span></p>';
  161. itemlist += '<p class="h2Font ellipsisSty" id="orgName"></p>';
  162. itemlist += '</div><div class="deleteThis"></div></li>';
  163. $itemlist = $(itemlist);
  164. $("#expertlist").append($itemlist);
  165. var datalist = data.data[i];
  166. $itemlist.attr("data-id",datalist.id);
  167. $itemlist.find("#name").text(datalist.name);
  168. $itemlist.find("#title").text(datalist.title);
  169. $itemlist.find("#orgName").text(datalist.orgName);
  170. if(datalist.hasHeadImage==1) {
  171. $itemlist.find("#userimg").attr("style", "background-image: url(/images/head/" + datalist.id + "_l.jpg);");
  172. }
  173. }
  174. }else{
  175. $(_this).next().addClass("displayNone");
  176. }
  177. }else{
  178. $(_this).next().addClass("displayNone");
  179. }
  180. },
  181. "error": function() {
  182. $.MsgBox.Alert('提示', '链接服务器超时')
  183. }
  184. });
  185. }
  186. var titleflase = false;
  187. var imgflase = false;
  188. //交验图片和标题不能为空
  189. function noTitleImg(){
  190. var ImageKey = $("#uploader").attr("data-id");
  191. var newstitle = $("#newstitle").val();
  192. if(ImageKey==""){
  193. $(".imgtis").text("请上传封面图片");
  194. }else{
  195. $(".imgtis").text("");
  196. imgflase = true;
  197. }
  198. if(newstitle==""){
  199. $("#aboutTit span").text("请输入文章标题");
  200. }else{
  201. $("#aboutTit span").text("");
  202. titleflase = true;
  203. }
  204. }
  205. //获取相关专家
  206. function expertli(){
  207. $("#expertli li").each(function(i){
  208. var liid = $(this).attr("data-id");
  209. experarray.push(liid);
  210. });
  211. return experarray;
  212. }
  213. //获取相关专家
  214. function resourcesli(){
  215. $("#resources li").each(function(i){
  216. var liid = $(this).attr("data-id");
  217. resourcesarray.push(liid);
  218. });
  219. return resourcesarray;
  220. }
  221. //文章发布
  222. $("#release").on("click",function(){
  223. noTitleImg();
  224. if(imgflase && titleflase){
  225. $.MsgBox.Confirm("提示","确认发布该文章?",newsAdd);
  226. }
  227. })
  228. //文章存草稿
  229. $("#draft").on("click",function(){
  230. noTitleImg();
  231. if(imgflase && titleflase){
  232. draftAdd(1);
  233. }
  234. })
  235. //文章预览
  236. $("#preview").on("click",function(){
  237. noTitleImg();
  238. if(imgflase && titleflase){
  239. draftAdd(2);
  240. }
  241. })
  242. /*文章添加*/
  243. function newsAdd(){
  244. expertli();//相关专家
  245. resourcesli();//相关咨询
  246. var $data = {};
  247. $data.professorId = userid;
  248. $data.articleTitle = $("#newstitle").val();
  249. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  250. $data.articleImg = $("#uploader").attr("data-id");
  251. $data.articleContent = ue.getContent();
  252. $data.professors = experarray;
  253. $data.resources = resourcesarray;
  254. console.log($data);
  255. $.ajax({
  256. "url" : "/ajax/article/save",
  257. "type" : "post" ,
  258. "dataType" : "json",
  259. "data" :$data,
  260. "traditional": true, //传数组必须加这个
  261. "success" : function(data) {
  262. console.log(data);
  263. if (data.success){
  264. articleId = data.data;
  265. $.MsgBox.Alert("提示","文章发表成功!",function articalList(){
  266. location.href = "articalList.html";
  267. });
  268. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  269. } else {
  270. $.MsgBox.Alert("提示","文章发表失败!");
  271. }
  272. },
  273. "error":function(){
  274. $.MsgBox.Alert('提示','链接服务器超时')
  275. }
  276. });
  277. }
  278. /*文章添加草稿和文章预览*/
  279. function draftAdd(num){
  280. expertli();//相关专家
  281. resourcesli();//相关咨询
  282. var $data = {};
  283. $data.professorId = userid;
  284. $data.articleTitle = $("#newstitle").val();
  285. $data.subject = captiureSubInd("keyWordlist .delkeylist");
  286. $data.articleImg = $("#uploader").attr("data-id");
  287. $data.articleContent = ue.getContent();
  288. $data.professors = experarray;
  289. $data.resources = resourcesarray;
  290. console.log($data);
  291. $.ajax({
  292. "url" : "/ajax/article/draft",
  293. "type" : "post" ,
  294. "dataType" : "json",
  295. "data" :$data,
  296. "traditional": true, //传数组必须加这个
  297. "success" : function(data) {
  298. console.log(data);
  299. if(num==1){
  300. if (data.success){
  301. articleId = data.data;
  302. $.MsgBox.Alert("提示","文章已保存草稿。");
  303. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  304. }
  305. }
  306. if(num==2){
  307. if (data.success){
  308. articleId = data.data;
  309. window.open("articalPreview.html?articleId="+ articleId)
  310. }
  311. }
  312. },
  313. "error":function(){
  314. $.MsgBox.Alert('提示','链接服务器超时')
  315. }
  316. });
  317. }
  318. });