Browse Source

企业资源发布

jack 7 years ago
parent
commit
36e0efbc1c
3 changed files with 553 additions and 8 deletions
  1. 526 0
      cmp-portal/js/resourceIssue.js
  2. 25 4
      cmp-portal/resourceIssue.html
  3. 2 4
      js/resourceIssue.js

+ 526 - 0
cmp-portal/js/resourceIssue.js

@ -0,0 +1,526 @@
1
$(document).ready(function() {
2
	var resourceId = GetQueryString("resourceId");
3
	if(resourceId) {
4
		$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
5
		getRecourceMe();
6
	}
7
	//loginStatus(); //判断个人是否登录
8
	var userid = $.cookie("userid");
9
	var temp = [];
10
	var array = [];
11
	ue = UE.getEditor('editor', {});
12
	/*获取资源信息*/
13
	function getRecourceMe() {
14
		$.ajax({
15
			"url": "/ajax/resource/queryOne",
16
			"type": "GET",
17
			"success": function(data) {
18
				console.log(data);
19
				if(data.success) {
20
					resourceHtml(data.data);
21
				}
22
			},
23
			"data": {
24
				"resourceId": resourceId
25
			},
26
			dataType: "json",
27
			'error': function() {
28
				$.MsgBox.Alert('提示', '服务器连接超时!');
29
			}
30
		});
31
	}
32
	/*处理资源html代码*/
33
	function resourceHtml($da) {
34
		$("#resourceName").val($da.resourceName); //名字
35
		$("#application").val($da.supportedServices); //应用用途
36
		if($da.editProfessor.orgName) { //所属机构
37
			$("#organizationName").val($da.editProfessor.orgName);
38
		}
39
		if($da.spec) { //厂商型号
40
			$("#modelNumber").val($da.spec);
41
		}
42
		if($da.parameter) { //性能参数
43
			$("#performancePa").val($da.parameter);
44
		}
45
		if($da.cooperationNotes) { //合作备注
46
			$("#remarkContent").val($da.cooperationNotes);
47
		}
48
		if($da.subject) {
49
			var oSub = $da.subject.split(",");
50
			var oSt = "";
51
			for(var i = 0; i < oSub.length; i++) {
52
				oSt += '<li><p class="h2Font">' + oSub[i] + '</p><div class="closeThis"></div></li>'
53
			}
54
			$("#keywordList").html(oSt);
55
		} else {
56
			$("#keywordList").html("");
57
		}
58
		if($da.descp) { //编辑器
59
			ue.ready(function() {
60
				ue.setContent($da.descp);
61
			});
62

63
		}
64
		if($da.images.length) {
65
			var arr = [];
66
			for(var i = 0; i < $da.images.length; i++) {
67
				var oString = '<dd>' +
68
					'<div class="imgItem">' +
69
					'<img src="' + "/data/resource/" + $da.images[i].imageSrc + '"/>' +
70
					'</div>' +
71
					'<div class="file-panel">' +
72
					'<span class="cancel" flag=1></span>' +
73
					'</div>' +
74
					'</dd>'
75
				arr[i] = oString;
76
				array[i] = $da.images[i].imageId;
77
			}
78
			$("#fileList dd").eq(2).remove();
79
			if($da.images.length == 1) {
80
				$("#fileList").prepend(arr[0]);
81
			} else if($da.images.length == 2) {
82
				$("#fileList dd").eq(1).remove();
83
				$("#fileList").prepend(arr[1]);
84
				$("#fileList").prepend(arr[0]);
85
			} else if($da.images.length == 3) {
86
				$("#fileList dd").eq(1).remove();
87
				$("#fileList").prepend(arr[2]);
88
				$("#fileList").prepend(arr[1]);
89
				$("#fileList").prepend(arr[0]);
90
			}
91

92
		}
93
	}
94
	var uploader = WebUploader.create({
95
		auto: true,
96
		fileNumLimit: 3,
97
		swf: '../js/webuploader/Uploader.swf',
98
		server: '../ajax/cachedFileUpload',
99
		fileSingleSizeLimit: 2 * 1024 * 1024,
100
		pick: {
101
			id: "#filePicker",
102
			multiple: false
103
		},
104
		accept: {
105
			title: 'Images',
106
			extensions: 'jpg,jpeg,png',
107
			mimeTypes: 'image/jpg,image/png'
108
		}
109

110
	});
111

112
	// 当有文件添加进来的时候
113
	uploader.on('fileQueued', function(file) {
114
		fileId = file.id;
115
		var $len = $("#fileList").find("img").length;
116
		if($len == 0 || $len == 1) {
117
			var oRemove = $("#fileList").find("dd");
118
			oRemove.eq(oRemove.length - 1).remove();
119
		}
120
		var $li = $(
121
				'<dd>' +
122
				'<div class="imgItem" id="' + file.id + '">' +
123
				'<img />' +
124
				'</div>' +
125
				//'<div class="info">' + file.name + '</div>' +
126
				'</dd>'
127
			),
128
			$btns = $('<div class="file-panel">' +
129
				'<span class="cancel"></span>' +
130
				'</div>').appendTo($li),
131
			$img = $li.find('img');
132
		var $list = $("#fileList");
133
		if($len == 1) {
134
			$list.find("dd").eq(0).after($li)
135
		} else if($len == 2) {
136
			$list.find("dd").eq(1).after($li)
137
		} else {
138
			$list.prepend($li);
139
		}
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

157
		$li.on('mouseleave', function() {
158
			$btns.stop().animate({
159
				height: 0
160
			});
161
		});*/
162

163
	});
164
	uploader.onError = function(code) {
165
		console.log(code)
166
		$.MsgBox.Alert('提示', '请上传jpg、png格式的图片,大小不超过2M')
167
	};
168
	uploader.on('uploadSuccess', function(file, data) {
169
		uploader.removeFile(fileId);
170
		var cacheImageKey = temp.push(data.data[0].cacheKey);
171
	});
172
	/*删除图片*/
173
	$("#fileList").on("click", ".cancel", function() {
174
		var flag = $(this).attr("flag");
175
		var oNum = $(this).parents("dd").index();
176
		if(flag == 1) {
177
			array.splice(oNum, 1);
178
		} else {
179
			temp.splice(oNum, 1);
180
		}
181
		$(this).parent().parent().remove();
182

183
		var $len = $("#fileList").find("img").length;
184
		if($len != 2) {
185
			$("#fileList").append("<dd></dd>")
186
		}
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();
207
			$("#keyList").show();
208
		},
209
		blur: function() {
210
			$("#keywordPrompt").hide();
211
			setTimeout(function() {
212
				$("#keyList").show();
213
			}, 200)
214
		},
215
		keyup: function() {
216
			if($(this).val().length > 10) {
217
				$(this).val($(this).val().substr(0, 10));
218
			} else if(0 < $(this).val().length < 10) {
219
				$.ajax({
220
					"url": "/ajax/dataDict/qaHotKey",
221
					"type": "GET",
222
					"success": function(data) {
223
						console.log(data);
224
						if(data.success) {
225
							if(data.data == null) {
226
								$("#keyList ul").html("");
227
							} else {
228
								var oSr = "";
229
								for(var i = 0; i < data.data.length; i++) {
230
									oSr += '<li><p class="h2Font">' + data.data[i].name + '</p></li>'
231
								}
232
								$("#department ul").html(oSr);
233
							}
234
						}
235
					},
236
					"data": {
237
						"key": $(this).val(),
238
						rows: 3
239
					},
240
					dataType: "json",
241
					'error': function() {
242
						$.MsgBox.Alert('提示', '服务器连接超时!');
243
					}
244
				});
245
			}
246
		}
247
	})
248
	/*添加关键词*/
249
	$("#addKeyword").click(function() {
250
		var oKeywordName = $("#keywordName").val();
251
		var keywordListLength = $("#keywordList").find("li");
252
		if(oKeywordName.length == 0) {
253
			$.MsgBox.Alert('提示', '关键词输入不能为空');
254
			return;
255
		}
256
		for(var i = 0; i < keywordListLength.length; i++) {
257
			if(oKeywordName == keywordListLength.find("p").eq(i).text()) {
258
				$.MsgBox.Alert('提示', '该关键词已存在');
259
				return;
260
			}
261
		}
262
		var oStr = '<li><p class="h2Font">' + oKeywordName + '</p><div class="closeThis"></div></li>'
263
		$("#keywordList").append(oStr);
264
		$("#keywordName").val("");
265
		if((keywordListLength.length + 1) == 5) {
266
			$("#keywordHide").hide();
267
		}
268
	})
269
	/*删除关键词*/
270
	$("#keywordList").on("click", ".closeThis", function() {
271
		$(this).parent().remove();
272
		var keywordListLength = $("#keywordList").find("li");
273
		if(keywordListLength.length < 5) {
274
			$("#keywordHide").show();
275
		}
276
	});
277
	/*应用用途*/
278
	$("#application").bind({
279
		focus: function() {
280
			$("#applicationPrompt").show();
281
		},
282
		blur: function() {
283
			$("#applicationPrompt").hide();
284
		},
285
		keyup: function() {
286
			if($(this).val().length > 50) {
287
				$(this).val($(this).val().substr(0, 50));
288
			}
289
		}
290

291
	})
292
	/*所属机构*/
293
	$("#organizationName").bind({
294
		focus: function() {
295
			$("#organization").show();
296
			$("#department").show();
297
		},
298
		blur: function() {
299
			$("#organization").hide();
300
			setTimeout(function() {
301
				$("#department").hide();
302
			}, 100)
303
		},
304
		keyup: function() {
305
			if($(this).val().length > 50) {
306
				$(this).val($(this).val().substr(0, 50));
307
			} else if(0 < $(this).val().length < 50) {
308
				$.ajax({
309
					"url": "/ajax/org/querylimit",
310
					"type": "GET",
311
					"success": function(data) {
312
						console.log(data);
313
						if(data.success) {
314
							if(data.data == null) {
315
								$("#department ul").html("");
316
							} else {
317
								addHtml(data.data);
318
							}
319
						}
320
					},
321
					"data": {
322
						name: $(this).val(),
323
						rows: 3
324
					},
325
					dataType: "json",
326
					'error': function() {
327
						$.MsgBox.Alert('提示', '服务器连接超时!');
328
					}
329
				});
330
			}
331
		}
332
	})
333

334
	function addHtml($html) {
335
		var i = 0;
336
		var oSum = "";
337
		for(i in $html) {
338
			var oImg = "";
339
			console.log($html[i].hasOrgLogo)
340
			if($html[i].hasOrgLogo) {
341
				oImg = "/images/org/" + $html[i].id + ".jpg"
342
			} else {
343
				oImg = "../images/default-icon.jpg"
344
			}
345
			oSum += '<li class="orgList"><img src="' + oImg + '" class="floatL" /><p class="h2Font floatL">' + $html[i].name + '</p></li>'
346
		}
347
		$("#department ul").html(oSum);
348
	}
349
	$("#department ul").on("click", "li", function() {
350
		$("#organizationName").val($(this).find("p").text());
351
		$("#department ul").html("");
352
	})
353
	/*厂商型号*/
354
	$("#modelNumber").bind({
355
		focus: function() {
356
			$("#model").show();
357
		},
358
		blur: function() {
359
			$("#model").hide();
360
		},
361
		keyup: function() {
362
			if($(this).val().length > 50) {
363
				$(this).val($(this).val().substr(0, 50));
364
			}
365
		}
366

367
	});
368

369
	function para(sel1, sel2, sel3) {
370
		$(sel1).bind({
371
			focus: function() {
372
				$(sel2).show();
373
			},
374
			blur: function() {
375
				$(sel2).hide();
376
			},
377
			keyup: function(e) {
378
				if($(this).val().length > 200) {
379
					$(this).val($(this).val().substring(0, 200));
380
					e.preventDefault();
381
				}
382
				setTimeout(function() {
383
					$(sel3).text($(sel1).val().length);
384
				}, 1);
385
			}
386

387
		});
388
	}
389
	/*性能参数*/
390
	para("#performancePa", "#performance", "#entry1");
391
	/*合作备注*/
392
	para('#remarkContent', '#remark', '#entry2');
393
	/*发布*/
394
	$(".goFabu").click(function() {
395
		var oYes = term();
396
		if(oYes == 0) {
397
			return;
398
		}
399
		$.MsgBox.Confirm("提示", "确认发布该资源?", ajsPost);
400
	})
401
	/*预览*/
402
	$("#oPreview").click(function() {
403
		var oYes = term();
404
		if(oYes == 0) {
405
			return;
406
		}
407
		ajsPost("/ajax/resource/draft", 1);
408
	})
409
	/*存草稿*/
410
	$("#oDraft").click(function() {
411
		var oYes = term();
412
		if(oYes == 0) {
413
			return;
414
		}
415
		ajsPost("/ajax/resource/draft", 2);
416
	})
417
	/*删除*/
418
	$("#operateBlocko").on("click", ".deleteResource", function() {
419
		$.MsgBox.Confirm("提示", "确认删除该资源?", deleResource);
420
	})
421
	/*删除函数*/
422
	function deleResource() {
423
		$.ajax({
424
			"url": "/ajax/resource/delete",
425
			"type": "POST",
426
			"success": function(data) {
427
				console.log(data)
428
				if(data.success) {
429
					location.href = "resourceList.html"
430
				}
431
			},
432
			"data": {
433
				"resourceId": resourceId
434
			},
435
			"beforeSend": function() { /*console.log(this.data)*/ },
436
			"contentType": "application/x-www-form-urlencoded",
437
			dataType: "json"
438
		});
439
	}
440
	/*条件是否匹配*/
441
	function term() {
442
		var $len = $("#fileList").find("img").length;
443
		var reName = $("#resourceName").val();
444
		var oIndustry = $("#application").val();
445
		if($len == 0) {
446
			$.MsgBox.Alert('提示', '请上传资源图片。');
447
			return 0;
448
		}
449
		if(reName == "") {
450
			$.MsgBox.Alert('提示', '请输入资源名称。');
451
			return 0;
452
		}
453
		if(oIndustry == "") {
454
			$.MsgBox.Alert('提示', '请输入应用用途。');
455
			return 0;
456
		}
457
	}
458
	/*发布函数*/
459
	function ajsPost(pa1, pa2) {
460
		var oUrl = "/ajax/resource/save";
461
		if(pa1) {
462
			oUrl = pa1
463
		}
464
		var $data = {};
465
		if(resourceId) {
466
			$data.resourceId = resourceId;
467
		}
468
		$data.professorId = userid;
469
		$data.resourceName = $("#resourceName").val(); //资源名字
470
		$data.cooperationNotes = $("#remarkContent").val(); //合作备注
471
		$data.subject = captiureSubInd("keywordList p");
472
		console.log($data.subject);
473
		$data.supportedServices = $("#application").val();
474
		$data.orgName = $("#organizationName").val();
475
		$data.spec = $("#modelNumber").val();
476
		$data.parameter = $("#performancePa").val();
477
		$data.descp = ue.getContent();
478
		$data.fns = temp;
479
		$data.imageIds = array;
480
		//$data.imageIds:资源图片ID NULL 字符串数组
481
		console.log(temp);
482
		$.ajax({
483
			"url": oUrl,
484
			"type": "POST",
485
			"success": function(data) {
486
				console.log(data)
487
				if(data.success) {
488
					if(pa2 == 1) {
489
						resourceId = data.data;
490
						$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
491
						window.open("resourcePreview.html?resourceId=" + data.data);
492
						//弹出预览
493
					} else if(pa2 == 2) {
494
						$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
495
						resourceId = data.data;
496
						$.MsgBox.Alert('提示', '资源已保存草稿。');
497
						$("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
498
					} else {
499
						$.MsgBox.Alert('提示', '资源发布成功!');
500
						$("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
501
						location.href = "resourceList.html"
502
					}
503

504
				}
505
			},
506
			"data": $data,
507
			"beforeSend": function() { /*console.log(this.data)*/ },
508
			"contentType": "application/x-www-form-urlencoded",
509
			"traditional": true,
510
			dataType: "json"
511
		});
512
	}
513

514
	function captiureSubInd(subIndu) {
515
		var industrys = $("#" + subIndu + "");
516
		var industryAll = "";
517
		if(industrys.size() > 0) {
518
			for(var i = 0; i < industrys.size(); i++) {
519
				industryAll += industrys[i].innerText;
520
				industryAll += ',';
521
			};
522
			industryAll = industryAll.substring(0, industryAll.length - 1);
523
		}
524
		return industryAll;
525
	}
526
})

+ 25 - 4
cmp-portal/resourceIssue.html

@ -13,6 +13,7 @@
13 13
<script type="text/javascript" src="js/public/jquery-1.11.1.js"></script>
14 14
<style type="text/css">
15 15
	.conItem ul.operateBlock>li{width: 25%;}
16
	.selectAdd{position:absolute; right:30px;top:50%;margin-top:-12px;width:24px; height:24px;background: url(../images/c-sign-on_button_xuanze_hig.png) no-repeat center center;background-size: cover;}
16 17
</style>
17 18
</head>
18 19

@ -160,6 +161,26 @@
160 161
						
161 162
					</ul>
162 163
				</div>
164
				<div class="conItem">
165
					<div class="form-item otherBlock">
166
						<div class="aboutTit">负责人/联系人</div>
167
						<div class="form-result">
168
							<ul class="addexpert" id="expertli">
169
								<li id="usid" data-id="7F26E3C720064AE8A10C7357BBBD239B">
170
									<div class="madiaHead useHead" id="userimg" style="background-image: url(/images/head/7F26E3C720064AE8A10C7357BBBD239B_l.jpg);"></div>
171
									<div class="madiaInfo">
172
										<p class="ellipsisSty">
173
											<span class="h1Font" id="name">李潇远2</span><span class="h2Font" style="margin-left:10px;" id="title"></span>
174
										</p>
175
										<p class="h2Font ellipsisSty" id="orgName">科袖科技</p>
176
									</div>
177
									<div class="selectAdd"></div>
178
								</li>
179
							</ul>
180
						</div>
181
					</div>
182
					
183
				</div>
163 184
			</div>
164 185
		</div>
165 186
	</div>
@ -171,10 +192,10 @@
171 192
<script type="text/javascript"src="js/public/jquery.similar.msgbox.js"></script>
172 193
<script type="text/javascript" src="js/public/common.js"></script>  
173 194
<script type="text/javascript" src="../js/jquery.page.js"></script>
174
<script type="text/javascript" src="js/ueditor/ueditor.config.js"></script>
175
<script type="text/javascript" src="js/ueditor/ueditor.all.js"></script>
176
<script type="text/javascript" src="./js/webuploader/webuploader.js"></script>
177
<script type="text/javascript" src="js/articalIssue.js"></script>
195
<script type="text/javascript" src="../js/ueditor/ueditor.config.js"></script>
196
<script type="text/javascript" src="../js/ueditor/ueditor.all.js"></script>
197
<script type="text/javascript" src="../js/webuploader/webuploader.js"></script>
198
<script type="text/javascript" src="js/resourceIssue.js"></script>
178 199

179 200
</body>
180 201
</html>

+ 2 - 4
js/resourceIssue.js

@ -118,9 +118,7 @@ $(document).ready(function() {
118 118
		if($len == 0 || $len == 1) {
119 119
			var oRemove = $("#fileList").find("dd");
120 120
			oRemove.eq(oRemove.length - 1).remove();
121
		} else if($len == 2) {
122
			$("#uploadDd").hide();
123
		}
121
		} 
124 122
		var $li = $(
125 123
				'<dd>' +
126 124
					'<div class="imgItem" id="' + file.id + '">'+
@ -183,7 +181,7 @@ $(document).ready(function() {
183 181
			temp.splice(oNum,1);
184 182
		}
185 183
		$(this).parent().parent().remove();
186
		$("#uploadDd").show();
184
		
187 185
		var $len = $("#fileList").find("img").length;
188 186
		if($len != 2) {
189 187
			$("#fileList").append("<dd></dd>")