portal html css js resource

resourceIssue.js 14KB

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