portal html css js resource

resourceIssue.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. $("#application").bind({
  225. focus: function() {
  226. $("#applicationPrompt").show();
  227. },
  228. blur: function() {
  229. $("#applicationPrompt").hide();
  230. },
  231. keyup: function() {
  232. if($(this).val().length > 250) {
  233. $(this).val($(this).val().substr(0, 250));
  234. }
  235. }
  236. })
  237. /*厂商型号*/
  238. $("#modelNumber").bind({
  239. focus: function() {
  240. $("#model").show();
  241. },
  242. blur: function() {
  243. $("#model").hide();
  244. },
  245. keyup: function() {
  246. if($(this).val().length > 50) {
  247. $(this).val($(this).val().substr(0, 50));
  248. }
  249. }
  250. });
  251. /*性能参数*/
  252. limitObj("#performancePa",1000)
  253. /*合作备注*/
  254. limitObj("#remarkContent",1000)
  255. /*发布*/
  256. $(".goFabu").click(function() {
  257. if($(this).hasClass("disableLi")){
  258. return;
  259. }
  260. var oYes = term();
  261. if(oYes == 0) {
  262. return;
  263. }
  264. $.MsgBox.Confirm("提示", "确认发布该资源?", ajsPost);
  265. })
  266. /*预览*/
  267. $("#oPreview").click(function() {
  268. if($(this).hasClass("disableLi")){
  269. return;
  270. }
  271. var oYes = term();
  272. if(oYes == 0) {
  273. return;
  274. }
  275. ajsPost("/ajax/resource/orgDraft", 1);
  276. })
  277. /*存草稿*/
  278. $("#oDraft").click(function() {
  279. if($(this).hasClass("disableLi")){
  280. return;
  281. }
  282. var oYes = term();
  283. if(oYes == 0) {
  284. return;
  285. }
  286. ajsPost("/ajax/resource/orgDraft", 2);
  287. })
  288. /*删除*/
  289. $("#operateBlocko").on("click", ".deleteResource", function() {
  290. $.MsgBox.Confirm("提示", "确认删除该资源?", deleResource);
  291. })
  292. /*删除函数*/
  293. function deleResource() {
  294. $.ajax({
  295. "url": "/ajax/resource/delete",
  296. "type": "POST",
  297. "success": function(data) {
  298. console.log(data)
  299. if(data.success) {
  300. location.href = "cmp-resourceList.html"
  301. }
  302. },
  303. "data": {
  304. "resourceId": resourceId
  305. },
  306. "beforeSend": function() { /*console.log(this.data)*/ },
  307. "contentType": "application/x-www-form-urlencoded",
  308. dataType: "json"
  309. });
  310. }
  311. /*条件是否匹配*/
  312. function term() {
  313. var $len = $("#fileList").find("img").length;
  314. var reName = $("#resourceName").val();
  315. var oIndustry = $("#application").val();
  316. var oLen=$("#expertli").find(".selectAdd").length
  317. if($len == 0) {
  318. $.MsgBox.Alert('提示', '请上传资源图片。');
  319. return 0;
  320. }
  321. if(reName == "") {
  322. $.MsgBox.Alert('提示', '请输入资源名称。');
  323. return 0;
  324. }
  325. if(oIndustry == "") {
  326. $.MsgBox.Alert('提示', '请输入应用用途。');
  327. return 0;
  328. }
  329. if(oLen==0) {
  330. $.MsgBox.Alert('提示', '至少选择一个负责人');
  331. return 0;
  332. }
  333. }
  334. /*发布函数*/
  335. function ajsPost(pa1, pa2) {
  336. var industrys = $("#keyWordlist li");
  337. var industryAll = "";
  338. if(industrys.size() > 0) {
  339. for(var i = 0; i < industrys.size(); i++) {
  340. industryAll += industrys[i].innerText.trim();
  341. industryAll += ',';
  342. };
  343. industryAll = industryAll.substring(0, industryAll.length - 1);
  344. }
  345. $(".operateBlock").find("li").addClass("disableLi");
  346. var oUrl = "/ajax/resource/orgSave";
  347. if(pa1) {
  348. oUrl = pa1
  349. }
  350. var $data = {};
  351. if(resourceId) {
  352. $data.resourceId = resourceId;
  353. }
  354. $data.orgId = orgId;
  355. $data.resourceName = $("#resourceName").val(); //资源名字
  356. $data.cooperationNotes = $("#remarkContent").val(); //合作备注
  357. $data.subject = industryAll;
  358. console.log($data.subject);
  359. $data.supportedServices = $("#application").val();
  360. $data.spec = $("#modelNumber").val();
  361. $data.parameter = $("#performancePa").val();
  362. $data.descp = ue.getContent();
  363. $data.fns = temp;
  364. $data.imageIds = array;
  365. $data.professorIds=oProfessor;
  366. //$data.imageIds:资源图片ID NULL 字符串数组
  367. console.log(temp);
  368. $.ajax({
  369. "url": oUrl,
  370. "type": "POST",
  371. "complete":function(){
  372. $(".operateBlock").find("li").removeClass("disableLi");
  373. },
  374. "success": function(data) {
  375. console.log(data)
  376. if(data.success) {
  377. if(pa2 == 1) {
  378. resourceId = data.data;
  379. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  380. window.open("../resourcePreview.html?resourceId=" + data.data);
  381. getRecourceMe();
  382. //弹出预览
  383. } else if(pa2 == 2) {
  384. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  385. resourceId = data.data;
  386. $.MsgBox.Alert('提示', '资源已保存草稿。');
  387. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  388. getRecourceMe();
  389. } else {
  390. $.MsgBox.Alert('提示', '资源发布成功!');
  391. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  392. location.href = "cmp-resourceList.html"
  393. }
  394. }else {
  395. if(data.code==90) {
  396. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  397. }
  398. }
  399. },
  400. "data": $data,
  401. "beforeSend": function() { /*console.log(this.data)*/ },
  402. "contentType": "application/x-www-form-urlencoded",
  403. "traditional": true,
  404. dataType: "json"
  405. });
  406. }
  407. function UnauthorizedUser() {
  408. $.ajax({
  409. url: "/ajax/professor/qaOrgAuth",
  410. type: "GET",
  411. timeout: 10000,
  412. dataType: "json",
  413. async:"false",
  414. data: {
  415. "orgId": orgId,
  416. "orgAuth": 1
  417. },
  418. success: function(data, textState) {
  419. if(data.success) {
  420. console.log(data);
  421. unauthUser(data.data);
  422. }
  423. },
  424. error: function(XMLHttpRequest, textStats, errorThrown) {
  425. $.MsgBox.Alert('提示', '服务器请求失败')
  426. }
  427. })
  428. }
  429. UnauthorizedUser();
  430. function unauthUser($res) {
  431. if(resourceId) {
  432. selUse();
  433. }
  434. var osting=""
  435. for(var i = 0; i < $res.length; i++) {
  436. var img;
  437. //var styC="";
  438. var oClass = autho($res[i].authType, $res[i].orgAuth, $res[i].authStatus);
  439. var oTitle="";
  440. if(!resourceId) {
  441. /*if(i<5) {
  442. styC="selectAdd";
  443. oProfessor.push($res[i].id);
  444. }*/
  445. }
  446. if($res[i].title) {
  447. oTitle=$res[i].title;
  448. }else{
  449. if($res[i].office) {
  450. oTitle=$res[i].office;
  451. }
  452. }
  453. if($res[i].hasHeadImage) {
  454. img = "/images/head/" + $res[i].id + "_l.jpg";
  455. } else {
  456. img = "../images/default-photo.jpg"
  457. }
  458. var oSt = '<li class="flexCenter" style="cursor:pointer;" id="'+$res[i].id+'">'
  459. oSt += '<div class="madiaHead useHead" id="userimg" style="background-image: url('+img+');"></div>'
  460. oSt += '<div class = "madiaInfo">'
  461. oSt += '<p class = "ellipsisSty">'
  462. oSt += '<span class = "h1Font" id="name">'+$res[i].name+'</span><em class="authicon '+oClass.sty+'" title="'+oClass.title+'"></em >'
  463. oSt += '</p>'
  464. oSt += '<p class="h2Font ellipsisSty">'+oTitle+'</p>'
  465. oSt += '</div>'
  466. oSt += '<div class="selectNull " flag=1></div>'
  467. oSt += '</li>'
  468. osting+=oSt;
  469. }
  470. $("#expertli").html(osting);
  471. }
  472. /*选择用户*/
  473. $("#expertli").on("click","li",function(){
  474. var userL=$("#expertli").find(".selectAdd").length;
  475. var oSel=$(this).find(".selectAdd").length;
  476. var oId=$(this).attr("id");
  477. $("#linkman").text("");
  478. if(oSel == 0) {
  479. if(userL == 5) {
  480. $("#linkman").text("最多可选5个负责人");
  481. return;
  482. }
  483. $(this).find('[flag]').addClass("selectAdd");
  484. oProfessor.push(oId);
  485. } else {
  486. $(this).find('[flag]').removeClass("selectAdd");
  487. for(var i=0;i<oProfessor.length;i++) {
  488. if(oId==oProfessor[i]) {
  489. oProfessor.splice(i, 1);
  490. }
  491. }
  492. }
  493. });
  494. function selUse() {
  495. $.ajax({
  496. url: "/ajax/resource/qaLinkman",
  497. type: "GET",
  498. timeout: 10000,
  499. dataType: "json",
  500. async:true,
  501. data: {
  502. "resourceId": resourceId,
  503. },
  504. success: function(data, textState) {
  505. console.log(data)
  506. if(data.success) {
  507. var arr=[];
  508. var arr1=[];
  509. var oLength=$("#expertli").find("li");
  510. for(var i=0;i<data.data.length;i++) {
  511. arr1.push(data.data[i].professorId);
  512. }
  513. for(var i=0;i<oLength.length;i++) {
  514. arr.push(oLength.eq(i).attr("id"));
  515. }
  516. for(var i=0;i<arr1.length;i++) {
  517. oProfessor.push(arr1[i]);
  518. oLength.eq(arr.indexOf(arr1[i])).find("[flag]").addClass("selectAdd")
  519. }
  520. }
  521. },
  522. error: function(XMLHttpRequest, textStats, errorThrown) {
  523. $.MsgBox.Alert('提示', '服务器请求失败')
  524. }
  525. })
  526. }
  527. })