portal html css js resource

articalIssue.js 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 style="position:relative"><div class="input-append date form_date form_datetime" data-link-field="dtp_input2" >'+
  271. '<em class="mr_sj"></em>'+
  272. '<input size="16" type="text" readonly class="frmtype frmcontype fColor" placeholder="请设置文章发布的时间">'+
  273. '<span class="dateIcon"><i class="icon-calendar displayNone"></i></span>'+
  274. '<span class="add-on"><i class="icon-th displayNone"></i></span>'+
  275. '</div>'+
  276. '<input type="hidden" id="dtp_input2"/>'+
  277. '<span></span></div></div>'
  278. var a = new Date();
  279. var c = a.getFullYear() + "-" + (Number(a.getMonth()) + 1) + "-" + (Number(a.getDate()));
  280. //定时文章发布
  281. $("#setTimeIssue").on("click", function() {
  282. if($(this).hasClass("disableLi")){
  283. return;
  284. }
  285. noTitleImg();
  286. if(imgflase && titleflase) {
  287. $(".blackcover2").fadeIn();
  288. $(".modelContain").show();
  289. $("body").addClass("modelOpen");
  290. $(".mb-listR").remove(); $("#promotTh").append(seleTime);//时间选择器
  291. $(".mb-listR .form_datetime").datetimepicker({
  292. language: 'ch',
  293. format: 'yyyy-mm-dd hh:ii',
  294. forceParse: 1,
  295. autoclose: 1,
  296. todayBtn: 1,
  297. todayHighlight: 1,
  298. startDate: c,
  299. oflag: 1,
  300. });
  301. $(".mb-listR .form_datetime .frmcontype").val(getNowFormatDate());
  302. $(".mb_btnOk").on("click", function() {
  303. var publishTime = $(".mb-listR .form_datetime .frmcontype").val();
  304. console.log(st6(publishTime));
  305. setTimeIssue(st6(publishTime));
  306. })
  307. }
  308. })
  309. //文章存草稿
  310. $("#draft").on("click", function() {
  311. if($(this).hasClass("disableLi")){
  312. return;
  313. }
  314. noTitleImg();
  315. if(imgflase && titleflase) {
  316. draftAdd(1);
  317. }
  318. })
  319. //文章预览
  320. $("#preview").on("click", function() {
  321. if($(this).hasClass("disableLi")){
  322. return;
  323. }
  324. noTitleImg();
  325. if(imgflase && titleflase) {
  326. draftAdd(2);
  327. }
  328. })
  329. /*获取数据*/
  330. function getdata(publishTime) {
  331. var industrys = $("#keyWordlist li");
  332. var industryAll = "";
  333. if(industrys.size() > 0) {
  334. for(var i = 0; i < industrys.size(); i++) {
  335. industryAll += industrys[i].innerText.trim();
  336. industryAll += ',';
  337. };
  338. industryAll = industryAll.substring(0, industryAll.length - 1);
  339. }
  340. expertli(); //相关专家
  341. resourcesli(); //相关咨询
  342. $data.ownerId = userid;
  343. $data.articleType = "1";
  344. $data.articleTitle = $("#newstitle").val();
  345. $data.subject = industryAll;
  346. $data.articleImg = $("#uploader").attr("data-id");
  347. $data.articleContent = ue.getContent();
  348. $data.professors = experarray;
  349. $data.resources = relaResource("resouceli");
  350. $data.colNum=1;
  351. $data.wares=relaResource("sevriceli");
  352. if($("#hidearticleId").val().length != 0) {
  353. $data.articleId = $("#hidearticleId").val();
  354. }
  355. if(publishTime!="") {
  356. $data.publishTime = publishTime;
  357. }
  358. console.log($data);
  359. }
  360. /*文章发布*/
  361. function newsAdd() {
  362. $(".operateBlock").find("li").addClass("disableLi");
  363. getdata();
  364. $.ajax({
  365. "url": "/ajax/article/save",
  366. "type": "post",
  367. "dataType": "json",
  368. "data": $data,
  369. "traditional": true, //传数组必须加这个
  370. "complete":function(){
  371. $(".operateBlock").find("li").removeClass("disableLi");
  372. },
  373. "success": function(data) {
  374. console.log(data);
  375. if(data.success) {
  376. $("#hidearticleId").val(data.data);
  377. $.MsgBox.Alert("提示", "文章发表成功!", function articalList() {
  378. location.href = "articalList.html";
  379. });
  380. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  381. } else {
  382. if(data.code==90) {
  383. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  384. }else{
  385. $.MsgBox.Alert("提示", "文章发表失败!");
  386. }
  387. }
  388. },
  389. "error": function() {
  390. $.MsgBox.Alert('提示', '链接服务器超时')
  391. }
  392. });
  393. }
  394. /*文章定时发布*/
  395. function setTimeIssue(publishTime) {
  396. var opublishTime=publishTime+"01";
  397. getdata(opublishTime);
  398. $(".operateBlock").find("li").addClass("disableLi");
  399. $.ajax({
  400. "url": "/ajax/article/timing",
  401. "type": "post",
  402. "dataType": "json",
  403. "data": $data,
  404. "traditional": true, //传数组必须加这个
  405. "complete":function(){
  406. $(".operateBlock").find("li").removeClass("disableLi");
  407. },
  408. "success": function(data) {
  409. if(data.success) {
  410. console.log(data)
  411. $("#hidearticleId").val(data.data);
  412. location.href = "articalList.html";
  413. } else {
  414. if(data.code==90) {
  415. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  416. }else{
  417. $.MsgBox.Alert("提示", "文章发表失败!");
  418. }
  419. }
  420. },
  421. "error": function() {
  422. $.MsgBox.Alert('提示', '链接服务器超时')
  423. }
  424. });
  425. }
  426. /*文章添加草稿和文章预览*/
  427. function draftAdd(num) {
  428. $(".operateBlock").find("li").addClass("disableLi");
  429. getdata();
  430. $.ajax({
  431. "url": "/ajax/article/draft",
  432. "type": "post",
  433. "dataType": "json",
  434. "data": $data,
  435. "traditional": true, //传数组必须加这个
  436. complete:function(){
  437. $(".operateBlock").find("li").removeClass("disableLi");
  438. },
  439. "success": function(data) {
  440. console.log(data);
  441. if(num == 1) {
  442. if(data.success) {
  443. $("#hidearticleId").val(data.data);
  444. articleId = data.data;
  445. $.MsgBox.Alert("提示", "文章已保存草稿。");
  446. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  447. $("#delete").removeClass("disableLi").addClass("odele");
  448. }else{
  449. if(data.code==90) {
  450. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  451. }else{
  452. $.MsgBox.Alert("提示", "文章发表失败!");
  453. }
  454. }
  455. }
  456. if(num == 2) {
  457. if(data.success) {
  458. $("#hidearticleId").val(data.data);
  459. articleId = data.data;
  460. $("#delete").removeClass("disableLi").addClass("odele");
  461. fa = true;
  462. }else{
  463. if(data.code==90) {
  464. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  465. }else{
  466. $.MsgBox.Alert("提示", "文章发表失败!");
  467. }
  468. }
  469. if(fa) {
  470. window.open("articalPreview.html?articleId=" + articleId)
  471. }
  472. }
  473. },
  474. "error": function() {
  475. $.MsgBox.Alert('提示', '链接服务器超时')
  476. }
  477. });
  478. }
  479. function st6(osr) {
  480. var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10) + osr.substring(11, 13) + osr.substring(14, 16);
  481. return tim;
  482. }
  483. /*删除文章*/
  484. $(".operateBlock").on("click",".odele",function(){
  485. $.MsgBox.Confirm("提示","确认删除该文章?",newsDelet);
  486. })
  487. /*文章删除*/
  488. function newsDelet() {
  489. $.ajax({
  490. "url" : "/ajax/article/deleteArticle",
  491. "type" : "POST",
  492. "dataType" : "json",
  493. "data": {
  494. "articleId": articleId
  495. },
  496. "success" : function($data) {
  497. if ($data.success) {
  498. location.href = "articalList.html";
  499. }
  500. },
  501. "error":function(){
  502. $.MsgBox.Alert('提示','链接服务器超时')
  503. }
  504. })
  505. }
  506. $("#sevriceli,#resouceli").on("click", "li", function() {
  507. $(this).find(".selectNull").toggleClass("selectAdd");
  508. });
  509. function relaResource(select) {
  510. var arr1 = $("#"+select).find(".selectAdd"),
  511. arr2 = [];
  512. for(var i = 0; i < arr1.length; i++) {
  513. arr2.push(arr1.eq(i).parents("li").attr("data-id"));
  514. }
  515. return arr2;
  516. }
  517. function ajaxRequist(url, obj, type, fn) {
  518. $.ajax({
  519. url: url,
  520. data: obj,
  521. dataType: 'json', //服务器返回json格式数据
  522. type: type, //支持'GET'和'POST'
  523. traditional: true,
  524. success: function(data) {
  525. if(data.success) {
  526. fn(data)
  527. }
  528. },
  529. error: function(xhr, type, errorThrown) {
  530. $.MsgBox.Alert('提示', '服务器请求失败');
  531. }
  532. });
  533. }
  534. ajaxRequist("/ajax/ware/publish", {
  535. category:1,
  536. owner:userid,
  537. rows:1111,
  538. }, "get", function(data) {
  539. var data = data.data,
  540. oArr = [];
  541. if(data.length == 0) {
  542. $("#sevriceli").addClass("displayNone").siblings(".seRe").removeClass('displayNone');
  543. } else {
  544. for(var i = 0; i < data.length; i++) {
  545. oArr.push(data[i].id);
  546. var str = '<li class="listy" data-id="' + data[i].id + '" style="margin-left:-20px;margin-right:-20px;">' +
  547. '<p class="col-w-9 h2font ellipsisSty-2 col childElement">' + data[i].name + '</p>' +
  548. '<div class="selectNull"></div></li>'
  549. $("#sevriceli").append(str);
  550. }
  551. }
  552. })
  553. ajaxRequist("/ajax/resource/qaProPublish", {
  554. "professorId": userid
  555. }, "get", function(data) {
  556. console.log(data)
  557. var data = data.data,
  558. oArr = [];
  559. if(data.length == 0) {
  560. $("#resouceli").addClass("displayNone").siblings(".seRe").removeClass('displayNone');
  561. } else {
  562. for(var i = 0; i < data.length; i++) {
  563. oArr.push(data[i].resourceId);
  564. var str = '<li class="listy" style="margin-right:-20px;margin-left:-20px;"data-id="' + data[i].resourceId + '">' +
  565. '<p class="col-w-9 h2font ellipsisSty-2 col childElement">' + data[i].resourceName + '</p>' +
  566. '<div class="selectNull"></div></li>'
  567. $("#resouceli").append(str);
  568. }
  569. }
  570. })
  571. });