jack 8 年之前
父节点
当前提交
0523667ce8
共有 1 个文件被更改,包括 386 次插入0 次删除
  1. 386 0
      cmp-portal/js/cmp-updateinfo.js

+ 386 - 0
cmp-portal/js/cmp-updateinfo.js

@ -0,0 +1,386 @@
1
$(document).ready(function() {
2
	var id = "05FBD2E6F568461CA7EC378E66C47ABE";
3
	/*企业信息*/
4
	function companyInformation() {
5
		$.ajax({
6
			url: "/ajax/org/" + id,
7
			type: "GET",
8
			timeout: 10000,
9
			dataType: "json",
10
			beforeSend: function() {},
11
			success: function(data, textState) {
12
				if(data.success) {
13
					console.log(data);
14
					var $data = data.data;
15
					$(".h1Font").text($data.name);
16
					if($data.orgUrl) {
17
						$("#inteAddress").val($data.orgUrl);
18
					}
19
					if($data.orgUrl) {
20
						$("#inteAddress").val($data.orgUrl);
21
					}
22
					if($data.forShort) {
23
						$("#businessAbbreviation").val($data.forShort);
24
					}
25
					if($data.foundTime) {
26
						var oTime = timeGeshi($data.foundTime);
27
						$("#createTime").val(oTime);
28
					}
29
					if($data.province) {
30
						$("#oprovince").text($data.province);
31
					}
32
					if($data.city) {
33
						$("#oCity").text($data.city);
34
					}
35
					if($data.descp) {
36
						$("textarea").val($data.descp);
37
					}
38
					if($data.orgSize) {
39

40
						switch($data.orgSize) {
41
							case '1':
42
								$("#qualificationList").find("li").eq(0).addClass("cmpBg listactive");
43
								break;
44
							case '2':
45
								$("#qualificationList").find("li").eq(1).addClass("cmpBg listactive")
46
								break;
47
							case '3':
48
								$("#qualificationList").find("li").eq(2).addClass("cmpBg listactive")
49
								break;
50
							case '4':
51
								$("#qualificationList").find("li").eq(3).addClass("cmpBg listactive")
52
								break;
53
							case '5':
54
								$("#qualificationList").find("li").eq(4).addClass("cmpBg listactive")
55
								break;
56
							default:
57
								$("#qualificationList").find("li").eq(5).addClass("cmpBg listactive")
58
								break;
59
						}
60
					}
61
					if($data.orgType) {
62
						switch($data.orgType) {
63
							case '2':
64
								$("#orgType").find("li").eq(0).addClass("cmpBg listactive");
65
								break;
66
							case '3':
67
								$("#orgType").find("li").eq(1).addClass("cmpBg listactive")
68
								break;
69
							case '4':
70
								$("#orgType").find("li").eq(2).addClass("cmpBg listactive")
71
								break;
72
							case '5':
73
								$("#orgType").find("li").eq(3).addClass("cmpBg listactive")
74
								break;
75
							case '6':
76
								$("#orgType").find("li").eq(4).addClass("cmpBg listactive")
77
								break;
78
							default:
79
								$("#orgType").find("li").eq(5).addClass("cmpBg listactive")
80
								break;
81
						}
82
					}
83
					if($data.industry) {
84
						indu($data.industry, '#industryList')
85
					}
86
					if($data.subject) {
87
						indu($data.subject, '#subjectList')
88
					}
89
					if($data.qualification) {
90
						indu($data.qualification, '.editUlistC ')
91
					}
92
				}
93
			},
94
			error: function(XMLHttpRequest, textStats, errorThrown) {
95
				console.log(XMLHttpRequest)
96
			}
97
		})
98
	}
99
	companyInformation()
100
		/*时间格式*/
101
	function timeGeshi(otm) {
102
		var otme = otm.substring(0, 4) + "-" + otm.substring(4, 6) + "-" + otm.substring(6, 8);
103
		return otme;
104
	}
105
	/*企业简称限制在300字内*/
106
	function limitFont(e) {
107
		var pastedText;
108
		if (window.clipboardData  &&  window.clipboardData.getData)  {  // IE
109
			            
110
			pastedText  = $("textarea").val() +  window.clipboardData.getData('Text');          
111
112
		else  {            
113
			pastedText  = $("textarea").val() +  e.originalEvent.clipboardData.getData('Text'); //e.clipboardData.getData('text/plain');
114
			          
115
		}
116
		$("textarea").val(pastedText.substring(0, 300));
117

118
	}
119
	$("textarea").bind({
120
		paste: function(e) {
121
			limitFont(e);
122
			setTimeout(function() {
123
				$(".limitNum").find("span").text(300 - $("textarea").val().length);
124
			}, 1);
125
			e.preventDefault();
126
		},
127
		cut: function(e) {
128
			setTimeout(function() {
129
				$(".limitNum").find("span").text(300 - $("textarea").val().length);
130
			}, 1);
131
		},
132
		keyup: function(e) {
133
			if($("textarea").val().length > 300) {
134
				$("textarea").val($("textarea").val().substring(0, 300));
135
				e.preventDefault();
136
			}
137
			setTimeout(function() {
138
				$(".limitNum").find("span").text(300 - $("textarea").val().length);
139
			}, 1);
140
		}
141
	});
142
	/*应用行业及领域及企业纸质*/
143
	function indu(oString, oSelector) {
144
		var arr = oString.split(",");
145
		var oArr = new Array();
146
		var i;
147
		for(i in arr) {
148
			oArr.push('<li>' + arr[i] + '<img src="images/con_icon_delete.png" /></li>');
149
		}
150
		console.log(oArr.join(","));
151
		$(oSelector).html(oArr.join(""));
152
	}
153
	/*删除*/
154
	$("body").on("click", "li img", function() {
155
			$(this).parent().remove();
156
		})
157
		/*添加*/
158
	$("button:contains('添加')").click(function() {
159
			var oValue = $(this).parent().siblings(".col-w-10").children("input").val().trim();
160
			var oJudge = $(this).parent().siblings("ul").find("li");
161
			if(!oValue) {
162
				$.MsgBox.Alert('提示', '请先填写内容');
163
				return;
164
			}
165
			if(oValue.length > 10) {
166
				$.MsgBox.Alert('提示', '添加内容不能超过10个字');
167
				return;
168
			}
169
			for(var i = 0; i < oJudge.length; i++) {
170
				if(oValue == oJudge[i].innerText) {
171
					$.MsgBox.Alert('提示', '添加内容不能重复');
172
					return;
173
				}
174
			}
175
			$(this).parent().siblings("ul").append('<li>' + oValue + '<img src="images/con_icon_delete.png" /></li>');
176
			$(this).parent().siblings(".col-w-10").children("input").val("");
177
		})
178
		/*选择单一选项*/
179
	$("#orgType,#qualificationList").on("click", "li", function() {
180
			var oClassName = $(this).addClass("cmpBg listactive").siblings().removeClass("cmpBg listactive");
181
		})
182
		/*保存*/
183
	$("button:contains('保存')").click(function() {
184
			var oBusinessAbbreviation = $("#businessAbbreviation").val().trim();
185
			var oTextArea = $("textarea").val().trim();
186
			var oBusinessType = $("#orgType").find("li.cmpBg.listactive").length;
187
			var oBusinessDimensions = $("#qualificationList").find("li.cmpBg.listactive").length;
188
			var oIndustryNumber = $("#industryList").find("li").length;
189
			var oSubjectNumber = $("#subjectList").find("li").length;
190
			var oEditUlistCNumber = $(".editUlistC ").find("li").length;
191
			if(!oBusinessAbbreviation) {
192
				$.MsgBox.Alert('提示', '企业简称不能为空');
193
				return;
194
			}
195
			if(oBusinessAbbreviation.length > 10) {
196
				$.MsgBox.Alert('提示', '企业简称不能超过10个字');
197
				return;
198
			}
199
			if(!oTextArea) {
200
				$.MsgBox.Alert('提示', '企业简介不能为空');
201
				return;
202
			}
203
			if(oBusinessType == 0) {
204
				$.MsgBox.Alert('提示', '请选择企业类型');
205
				return;
206
			}
207
			if(oIndustryNumber == 0) {
208
				$.MsgBox.Alert('提示', '企业所属行业必填一项');
209
				return;
210
			}
211
			if(oSubjectNumber == 0) {
212
				$.MsgBox.Alert('提示', '企业所属领域必填一项');
213
				return;
214
			}
215
			if(oBusinessDimensions == 0) {
216
				$.MsgBox.Alert('提示', '请选择企业规模');
217
				return;
218
			}
219
			if(oEditUlistCNumber == 0) {
220
				$.MsgBox.Alert('提示', '企业资质必填一项');
221
				return;
222
			}
223
			/*					
224
			fn: 企业logo上传临时文件名 NULL 字符串*/
225
			var tex = $("#orgType").find("li.cmpBg.listactive").text();
226
			var oTextGui = $("#qualificationList").find("li.cmpBg.listactive").text();
227
			var $info = {};
228
			$info.id = id;
229
			$info.forShort = $("#businessAbbreviation").val();
230
			switch(tex) {
231
				case '上市企业':
232
					$info.orgType = 2;
233
					break;
234
				case '国有企业':
235
					$info.orgType = 3;
236
					break;
237
				case '合资企业':
238
					$info.orgType = 4;
239
					break;
240
				case '私人企业':
241
					$info.orgType = 5;
242
					break;
243
				case '外资企业':
244
					$info.orgType = 6;
245
					break;
246
				default:
247
					$info.orgType = 7;
248
					break;
249
			}
250
			switch(oTextGui) {
251
				case '50人以内':
252
					$info.orgSize = 1;
253
					break;
254
				case '50-100人':
255
					$info.orgSize = 2;
256
					break;
257
				case '100-200人':
258
					$info.orgSize = 3;
259
					break;
260
				case '200-500人':
261
					$info.orgSize = 4;
262
					break;
263
				case '500-1000人':
264
					$info.orgSize = 5;
265
					break;
266
				default:
267
					$info.orgSize = 6;
268
					break;
269
			}
270
			if($("#inteAddress").val().trim()) {
271
				$info.orgUrl = $("#inteAddress").val();
272
			}
273
			if($("#oprovince").text() != "请选择企业总部所在省或直辖市") {
274
				$info.province = $("#oprovince").text();
275
			}
276
			if($("#oCity").text() != "请选择企业总部所在城市") {
277
				$info.city = $("#oCity").text();
278
			}
279
			if($("#createTime").val()) {
280
				$info.foundTime = st6($("#createTime").val());
281
			}
282
			$info.descp = $("textarea").val();
283
			$info.industry = oString("#industryList");
284
			$info.subject = oString("#subjectList");
285
			$info.qualification = oString(".editUlistC");
286
			$.ajax({
287
				url: "/ajax/org/update",
288
				type: "POST",
289
				data: $info,
290
				timeout: 10000,
291
				dataType: "json",
292
				beforeSend: function() {},
293
				success: function(data, textState) {
294
					if(data.success) {
295
						alert(11)
296
						companyInformation();
297
					}
298
				},
299
				error: function(XMLHttpRequest, textStats, errorThrown) {
300
					console.log(XMLHttpRequest)
301
				}
302
			})
303
		})
304
		/*应用行业,学术领域,企业纸质生成字符串*/
305
	function oString(sele) {
306
		var len = $(sele).find("li");
307
		var arry = new Array();
308
		for(var i = 0; i < len.length; i++) {
309
			arry.push(len[i].innerText);
310
		}
311
		return arry.join(",");
312
	}
313
	/*时间转换成6位传给后台*/
314
	function st6(osr) {
315
		var tim = osr.substring(0, 4) + osr.substring(5, 7) + osr.substring(8, 10);
316
		return tim;
317
	}
318
	/*企业图片上传*/
319
	var fileId = null;
320
	var cacheImageKey=null;
321
	var uploader = WebUploader.create({
322
		auto: true,
323
		fileNumLimit: 1,
324
		swf: '../js/webuploader/Uploader.swf',
325
		server: '../ajax/cachedFileUpload',
326
		pick: {
327
			id: "#filePicker",
328
			multiple: false
329
		},
330
		accept: {
331
			title: 'Images',
332
			extensions: 'gif,jpg,jpeg,bmp',
333
			mimeTypes: 'image/*'
334
		}
335

336
	});
337

338
	// 当有文件添加进来的时候
339
	uploader.on('fileQueued', function(file) {
340
		fileId = file.id;
341
		var $li = $('<div id="' + file.id + '" class="file-item thumbnail">' +'<img>' +'</div>')
342
		$img = $li.find('img');
343
		var $list = $('#fileList');
344
		// 创建缩略图
345
		// 如果为非图片文件,可以不用调用此方法。
346
		// thumbnailWidth x thumbnailHeight 为 100 x 100
347
		uploader.makeThumb(file, function(error, src) {
348
			if(error) {
349
				$img.replaceWith('<span>不能预览</span>');
350
				return;
351
			}
352

353
		}, 240, 240);
354

355
		//判断上传文件格式
356
		 var fileNameAll = file.name;
357
		    var AllImgExt=".jpg|.jpeg|.gif|.bmp|.png|";
358
		    var extName = fileNameAll.substring(fileNameAll.lastIndexOf(".")).toLowerCase();//(把路径中的所有字母全部转换为小写)
359
	        if(AllImgExt.indexOf(extName+"|")==-1){
360
	            var ErrMsg="该文件类型不允许上传。请上传 "+AllImgExt+" 类型的文件,当前文件类型为"+extName;
361
	            $.MsgBox.Alert('提示',ErrMsg);
362
	            return false;
363
	        }
364

365
	});
366

367
	uploader.on( 'uploadError', function( file ) {
368
		alert(file);
369
    var $li = $( '#'+file.id ),
370
        $error = $li.find('div.error');
371

372
    // 避免重复创建
373
    if ( !$error.length ) {
374
        $error = $('<div class="error"></div>').appendTo( $li );
375
    }
376

377
    $error.text('上传失败');
378
    
379
});
380
	uploader.on('uploadSuccess', function(file, data) {
381
		uploader.removeFile(fileId);
382
		cacheImageKey = data.data[0].cacheKey;
383
		$("#oimg").attr("src", "/images/tmp/" + cacheImageKey);
384
	});
385

386
})