portal html css js resource

resourceIssue.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. if($(this).hasClass("disableLi")){
  340. return;
  341. }
  342. var oYes = term();
  343. if(oYes == 0) {
  344. return;
  345. }
  346. $.MsgBox.Confirm("提示", "确认发布该资源?", ajsPost);
  347. })
  348. /*预览*/
  349. $("#oPreview").click(function() {
  350. if($(this).hasClass("disableLi")){
  351. return;
  352. }
  353. var oYes = term();
  354. if(oYes == 0) {
  355. return;
  356. }
  357. ajsPost("/ajax/resource/orgDraft", 1);
  358. })
  359. /*存草稿*/
  360. $("#oDraft").click(function() {
  361. if($(this).hasClass("disableLi")){
  362. return;
  363. }
  364. var oYes = term();
  365. if(oYes == 0) {
  366. return;
  367. }
  368. ajsPost("/ajax/resource/orgDraft", 2);
  369. })
  370. /*删除*/
  371. $("#operateBlocko").on("click", ".deleteResource", function() {
  372. $.MsgBox.Confirm("提示", "确认删除该资源?", deleResource);
  373. })
  374. /*删除函数*/
  375. function deleResource() {
  376. $.ajax({
  377. "url": "/ajax/resource/delete",
  378. "type": "POST",
  379. "success": function(data) {
  380. console.log(data)
  381. if(data.success) {
  382. location.href = "resourceList.html"
  383. }
  384. },
  385. "data": {
  386. "resourceId": resourceId
  387. },
  388. "beforeSend": function() { /*console.log(this.data)*/ },
  389. "contentType": "application/x-www-form-urlencoded",
  390. dataType: "json"
  391. });
  392. }
  393. /*条件是否匹配*/
  394. function term() {
  395. var $len = $("#fileList").find("img").length;
  396. var reName = $("#resourceName").val();
  397. var oIndustry = $("#application").val();
  398. var oLen=$("#expertli").find(".selectAdd").length
  399. if($len == 0) {
  400. $.MsgBox.Alert('提示', '请上传资源图片。');
  401. return 0;
  402. }
  403. if(reName == "") {
  404. $.MsgBox.Alert('提示', '请输入资源名称。');
  405. return 0;
  406. }
  407. if(oIndustry == "") {
  408. $.MsgBox.Alert('提示', '请输入应用用途。');
  409. return 0;
  410. }
  411. if(oLen==0) {
  412. $.MsgBox.Alert('提示', '至少选择一个负责人');
  413. return 0;
  414. }
  415. }
  416. /*发布函数*/
  417. function ajsPost(pa1, pa2) {
  418. $(".operateBlock").find("li").addClass("disableLi");
  419. var oUrl = "/ajax/resource/orgSave";
  420. if(pa1) {
  421. oUrl = pa1
  422. }
  423. var $data = {};
  424. if(resourceId) {
  425. $data.resourceId = resourceId;
  426. }
  427. $data.orgId = orgId;
  428. $data.resourceName = $("#resourceName").val(); //资源名字
  429. $data.cooperationNotes = $("#remarkContent").val(); //合作备注
  430. $data.subject = captiureSubInd("keywordList p");
  431. console.log($data.subject);
  432. $data.supportedServices = $("#application").val();
  433. $data.spec = $("#modelNumber").val();
  434. $data.parameter = $("#performancePa").val();
  435. $data.descp = ue.getContent();
  436. $data.fns = temp;
  437. $data.imageIds = array;
  438. $data.professorIds=oProfessor;
  439. //$data.imageIds:资源图片ID NULL 字符串数组
  440. console.log(temp);
  441. $.ajax({
  442. "url": oUrl,
  443. "type": "POST",
  444. "complete":function(){
  445. $(".operateBlock").find("li").removeClass("disableLi");
  446. },
  447. "success": function(data) {
  448. console.log(data)
  449. if(data.success) {
  450. if(pa2 == 1) {
  451. resourceId = data.data;
  452. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  453. window.open("../resourcePreview.html?resourceId=" + data.data);
  454. getRecourceMe();
  455. //弹出预览
  456. } else if(pa2 == 2) {
  457. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  458. resourceId = data.data;
  459. $.MsgBox.Alert('提示', '资源已保存草稿。');
  460. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  461. getRecourceMe();
  462. } else {
  463. $.MsgBox.Alert('提示', '资源发布成功!');
  464. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  465. location.href = "resourceList.html"
  466. }
  467. }else {
  468. if(data.code==90) {
  469. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  470. }
  471. }
  472. },
  473. "data": $data,
  474. "beforeSend": function() { /*console.log(this.data)*/ },
  475. "contentType": "application/x-www-form-urlencoded",
  476. "traditional": true,
  477. dataType: "json"
  478. });
  479. }
  480. function captiureSubInd(subIndu) {
  481. var industrys = $("#" + subIndu + "");
  482. var industryAll = "";
  483. if(industrys.size() > 0) {
  484. for(var i = 0; i < industrys.size(); i++) {
  485. industryAll += industrys[i].innerText;
  486. industryAll += ',';
  487. };
  488. industryAll = industryAll.substring(0, industryAll.length - 1);
  489. }
  490. return industryAll;
  491. }
  492. function UnauthorizedUser() {
  493. $.ajax({
  494. url: "/ajax/professor/qaOrgAuth",
  495. type: "GET",
  496. timeout: 10000,
  497. dataType: "json",
  498. async:"false",
  499. data: {
  500. "orgId": orgId,
  501. "orgAuth": 1
  502. },
  503. success: function(data, textState) {
  504. if(data.success) {
  505. console.log(data);
  506. unauthUser(data.data);
  507. }
  508. },
  509. error: function(XMLHttpRequest, textStats, errorThrown) {
  510. $.MsgBox.Alert('提示', '服务器请求失败')
  511. }
  512. })
  513. }
  514. UnauthorizedUser();
  515. function unauthUser($res) {
  516. if(resourceId) {
  517. selUse();
  518. }
  519. var osting=""
  520. for(var i = 0; i < $res.length; i++) {
  521. var img;
  522. //var styC="";
  523. var oClass = autho($res[i].authType, $res[i].orgAuth, $res[i].authStatus);
  524. var oTitle="";
  525. if(!resourceId) {
  526. /*if(i<5) {
  527. styC="selectAdd";
  528. oProfessor.push($res[i].id);
  529. }*/
  530. }
  531. if($res[i].title) {
  532. oTitle=$res[i].title;
  533. }else{
  534. if($res[i].office) {
  535. oTitle=$res[i].office;
  536. }
  537. }
  538. if($res[i].hasHeadImage) {
  539. img = "/images/head/" + $res[i].id + "_l.jpg";
  540. } else {
  541. img = "../images/default-photo.jpg"
  542. }
  543. var oSt = '<li class="flexCenter" style="cursor:pointer;" id="'+$res[i].id+'">'
  544. oSt += '<div class="madiaHead useHead" id="userimg" style="background-image: url('+img+');"></div>'
  545. oSt += '<div class = "madiaInfo">'
  546. oSt += '<p class = "ellipsisSty">'
  547. oSt += '<span class = "h1Font" id="name">'+$res[i].name+'</span><em class="authicon '+oClass.sty+'" title="'+oClass.title+'"></em >'
  548. oSt += '</p>'
  549. oSt += '<p class="h2Font ellipsisSty">'+oTitle+'</p>'
  550. oSt += '</div>'
  551. oSt += '<div class="selectNull " flag=1></div>'
  552. oSt += '</li>'
  553. osting+=oSt;
  554. }
  555. $("#expertli").html(osting);
  556. }
  557. /*选择用户*/
  558. $("#expertli").on("click","li",function(){
  559. var userL=$("#expertli").find(".selectAdd").length;
  560. var oSel=$(this).find(".selectAdd").length;
  561. var oId=$(this).attr("id");
  562. $("#linkman").text("");
  563. if(oSel == 0) {
  564. if(userL == 5) {
  565. $("#linkman").text("最多可选5个负责人");
  566. return;
  567. }
  568. $(this).find('[flag]').addClass("selectAdd");
  569. oProfessor.push(oId);
  570. } else {
  571. $(this).find('[flag]').removeClass("selectAdd");
  572. for(var i=0;i<oProfessor.length;i++) {
  573. if(oId==oProfessor[i]) {
  574. oProfessor.splice(i, 1);
  575. }
  576. }
  577. }
  578. });
  579. function selUse() {
  580. $.ajax({
  581. url: "/ajax/resource/qaLinkman",
  582. type: "GET",
  583. timeout: 10000,
  584. dataType: "json",
  585. async:true,
  586. data: {
  587. "resourceId": resourceId,
  588. },
  589. success: function(data, textState) {
  590. console.log(data)
  591. if(data.success) {
  592. var arr=[];
  593. var arr1=[];
  594. var oLength=$("#expertli").find("li");
  595. for(var i=0;i<data.data.length;i++) {
  596. arr1.push(data.data[i].professorId);
  597. }
  598. for(var i=0;i<oLength.length;i++) {
  599. arr.push(oLength.eq(i).attr("id"));
  600. }
  601. for(var i=0;i<arr1.length;i++) {
  602. oProfessor.push(arr1[i]);
  603. oLength.eq(arr.indexOf(arr1[i])).find("[flag]").addClass("selectAdd")
  604. }
  605. }
  606. },
  607. error: function(XMLHttpRequest, textStats, errorThrown) {
  608. $.MsgBox.Alert('提示', '服务器请求失败')
  609. }
  610. })
  611. }
  612. })