portal html css js resource

resourceIssue.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. $(document).ready(function() {
  2. var resourceId = GetQueryString("resourceId");
  3. if(resourceId) {
  4. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  5. getRecourceMe();
  6. }
  7. var orgId = $.cookie('orgId');
  8. if(orgId == "" || orgId == null || orgId == "null"){
  9. location.href = "cmp-settled-log.html";
  10. }
  11. var temp = [];
  12. var array = [];
  13. var oProfessor=[];
  14. var hbur,hburEnd;
  15. ue = UE.getEditor('editor', {});
  16. /*获取资源信息*/
  17. function getRecourceMe() {
  18. $.ajax({
  19. "url": "/ajax/resource/queryOne",
  20. "type": "GET",
  21. "success": function(data) {
  22. console.log(data);
  23. if(data.success) {
  24. $("#uploadDd").siblings().remove();
  25. $("#fileList").append("<dd></dd><dd></dd>");
  26. temp=[];
  27. array=[];
  28. resourceHtml(data.data);
  29. }
  30. },
  31. "data": {
  32. "resourceId": resourceId
  33. },
  34. dataType: "json",
  35. 'error': function() {
  36. $.MsgBox.Alert('提示', '服务器连接超时!');
  37. }
  38. });
  39. }
  40. /*处理资源html代码*/
  41. function resourceHtml($da) {
  42. $("#resourceName").val($da.resourceName); //名字
  43. $("#application").val($da.supportedServices); //应用用途
  44. if($da.spec) { //厂商型号
  45. $("#modelNumber").val($da.spec);
  46. }
  47. if($da.parameter) { //性能参数
  48. $("#performancePa").val($da.parameter);
  49. }
  50. if($da.cooperationNotes) { //合作备注
  51. $("#remarkContent").val($da.cooperationNotes);
  52. }
  53. if($da.subject) {
  54. var oSub = $da.subject.split(",");
  55. var oSt = "";
  56. for(var i = 0; i < oSub.length; i++) {
  57. oSt += '<li><p class="h2Font">' + oSub[i] + '</p><div class="closeThis"></div></li>'
  58. }
  59. $("#keywordList").html(oSt);
  60. } else {
  61. $("#keywordList").html("");
  62. }
  63. if($da.descp) { //编辑器
  64. ue.ready(function() {
  65. ue.setContent($da.descp);
  66. });
  67. }
  68. if($da.images.length) {
  69. var arr = [];
  70. for(var i = 0; i < $da.images.length; i++) {
  71. var oString = '<dd>' +
  72. '<div class="imgItem">' +
  73. '<img src="' + "/data/resource/" + $da.images[i].imageSrc + '"/>' +
  74. '</div>' +
  75. '<div class="file-panel">' +
  76. '<span class="cancel" flag=1></span>' +
  77. '</div>' +
  78. '</dd>'
  79. arr[i] = oString;
  80. array[i] = $da.images[i].imageId;
  81. }
  82. $("#fileList dd").eq(2).remove();
  83. if($da.images.length == 1) {
  84. $("#fileList").prepend(arr[0]);
  85. } else if($da.images.length == 2) {
  86. $("#fileList dd").eq(1).remove();
  87. $("#fileList").prepend(arr[1]);
  88. $("#fileList").prepend(arr[0]);
  89. } else if($da.images.length == 3) {
  90. $("#fileList dd").eq(1).remove();
  91. $("#fileList").prepend(arr[2]);
  92. $("#fileList").prepend(arr[1]);
  93. $("#fileList").prepend(arr[0]);
  94. }
  95. }
  96. }
  97. var uploader = WebUploader.create({
  98. auto: true,
  99. fileNumLimit: 3,
  100. swf: '../js/webuploader/Uploader.swf',
  101. server: '../ajax/cachedFileUpload',
  102. fileSingleSizeLimit: 2 * 1024 * 1024,
  103. pick: {
  104. id: "#filePicker",
  105. multiple: false
  106. },
  107. accept: {
  108. title: 'Images',
  109. extensions: 'jpg,jpeg,png',
  110. mimeTypes: 'image/jpg,image/png'
  111. }
  112. });
  113. // 当有文件添加进来的时候
  114. uploader.on('fileQueued', function(file) {
  115. fileId = file.id;
  116. var $len = $("#fileList").find("img").length;
  117. if($len == 0 || $len == 1) {
  118. var oRemove = $("#fileList").find("dd");
  119. oRemove.eq(oRemove.length - 1).remove();
  120. }
  121. var $li = $(
  122. '<dd>' +
  123. '<div class="imgItem" id="' + file.id + '">' +
  124. '<img />' +
  125. '</div>' +
  126. //'<div class="info">' + file.name + '</div>' +
  127. '</dd>'
  128. ),
  129. $btns = $('<div class="file-panel">' +
  130. '<span class="cancel"></span>' +
  131. '</div>').appendTo($li),
  132. $img = $li.find('img');
  133. var $list = $("#fileList");
  134. if($len == 1) {
  135. $list.find("dd").eq(0).after($li)
  136. } else if($len == 2) {
  137. $list.find("dd").eq(1).after($li)
  138. } else {
  139. $list.prepend($li);
  140. }
  141. // 创建缩略图
  142. // 如果为非图片文件,可以不用调用此方法。
  143. // thumbnailWidth x thumbnailHeight 为 100 x 100
  144. uploader.makeThumb(file, function(error, src) {
  145. if(error) {
  146. $img.replaceWith('<span>不能预览</span>');
  147. return;
  148. }
  149. $img.attr('src', src);
  150. }, 1, 1);
  151. /*$li.on('mouseenter', function() {
  152. $btns.stop().animate({
  153. height: 30
  154. });
  155. });
  156. $li.on('mouseleave', function() {
  157. $btns.stop().animate({
  158. height: 0
  159. });
  160. });*/
  161. });
  162. uploader.onError = function(code) {
  163. console.log(code)
  164. $.MsgBox.Alert('提示', '请上传jpg、jpeg、png格式的图片,大小不超过2M')
  165. };
  166. uploader.on('uploadSuccess', function(file, data) {
  167. if(data.success) {
  168. uploader.removeFile(fileId);
  169. var cacheImageKey = temp.push(data.data[0].cacheKey);
  170. }else{
  171. $.MsgBox.Alert('提示', '只支持jpeg/jpg/png格式的图片');
  172. }
  173. });
  174. /*删除图片*/
  175. $("#fileList").on("click", ".cancel", function() {
  176. var flag = $(this).attr("flag");
  177. var oNum = $(this).parents("dd").index();
  178. if(flag == 1) {
  179. array.splice(oNum, 1);
  180. } else {
  181. temp.splice(oNum, 1);
  182. }
  183. $(this).parent().parent().remove();
  184. var $len = $("#fileList").find("img").length;
  185. if($len != 2) {
  186. $("#fileList").append("<dd></dd>")
  187. }
  188. });
  189. /*资源名称*/
  190. $("#resourceName").bind({
  191. focus: function() {
  192. $("#resourceNamePrompt").show();
  193. },
  194. blur: function() {
  195. $("#resourceNamePrompt").hide();
  196. },
  197. keyup: function() {
  198. if($(this).val().length > 30) {
  199. $(this).val($(this).val().substr(0, 30));
  200. }
  201. }
  202. })
  203. /*关键词*/
  204. $("#keywordName").bind({
  205. focus: function() {
  206. $("#keywordPrompt").show().text('最多可添加5个关键词,每个关键词15字以内');
  207. },
  208. blur: function() {
  209. $("#keywordPrompt").text('');
  210. },
  211. keyup: function() {
  212. var ti=$(this).val();
  213. hbur=ti;
  214. var lNum=$.trim($(this).val()).length;
  215. console.log(lNum);
  216. if(lNum > 15) {
  217. $(this).val($(this).val().substr(0, 15));
  218. } else if(0 < lNum&& lNum < 15) {
  219. $("#addKeyword").show();
  220. setTimeout(function(){
  221. if( ti===hbur && ti!== hburEnd) {
  222. var tt=ti;
  223. hburEnd=tt;
  224. $.ajax({
  225. "url": "/ajax/dataDict/qaHotKey",
  226. "type": "GET",
  227. "success": function(data) {
  228. console.log(data);
  229. if(data.success) {
  230. if(hburEnd == tt){
  231. if(data.data.length==0) {
  232. $("#keyList").addClass("displayNone");
  233. $("#keyList ul").html("");
  234. }else{
  235. $("#keyList").removeClass("displayNone");
  236. var oSr="";
  237. for(var i=0;i<Math.min(data.data.length,5);i++) {
  238. oSr+='<li><p class="h2Font">'+data.data[i].caption+'</p></li>'
  239. }
  240. $("#keyList ul").html(oSr);
  241. }
  242. }
  243. }else {
  244. $("#keyList ul").html("");
  245. }
  246. },
  247. "data": {
  248. "key":$('#keywordName').val()
  249. },
  250. dataType: "json",
  251. 'error':function() {
  252. $.MsgBox.Alert('提示', '服务器连接超时!');
  253. }
  254. });
  255. }
  256. },500)
  257. }else if(lNum == 0){
  258. $("#addKeyword").hide();
  259. $("#keyList ul").html("");
  260. }
  261. }
  262. });
  263. $("#keyList ul").on("click","li",function(){
  264. keyWord($(this).find("p").text());
  265. $("#keyList ul").html("");
  266. $("#keyList").addClass("displayNone");
  267. $("#addKeyword").hide();
  268. })
  269. /*添加关键词*/
  270. $("#addKeyword").click(function() {
  271. keyWord($("#keywordName").val());
  272. })
  273. function keyWord(atl) {
  274. var oKeywordName =$.trim(atl);
  275. var keywordListLength = $("#keywordList").find("li");
  276. if(oKeywordName.length == 0) {
  277. $("#keywordPrompt").text('关键词输入不能为空');
  278. return;
  279. }
  280. for(var i = 0; i < keywordListLength.length; i++) {
  281. if(oKeywordName == keywordListLength.find("p").eq(i).text()) {
  282. $("#keywordPrompt").text('该关键词已存在');
  283. return;
  284. }
  285. }
  286. $("#keyList ul").html("");
  287. $("#addKeyword").hide();
  288. var oStr = '<li><p class="h2Font">' + oKeywordName + '</p><div class="closeThis"></div></li>'
  289. $("#keywordList").append(oStr);
  290. $("#keywordName").val("");
  291. if((keywordListLength.length + 1) == 5) {
  292. $("#keywordHide").hide();
  293. $("#keyList").css("border-top","none");
  294. }
  295. }
  296. /*删除关键词*/
  297. $("#keywordList").on("click", ".closeThis", function() {
  298. $(this).parent().remove();
  299. var keywordListLength = $("#keywordList").find("li");
  300. if(keywordListLength.length < 5) {
  301. $("#keywordHide").show();
  302. $("#keyList").css("border-top","1px solid #E5E5E5");
  303. }
  304. });
  305. /*应用用途*/
  306. $("#application").bind({
  307. focus: function() {
  308. $("#applicationPrompt").show();
  309. },
  310. blur: function() {
  311. $("#applicationPrompt").hide();
  312. },
  313. keyup: function() {
  314. if($(this).val().length > 50) {
  315. $(this).val($(this).val().substr(0, 50));
  316. }
  317. }
  318. })
  319. /*厂商型号*/
  320. $("#modelNumber").bind({
  321. focus: function() {
  322. $("#model").show();
  323. },
  324. blur: function() {
  325. $("#model").hide();
  326. },
  327. keyup: function() {
  328. if($(this).val().length > 50) {
  329. $(this).val($(this).val().substr(0, 50));
  330. }
  331. }
  332. });
  333. /*性能参数*/
  334. limitObj("#performancePa",200)
  335. /*合作备注*/
  336. limitObj("#remarkContent",200)
  337. /*发布*/
  338. $(".goFabu").click(function() {
  339. var oYes = term();
  340. if(oYes == 0) {
  341. return;
  342. }
  343. $.MsgBox.Confirm("提示", "确认发布该资源?", ajsPost);
  344. })
  345. /*预览*/
  346. $("#oPreview").click(function() {
  347. var oYes = term();
  348. if(oYes == 0) {
  349. return;
  350. }
  351. ajsPost("/ajax/resource/orgDraft", 1);
  352. })
  353. /*存草稿*/
  354. $("#oDraft").click(function() {
  355. var oYes = term();
  356. if(oYes == 0) {
  357. return;
  358. }
  359. ajsPost("/ajax/resource/orgDraft", 2);
  360. })
  361. /*删除*/
  362. $("#operateBlocko").on("click", ".deleteResource", function() {
  363. $.MsgBox.Confirm("提示", "确认删除该资源?", deleResource);
  364. })
  365. /*删除函数*/
  366. function deleResource() {
  367. $.ajax({
  368. "url": "/ajax/resource/delete",
  369. "type": "POST",
  370. "success": function(data) {
  371. console.log(data)
  372. if(data.success) {
  373. location.href = "resourceList.html"
  374. }
  375. },
  376. "data": {
  377. "resourceId": resourceId
  378. },
  379. "beforeSend": function() { /*console.log(this.data)*/ },
  380. "contentType": "application/x-www-form-urlencoded",
  381. dataType: "json"
  382. });
  383. }
  384. /*条件是否匹配*/
  385. function term() {
  386. var $len = $("#fileList").find("img").length;
  387. var reName = $("#resourceName").val();
  388. var oIndustry = $("#application").val();
  389. var oLen=$("#expertli").find(".selectAdd").length
  390. if($len == 0) {
  391. $.MsgBox.Alert('提示', '请上传资源图片。');
  392. return 0;
  393. }
  394. if(reName == "") {
  395. $.MsgBox.Alert('提示', '请输入资源名称。');
  396. return 0;
  397. }
  398. if(oIndustry == "") {
  399. $.MsgBox.Alert('提示', '请输入应用用途。');
  400. return 0;
  401. }
  402. if(oLen==0) {
  403. $.MsgBox.Alert('提示', '至少选择一个负责人');
  404. return 0;
  405. }
  406. }
  407. /*发布函数*/
  408. function ajsPost(pa1, pa2) {
  409. var oUrl = "/ajax/resource/orgSave";
  410. if(pa1) {
  411. oUrl = pa1
  412. }
  413. var $data = {};
  414. if(resourceId) {
  415. $data.resourceId = resourceId;
  416. }
  417. $data.orgId = orgId;
  418. $data.resourceName = $("#resourceName").val(); //资源名字
  419. $data.cooperationNotes = $("#remarkContent").val(); //合作备注
  420. $data.subject = captiureSubInd("keywordList p");
  421. console.log($data.subject);
  422. $data.supportedServices = $("#application").val();
  423. $data.spec = $("#modelNumber").val();
  424. $data.parameter = $("#performancePa").val();
  425. $data.descp = ue.getContent();
  426. $data.fns = temp;
  427. $data.imageIds = array;
  428. $data.professorIds=oProfessor;
  429. //$data.imageIds:资源图片ID NULL 字符串数组
  430. console.log(temp);
  431. $.ajax({
  432. "url": oUrl,
  433. "type": "POST",
  434. "success": function(data) {
  435. console.log(data)
  436. if(data.success) {
  437. if(pa2 == 1) {
  438. resourceId = data.data;
  439. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  440. window.open("../resourcePreview.html?resourceId=" + data.data);
  441. getRecourceMe();
  442. //弹出预览
  443. } else if(pa2 == 2) {
  444. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  445. resourceId = data.data;
  446. $.MsgBox.Alert('提示', '资源已保存草稿。');
  447. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  448. getRecourceMe();
  449. } else {
  450. $.MsgBox.Alert('提示', '资源发布成功!');
  451. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  452. location.href = "resourceList.html"
  453. }
  454. }else {
  455. if(data.code==90) {
  456. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  457. }
  458. }
  459. },
  460. "data": $data,
  461. "beforeSend": function() { /*console.log(this.data)*/ },
  462. "contentType": "application/x-www-form-urlencoded",
  463. "traditional": true,
  464. dataType: "json"
  465. });
  466. }
  467. function captiureSubInd(subIndu) {
  468. var industrys = $("#" + subIndu + "");
  469. var industryAll = "";
  470. if(industrys.size() > 0) {
  471. for(var i = 0; i < industrys.size(); i++) {
  472. industryAll += industrys[i].innerText;
  473. industryAll += ',';
  474. };
  475. industryAll = industryAll.substring(0, industryAll.length - 1);
  476. }
  477. return industryAll;
  478. }
  479. function UnauthorizedUser() {
  480. $.ajax({
  481. url: "/ajax/professor/qaOrgAuth",
  482. type: "GET",
  483. timeout: 10000,
  484. dataType: "json",
  485. async:"false",
  486. data: {
  487. "orgId": orgId,
  488. "orgAuth": 1
  489. },
  490. success: function(data, textState) {
  491. if(data.success) {
  492. console.log(data);
  493. unauthUser(data.data);
  494. }
  495. },
  496. error: function(XMLHttpRequest, textStats, errorThrown) {
  497. $.MsgBox.Alert('提示', '服务器请求失败')
  498. }
  499. })
  500. }
  501. UnauthorizedUser();
  502. function unauthUser($res) {
  503. if(resourceId) {
  504. selUse();
  505. }
  506. var osting=""
  507. for(var i = 0; i < $res.length; i++) {
  508. var img;
  509. var styC="";
  510. var oClass = autho($res[i].authType, $res[i].orgAuth, $res[i].authStatus);
  511. var oTitle="";
  512. if(!resourceId) {
  513. if(i<5) {
  514. styC="selectAdd";
  515. oProfessor.push($res[i].id);
  516. }
  517. }
  518. if($res[i].title) {
  519. oTitle=$res[i].title;
  520. }else{
  521. if($res[i].office) {
  522. oTitle=$res[i].office;
  523. }
  524. }
  525. if($res[i].hasHeadImage) {
  526. img = "/images/head/" + $res[i].id + "_l.jpg";
  527. } else {
  528. img = "../images/default-photo.jpg"
  529. }
  530. var oSt = '<li class="flexCenter" style="cursor:pointer;" id="'+$res[i].id+'">'
  531. oSt += '<div class="madiaHead useHead" id="userimg" style="background-image: url('+img+');"></div>'
  532. oSt += '<div class = "madiaInfo">'
  533. oSt += '<p class = "ellipsisSty">'
  534. oSt += '<span class = "h1Font" id="name">'+$res[i].name+'</span><em class="authicon '+oClass.sty+'" title="'+oClass.title+'"></em >'
  535. oSt += '</p>'
  536. oSt += '<p class="h2Font ellipsisSty">'+oTitle+'</p>'
  537. oSt += '</div>'
  538. oSt += '<div class="selectNull '+styC+'" flag=1></div>'
  539. oSt += '</li>'
  540. osting+=oSt;
  541. }
  542. $("#expertli").html(osting);
  543. }
  544. /*选择用户*/
  545. $("#expertli").on("click","li",function(){
  546. var userL=$("#expertli").find(".selectAdd").length;
  547. var oSel=$(this).find(".selectAdd").length;
  548. var oId=$(this).attr("id");
  549. $("#linkman").text("");
  550. if(oSel == 0) {
  551. if(userL == 5) {
  552. $("#linkman").text("最多可选5个负责人");
  553. return;
  554. }
  555. $(this).find('[flag]').addClass("selectAdd");
  556. oProfessor.push(oId);
  557. } else {
  558. $(this).find('[flag]').removeClass("selectAdd");
  559. for(var i=0;i<oProfessor.length;i++) {
  560. if(oId==oProfessor[i]) {
  561. oProfessor.splice(i, 1);
  562. }
  563. }
  564. }
  565. });
  566. function selUse() {
  567. $.ajax({
  568. url: "/ajax/resource/qaLinkman",
  569. type: "GET",
  570. timeout: 10000,
  571. dataType: "json",
  572. async:true,
  573. data: {
  574. "resourceId": resourceId,
  575. },
  576. success: function(data, textState) {
  577. console.log(data)
  578. if(data.success) {
  579. var arr=[];
  580. var arr1=[];
  581. var oLength=$("#expertli").find("li");
  582. for(var i=0;i<data.data.length;i++) {
  583. arr1.push(data.data[i].professorId);
  584. }
  585. for(var i=0;i<oLength.length;i++) {
  586. arr.push(oLength.eq(i).attr("id"));
  587. }
  588. for(var i=0;i<arr1.length;i++) {
  589. oProfessor.push(arr1[i]);
  590. oLength.eq(arr.indexOf(arr1[i])).find("[flag]").addClass("selectAdd")
  591. }
  592. }
  593. },
  594. error: function(XMLHttpRequest, textStats, errorThrown) {
  595. $.MsgBox.Alert('提示', '服务器请求失败')
  596. }
  597. })
  598. }
  599. })