common.js 58.8 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/**
 * [Prompt 公共提示]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-10T14:32:39+0800
 * @param {[string]}	msg  [提示信息]
 * @param {[string]} 	type [类型(失败:danger, 成功success)]
 * @param {[int]} 		time [自动关闭时间(秒), 默认3秒]
 */
var temp_time_out;
function Prompt(msg, type, time, distance, animation_type, location)
{
	if(msg != undefined && msg != '')
	{
		// 是否已存在提示条
		if($('#common-prompt').length > 0)
		{
			clearTimeout(temp_time_out);
		}

		// 提示信息添加
		$('#common-prompt').remove();
		if((type || null) == null) type = 'danger';
		if((animation_type || null) == null) animation_type = 'top';
		if((location || null) == null) location = 'top';

		var style = '';
		if((distance || null) != null) style = 'margin-'+animation_type+':'+distance+'px;';
		var html = '<div id="common-prompt" class="am-alert am-alert-'+type+' am-animation-slide-'+animation_type+' prompt-'+location+'" style="'+style+'" data-am-alert><button type="button" class="am-close am-close-spin">&times;</button><p>'+msg+'</p></div>';
		$('body').append(html);

		// 自动关闭提示
		temp_time_out = setTimeout(function()
		{
			$('#common-prompt').slideToggle();
		}, (time || 3)*1000);
	}
}
// 中间提示信息
function PromptCenter(msg, type, time, distance)
{
	Prompt(msg, type, time, distance, 'top', 'center');
}
// 底部提示信息
function PromptBottom(msg, type, time, distance)
{
	Prompt(msg, type, time, distance, 'bottom', 'bottom');
}

/**
 * [ArrayTurnJson js数组转json]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-10T14:32:04+0800
 * @param  {[array]} 	all    	[需要被转的数组]
 * @param  {[object]} 	object 	[需要压进去的json对象]
 * @return {[object]} 			[josn对象]
 */
function ArrayTurnJson(all, object)
{
	for(var name in all)
	{
		object.append(name, all[name]);
	}
	return object;
}

/**
 * [GetFormVal 获取form表单的数据]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-10T14:31:19+0800
 * @param    {[string]}     element [元素的class或id]
G
gongfuxiang 已提交
77
 * @param    {[boolean]}    is_json [是否返回json对象(默认否)]
D
v1.2.0  
devil_gong 已提交
78 79
 * @return   {[object]}        		[josn对象]
 */
G
gongfuxiang 已提交
80
function GetFormVal(element, is_json)
D
v1.2.0  
devil_gong 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
{
	var object = new FormData();

	// input 常用类型
	$(element).find('input[type="hidden"], input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="date"], input[type="url"], input[type="radio"]:checked, textarea, input[type="file"]').each(function(key, tmp)
	{
		if(tmp.type == 'file')
		{
			object.append(tmp.name, ($(this).get(0).files[0] == undefined) ? '' : $(this).get(0).files[0]);
		} else {
			object.append(tmp.name, tmp.value.replace(/^\s+|\s+$/g,""));
		}
	});

	// select 单选择和多选择
	var tmp_all = [];
	var i = 0;
	$(element).find('select').find('option').each(function(key, tmp)
	{
		var name = $(this).parents('select').attr('name');
		if(name != undefined && name != '')
		{
			if($(this).is(':selected') && tmp.value != undefined && tmp.value != '')
			{
				// 多选择
				if($(this).parents('select').attr('multiple') != undefined)
				{
					if(tmp_all[name] == undefined)
					{
						tmp_all[name] = [];
						i = 0;
					}
					tmp_all[name][i] = tmp.value;
					i++;
				} else {
					// 单选择
					object.append(name, tmp.value);
				}
			}
		}
	});
	object = ArrayTurnJson(tmp_all, object);

	// input 复选框checkboox
	tmp_all = [];
	i = 0;
	$(element).find('input[type="checkbox"]').each(function(key, tmp)
	{
		if(tmp.name != undefined && tmp.name != '')
		{
			if($(this).is(':checked'))
			{
				if(tmp_all[tmp.name] == undefined)
				{
					tmp_all[tmp.name] = [];
					i = 0;
				}
				tmp_all[tmp.name][i] = tmp.value;
				i++;
			}
		}
	});
	object = ArrayTurnJson(tmp_all, object);
G
gongfuxiang 已提交
144 145 146 147 148 149 150 151

	// 是否需要返回json对象
	if(is_json === true)
	{
		var json = {};
			object.forEach((value, key) => json[key] = value);
		return json;
	}
D
v1.2.0  
devil_gong 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
	return object;
}

/**
 * [IsExitsFunction 方法是否已定义]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-10T14:30:37+0800
 * @param    {[string]}    fun_name [方法名]
 * @return 	 {[boolean]}        	[已定义true, 则false]
 */
function IsExitsFunction(fun_name)
{
    try
    {
        if(typeof(eval(fun_name)) == "function") return true;
    } catch(e) {}
    return false;
}

/**
 * [GetTagValue 根据tag对象获取值]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2017-10-07T20:53:40+0800
 * @param    {[object]}         tag_obj [tag对象]
 */
function GetTagValue(tag_obj)
{
	// 默认值
	var v = null;

	// 标签名称
	var tag_name = tag_obj.prop("tagName");

	// input
	if(tag_name == 'INPUT')
	{
		var type = tag_obj.attr('type');
		switch(type)
		{
			// 单选框
			case 'checkbox' :
				v = tag_obj.is(':checked') ? tag_obj.val() : null;
				break;

			// 其它选择
			default :
				v = tag_obj.val() || null;
		}
	}
	return v;
}

/**
 * [$form.validator 公共表单校验, 添加class form-validation 类的表单自动校验]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-10T14:22:39+0800
 * @param    {[string] [form_name] 		[标题class或id]}
 * @param    {[string] [action] 		[请求地址]}
 * @param    {[string] [method] 		[请求类型 POST, GET]}
 * @param    {[string] [request-type] 	[回调类型 ajax-url, ajax-fun, ajax-reload]}
 * @param    {[string] [request-value] 	[回调值 ajax-url地址 或 ajax-fun方法]}
 */

function FromInit(form_name)
{
	if(form_name == undefined)
	{
		form_name = 'form.form-validation';
	}
	var editor_tag_name = 'editor-tag';
	var $form = $(form_name);
D
devil_gong 已提交
229 230 231 232
	if($form.length <= 0)
	{
		return false;
	}
D
v1.2.0  
devil_gong 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	var $editor_tag = $form.find('[id='+editor_tag_name+']');
	var editor_count = $editor_tag.length;
	if(editor_count > 0)
	{
		// 编辑器初始化
		var editor = UE.getEditor(editor_tag_name);

		// 编辑器内容变化时同步到 textarea
		editor.addListener('contentChange', function()
		{
			editor.sync();

			// 触发验证
			$editor_tag.trigger('change');
		});
	}
	$form.validator(
	{
		// 自定义校验规则
		validate: function(validity)
		{
			// 二选一校验
			if($(validity.field).is('.js-choice-one'))
			{
G
gongfuxiang 已提交
257
				var tag = $(validity.field).attr('data-choice-one-to');
D
v1.2.0  
devil_gong 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
				if(typeof($(validity.field).attr('required')) == 'undefined' && typeof($(tag).attr('required')) == 'undefined')
				{
					validity.valid = true;
				} else {
					var v1 = GetTagValue($(validity.field));
					var v2 = GetTagValue($(tag));
					validity.valid = (v1 == null && v2 == null) ? false : true;
				}
			}
		},

		// 错误
		onInValid: function(validity)
		{
			// 错误信息
			var $field = $(validity.field);
G
gongfuxiang 已提交
274
			var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
D
v1.2.0  
devil_gong 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
			Prompt(msg);
		},

		// 提交
		submit: function(e)
		{
			if(editor_count > 0)
			{
				// 同步编辑器数据
				editor.sync();

				// 表单验证未成功,而且未成功的第一个元素为 UEEditor 时,focus 编辑器
				if (!this.isFormValid() && $form.find('.' + this.options.inValidClass).eq(0).is($editor_tag))
				{
					// 编辑器获取焦点
					editor.focus();

					// 错误信息
G
gongfuxiang 已提交
293 294
					var msg = $editor_tag.data('validationMessage') || $editor_tag.getValidationMessage(validity);
					console.log(msg);
D
v1.2.0  
devil_gong 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
					Prompt(msg);
				}
			}

			// 通过验证
			if(this.isFormValid())
			{
				// 多选插件校验
				if($form.find('.chosen-select'))
				{
					var is_success = true;
					$form.find('select.chosen-select').each(function(k, v)
					{
						var required = $(this).attr('required');
						if(($(this).attr('required') || null) == 'required')
						{
							var multiple = $(this).attr('multiple') || null;
							var minchecked = parseInt($(this).attr('minchecked')) || 0;
							var maxchecked = parseInt($(this).attr('maxchecked')) || 0;
							var msg = $(this).attr('data-validation-message');
							var value = $(this).val();
							if((value || null) == null && value != '0')
							{
								is_success = false;
								Prompt(msg || '请选择项');
								$(this).trigger('blur');
								return false;
							} else {
								if(multiple == 'multiple')
								{
									var count = value.length;
									if(minchecked > 0 && count < minchecked)
									{
										is_success = false;
										msg = msg || '至少选择'+minchecked+'';
									}
									if(maxchecked > 0 && count > maxchecked)
									{
										is_success = false;
										msg = msg || '最多选择'+maxchecked+'';
									}
									if(is_success === false)
									{
										Prompt(msg);
										$(this).trigger('blur');
										$(this).parents('.am-form-group').removeClass('am-form-success').addClass('am-form-error');
										return false;
									}
								}
							}
						}
					});
					if(is_success === false)
					{
						return false;
					}
				}

				// button加载
				var $button = $form.find('button[type="submit"]');
				$button.button('loading');

				// 获取表单数据
G
gongfuxiang 已提交
358 359 360 361 362
				var action = $form.attr('action') || null;
				var method = $form.attr('method') || null;
				var request_type = $form.attr('request-type') || null;
				var request_value = $form.attr('request-value') || null;
				var ajax_all = ['ajax-reload', 'ajax-url', 'ajax-fun', 'sync'];
D
v1.2.0  
devil_gong 已提交
363

G
gongfuxiang 已提交
364
				// 是form表单直接通过
D
v1.2.0  
devil_gong 已提交
365 366 367 368 369 370
				if(request_type == 'form')
				{
					return true;
				}

				// 参数校验
G
gongfuxiang 已提交
371
				if(ajax_all.indexOf(request_type) == -1)
D
v1.2.0  
devil_gong 已提交
372 373
				{
	            	$button.button('reset');
G
gongfuxiang 已提交
374
	            	Prompt('表单[类型]参数配置有误');
D
v1.2.0  
devil_gong 已提交
375 376 377 378
	            	return false;
				}

				// 类型不等于刷新的时候,类型值必须填写
G
gongfuxiang 已提交
379
				if(request_type != 'ajax-reload' && request_value == null)
D
v1.2.0  
devil_gong 已提交
380 381 382 383 384 385
				{
	        		$button.button('reset');
					Prompt('表单[类型值]参数配置有误');
					return false;
				}

G
gongfuxiang 已提交
386 387 388 389 390 391
				// 同步调用方法
				if(request_type == 'sync')
				{
            		$button.button('reset');
					if(IsExitsFunction(request_value))
            		{
D
devil_gong 已提交
392
            			window[request_value](GetFormVal(form_name, true));
G
gongfuxiang 已提交
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
            		} else {
            			Prompt('['+request_value+']表单定义的方法未定义');
            		}
            		return false;
				}

				if(action == null || method == null)
				{
	            	$button.button('reset');
	            	Prompt('表单[action或method]参数配置有误');
	            	return false;
				}

				// 开启进度条
				$.AMUI.progress.start();

D
v1.2.0  
devil_gong 已提交
409 410 411 412 413
				// ajax请求
				$.ajax({
					url:action,
					type:method,
	                dataType:"json",
G
gongfuxiang 已提交
414
	                timeout:$form.attr('timeout') || 30000,
D
v1.2.0  
devil_gong 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
	                data:GetFormVal(form_name),
	                processData:false,
					contentType:false,
	                success:function(result)
	                {
	                	// 调用自定义回调方法
	                	if(request_type == 'ajax-fun')
	                	{
	                		if(IsExitsFunction(request_value))
	                		{
	                			window[request_value](result);
	                		} else {
	                			$.AMUI.progress.done();
		            			$button.button('reset');
	                			Prompt('['+request_value+']表单定义的方法未定义');
	                		}
	                	} else if(request_type == 'ajax-url' || request_type == 'ajax-reload')
	                	{
	                		$.AMUI.progress.done();
		            		if(result.code == 0)
		            		{
		            			// url跳转
		            			if(request_type == 'ajax-url')
		            			{
		            				Prompt(result.msg, 'success');
		            				setTimeout(function()
									{
										window.location.href = request_value;
									}, 1500);

		            			// 页面刷新
		            			} else if(request_type == 'ajax-reload')
		            			{
		            				Prompt(result.msg, 'success');
		            				setTimeout(function()
									{
										window.location.reload();
									}, 1500);
								}
							} else {
								Prompt(result.msg);
								$button.button('reset');
							}
						}
					},
					error:function(xhr, type)
		            {
		            	$.AMUI.progress.done();
		            	$button.button('reset');
D
devil_gong 已提交
464
		            	Prompt('服务器错误');
D
v1.2.0  
devil_gong 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
		            }
	            });
			}
			return false;
		}
	});
}
// 默认初始化一次,默认标签[form.form-validation]
FromInit('form.form-validation');

/**
 * [FormDataFill 表单数据填充]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-14T14:46:47+0800
 * @param    {[json]}    json [json数据对象]
 * @param    {[string]}  tag  [tag标签]
 */
function FormDataFill(json, tag)
{
	if(json != undefined)
	{
		if(tag == undefined)
		{
			tag = 'form.form-validation';
		}
		$form = $(tag);
		for(var i in json)
		{
			$form.find('input[type="hidden"][name="'+i+'"], input[type="text"][name="'+i+'"], input[type="password"][name="'+i+'"], input[type="email"][name="'+i+'"], input[type="number"][name="'+i+'"], input[type="date"][name="'+i+'"], textarea[name="'+i+'"], select[name="'+i+'"], input[type="url"][name="'+i+'"]').val(json[i]);

			// input radio
			$form.find('input[type="radio"][name="'+i+'"]').each(function(temp_value, temp_tag)
			{
				var state = (json[i] == temp_value);
				this.checked = state;
			});
		}

G
gongfuxiang 已提交
505 506 507 508 509 510 511 512 513 514
		// 是否存在pid和当前id相同
		if($form.find('select[name="pid"]').length > 0)
		{
			$form.find('select[name="pid"]').find('option').removeAttr('disabled');
			if((json['id'] || null) != null)
			{
				$form.find('select[name="pid"]').find('option[value="'+json['id']+'"]').attr('disabled', true);
			}
		}

D
v1.2.0  
devil_gong 已提交
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
		// 多选插件事件更新
		if($('.chosen-select').length > 0)
		{
			$('.chosen-select').trigger('chosen:updated');
		}
	}
}

/**
 * [Tree 树方法]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2017-01-13T10:30:23+0800
 * @param    {[int]}    	id    			[节点id]
 * @param    {[string]}   	url   			[请求url地址]
 * @param    {[int]}      	level 			[层级]
 * @param    {[int]}      	is_add_node 	[是否开启新增子级按钮]
 * @param    {[int]}      	is_delete_all	[是否所有开启删除按钮]
 */
function Tree(id, url, level, is_add_node, is_delete_all)
{
	$.ajax({
		url:url,
		type:'POST',
		dataType:"json",
G
gongfuxiang 已提交
541
		timeout:30000,
D
v1.2.0  
devil_gong 已提交
542 543 544 545 546 547 548
		data:{"id":id},
		success:function(result)
		{
			if(result.code == 0 && result.data.length > 0)
			{
				html = (id != 0) ? '' : '<table class="am-table am-table-striped am-table-hover">';
				is_add_node = is_add_node || 0;
G
gongfuxiang 已提交
549
				var is_astrict_rank = parseInt($('#tree').attr('data-rank')) || 0;
D
v1.2.0  
devil_gong 已提交
550 551 552 553 554 555 556 557 558 559 560 561
				for(var i in result.data)
				{
					// 获取class
					var class_name = $('#data-list-'+id).attr('class') || '';

					// 数据 start
					var is_active = (result.data[i]['is_enable'] == 0) ? 'am-active' : '';
					html += '<tr id="data-list-'+result.data[i]['id']+'" class="'+class_name+' tree-pid-'+id+' '+is_active+'"><td>';
					tmp_level = (id != 0) ? parseInt(level)+20 : parseInt(level);
					var son_css = '';
					if(result.data[i]['is_son'] == 'ok')
					{
562
						html += '<i class="am-icon-plus c-p tree-submit" data-id="'+result.data[i]['id']+'" data-url="'+result.data[i]['ajax_url']+'" data-level="'+tmp_level+'" data-is_add_node="'+is_add_node+'" data-is_delete_all="'+is_delete_all+'" style="margin-right:8px;width:12px;';
D
v1.2.0  
devil_gong 已提交
563 564 565 566 567 568 569 570 571 572 573
						if(id != 0)
						{
							html += 'margin-left:'+tmp_level+'px;';
						}
						html += '"></i>';
					} else {
						son_css = 'padding-left:'+tmp_level+'px;';
					}
					html += '<span style="'+son_css+'">';
					if((result.data[i]['icon_url'] || null) != null)
					{
D
devil_gong 已提交
574
						html += '<a href="'+result.data[i]['icon_url']+'" target="_blank"><img src="'+result.data[i]['icon_url']+'" width="20" height="20" class="am-vertical-align-middle am-margin-right-xs" /></a>';
D
v1.2.0  
devil_gong 已提交
575 576 577 578 579 580 581 582 583 584 585 586
					}
					html += '<span>'+(result.data[i]['name_alias'] || result.data[i]['name'])+'</span>';
					html += '</span>';
					// 数据 end

					// 操作项 start
					html += '<div class="fr m-r-20 submit">';

					// 新增
					var rank = tmp_level/20+1;
					if(is_add_node == 1 && (is_astrict_rank == 0 || rank < is_astrict_rank))
					{
G
gongfuxiang 已提交
587
						html += '<button class="am-btn am-btn-success am-btn-xs am-radius am-icon-plus c-p m-r-10 tree-submit-add-node" data-am-modal="{target: \'#data-save-win\'}" data-id="'+result.data[i]['id']+'"> 新增</button>';
D
v1.2.0  
devil_gong 已提交
588 589 590
					}

					// 编辑
G
gongfuxiang 已提交
591
					html += '<button class="am-btn am-btn-secondary am-btn-xs am-radius am-icon-edit c-p submit-edit" data-am-modal="{target: \'#data-save-win\'}" data-json=\''+result.data[i]['json']+'\' data-is_exist_son="'+result.data[i]['is_son']+'"> 编辑</button>';
D
v1.2.0  
devil_gong 已提交
592 593
					if(result.data[i]['is_son'] != 'ok' || is_delete_all == 1)
					{
594 595 596
						// 是否需要删除子数据
						var pid_class = is_delete_all == 1 ? '.tree-pid-'+result.data[i]['id'] : '';

D
v1.2.0  
devil_gong 已提交
597
						// 删除
G
gongfuxiang 已提交
598
						html += '<button class="am-btn am-btn-danger am-btn-xs am-radius am-icon-trash-o c-p m-l-10 submit-delete" data-id="'+result.data[i]['id']+'" data-url="'+result.data[i]['delete_url']+'" data-ext-delete-tag="'+pid_class+'"> 删除</button>';
D
v1.2.0  
devil_gong 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
					}
					html += '</div>';
					// 操作项 end
					
					html += '</td></tr>';
				}
				html += (id != 0) ? '' : '</table>';

				// 防止网络慢的情况下重复添加
				if($('#data-list-'+id).find('.tree-submit').attr('state') != 'ok')
				{
					if(id == 0)
					{
						$('#tree').html(html);
					} else {
						$('#data-list-'+id).after(html);
						$('#data-list-'+id).find('.tree-submit').attr('state', 'ok');
						$('#data-list-'+id).find('.tree-submit').removeClass('am-icon-plus');
						$('#data-list-'+id).find('.tree-submit').addClass('am-icon-minus-square');
					}
				}
			} else {
				$('#tree').find('p').text(result.msg);
				$('#tree').find('img').remove();
			}
		},
		error:function(xhr, type)
		{
			$('#tree').find('p').text('网络异常出错');
			$('#tree').find('img').remove();
		}
	});
}

/**
 * [ImageFileUploadShow 图片上传预览]
 * @param  {[string]} class_name 		[class名称]
 * @param  {[string]} show_img   		[预览图片id或class]
 * @param  {[string]} default_images    [默认图片]
 */
function ImageFileUploadShow(class_name, show_img, default_images)
{
	$(document).on("change", class_name, function(imgFile)
	{
G
gongfuxiang 已提交
643
		show_img = $(this).attr('data-image-tag') || null;
D
v1.2.0  
devil_gong 已提交
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
		var status = false;
		if((imgFile.target.value || null) != null)
		{
			var filextension = imgFile.target.value.substring(imgFile.target.value.lastIndexOf("."),imgFile.target.value.length);
				filextension = filextension.toLowerCase();
			if((filextension!='.jpg') && (filextension!='.gif') && (filextension!='.jpeg') && (filextension!='.png') && (filextension!='.bmp'))
			{
				Prompt("图片格式错误,请重新上传");
			} else {
				if(document.all)
				{
					Prompt('ie浏览器不可用');
					/*imgFile.select();
					path = document.selection.createRange().text;
					$(this).parent().parent().find('img').attr('src', '');
					$(this).parent().parent().find('img').attr('src', path);  //使用滤镜效果  */
				} else {
					var url = window.URL.createObjectURL(imgFile.target.files[0]);// FF 7.0以上
					$(show_img).attr('src', url);
					status = true;
				}
			}
		}
G
gongfuxiang 已提交
667
		var default_img = $(show_img).attr('data-default') || null;
D
v1.2.0  
devil_gong 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
		if(status == false && ((default_images || null) != null || default_img != null))
		{
			$(show_img).attr('src', default_images || default_img);
		}
	});
}

/**
 * [VideoFileUploadShow 视频上传预览]
 * @param  {[string]} class_name 		[class名称]
 * @param  {[string]} show_video   		[预览视频id或class]
 * @param  {[string]} default_video     [默认视频]
 */
function VideoFileUploadShow(class_name, show_video, default_video)
{
	$(document).on("change", class_name, function(imgFile)
	{
G
gongfuxiang 已提交
685
		show_video = $(this).attr('data-video-tag') || null;
D
v1.2.0  
devil_gong 已提交
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
		var status = false;
		if((imgFile.target.value || null) != null)
		{
			var filextension = imgFile.target.value.substring(imgFile.target.value.lastIndexOf("."),imgFile.target.value.length);
				filextension = filextension.toLowerCase();
			if(filextension != '.mp4')
			{
				Prompt("视频格式错误,请重新上传");
			} else {
				if(document.all)
				{
					Prompt('ie浏览器不可用');
					/*imgFile.select();
					path = document.selection.createRange().text;
					$(this).parent().parent().find('img').attr('src', '');
					$(this).parent().parent().find('img').attr('src', path);  //使用滤镜效果  */
				} else {
					var url = window.URL.createObjectURL(imgFile.target.files[0]);// FF 7.0以上
					$(show_video).attr('src', url);
					status = true;
				}
			}
		}
G
gongfuxiang 已提交
709
		var default_video = $(show_video).attr('data-default') || null;
D
v1.2.0  
devil_gong 已提交
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
		if(status == false && ((default_video || null) != null || default_video != null))
		{
			$(show_video).attr('src', default_video || default_video);
		}
	});
}

 
// 校验浏览器是否支持视频播放
function CheckVideo()
{
	if(document.createElement('video').canPlayType)
	{
		var vid_test = document.createElement("video");
		var ogg_test = vid_test.canPlayType('video/ogg; codecs="theora, vorbis"');
		if(!ogg_test)
		{
			h264_test = vid_test.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
			if(!h264_test)
			{
				document.getElementById("checkVideoResult").innerHTML = "Sorry. No video support."
			} else {
				if(h264_test == "probably")
				{
					document.getElementById("checkVideoResult").innerHTML = "Yes! Full support!";
				} else {
					document.getElementById("checkVideoResult").innerHTML = "Well. Some support.";
				}
			}
		} else {
			if(ogg_test == "probably")
			{
				document.getElementById("checkVideoResult").innerHTML = "Yes! Full support!";
			} else {
				document.getElementById("checkVideoResult").innerHTML = "Well. Some support.";
			}
		}
	} else {
		document.getElementById("checkVideoResult").innerHTML = "Sorry. No video support."
	}
}

/**
 * 弹窗加载
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-09-13
 * @desc    description
 * @param   {[string]}        url   	[加载url]
 * @param   {[string]}        title 	[标题]
 * @param   {[string]}        tag   	[指定id标记]
 * @param   {[string]}        class_tag [指定class]
 */
function ModalLoad(url, title, tag, class_tag)
{
	tag = tag || 'common-popup-modal';
	if($('#'+tag).length > 0)
	{
		$('#'+tag).remove();
	}

	var html = '<div class="am-popup popup-iframe '+class_tag+'" id="'+tag+'">';
		html += '<div class="am-popup-inner">';
	    html += '<div class="am-popup-hd">';
	    html += '<h4 class="am-popup-title">'+(title || '温馨提示')+'</h4>';
	    html += '<span data-am-modal-close class="am-close">&times;</span>';
		html += '</div>';
	    html += '<iframe src="'+url+'"></iframe>';
		html += '</div>';
		html += '</div>';
	$('body').append(html);
	$('#'+tag).modal();
}

/**
 * 价格四舍五入,并且指定保留小数位数
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-09-14
 * @desc    description
 * @param   {[float]}      value [金额]
 * @param   {[int]}        pos   [位数 默认2]
 */
function FomatFloat(value, pos)
{
	pos = pos || 2;
	var f_x = Math.round(value*Math.pow(10, pos))/Math.pow(10, pos);

	var s_x = f_x.toString();
	var pos_decimal = s_x.indexOf('.');
	if(pos_decimal < 0)
	{
	  pos_decimal = s_x.length;
	  s_x += '.';
	}
	while (s_x.length <= pos_decimal + 2)
	{
	  s_x += '0';
	}
	return s_x;
}

/**
 * [DataDelete 数据删除]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2018-09-24T08:24:58+0800
 * @param    {[object]}                 e [当前元素对象]
 */
function DataDelete(e)
{
G
gongfuxiang 已提交
824 825 826 827 828
	var id = e.attr('data-id');
	var url = e.attr('data-url');
	var view = e.attr('data-view') || 'delete';
	var value = e.attr('data-value') || null;
	var ext_delete_tag = e.attr('data-ext-delete-tag') || null;
D
v1.2.0  
devil_gong 已提交
829

D
devil_gong 已提交
830 831 832 833 834 835 836 837 838 839 840
	if((id || null) == null || (url || null) == null)
	{
		Prompt('参数配置有误');
		return false;
	}

	// 请求删除数据
	$.ajax({
		url:url,
		type:'POST',
		dataType:"json",
841
		timeout:e.attr('data-timeout') || 30000,
D
devil_gong 已提交
842 843
		data:{"id":id},
		success:function(result)
D
v1.2.0  
devil_gong 已提交
844
		{
D
devil_gong 已提交
845
			if(result.code == 0)
D
v1.2.0  
devil_gong 已提交
846
			{
D
devil_gong 已提交
847 848 849 850 851 852 853 854 855
				Prompt(result.msg, 'success');

				switch(view)
				{
					// 成功则删除数据列表
					case 'delete' :
						Prompt(result.msg, 'success');
						$('#data-list-'+id).remove();
						if(ext_delete_tag != null)
D
v1.2.0  
devil_gong 已提交
856
						{
D
devil_gong 已提交
857 858 859
							$(ext_delete_tag).remove();
						}
						break;
D
v1.2.0  
devil_gong 已提交
860

D
devil_gong 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
					// 刷新
					case 'reload' :
						Prompt(result.msg, 'success');
						setTimeout(function()
						{
							window.location.reload();
						}, 1500);
						break;

					// 回调函数
					case 'fun' :
						if(IsExitsFunction(value))
                		{
                			result['data_id'] = id;
                			window[value](result);
                		} else {
                			Prompt('['+value+']配置方法未定义');
                		}
						break;

					// 跳转
					case 'jump' :
						Prompt(result.msg, 'success');
						if(value != null)
						{
							setTimeout(function()
D
v1.2.0  
devil_gong 已提交
887
							{
D
devil_gong 已提交
888 889
								window.location.href = value;
							}, 1500);
D
v1.2.0  
devil_gong 已提交
890
						}
D
devil_gong 已提交
891 892 893 894 895 896 897 898 899 900
						break;

					// 默认提示成功
					default :
						Prompt(result.msg, 'success');
				}
				// 成功则删除数据列表
				$('#data-list-'+id).remove();
			} else {
				Prompt(result.msg);
D
v1.2.0  
devil_gong 已提交
901 902
			}
		},
D
devil_gong 已提交
903 904 905 906
		error:function(xhr, type)
		{
			Prompt('网络异常出错');
		}
D
v1.2.0  
devil_gong 已提交
907 908 909
	});
}

D
devil_gong 已提交
910 911 912 913 914 915 916 917 918 919
/**
 * [ConfirmDataDelete 数据删除]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2018-09-24T08:24:58+0800
 * @param    {[object]}                 e [当前元素对象]
 */
function ConfirmDataDelete(e)
{
G
gongfuxiang 已提交
920 921 922
	var title = e.attr('data-title') || '温馨提示';
	var msg = e.attr('data-msg') || '删除后不可恢复、确认操作吗?';
	var is_confirm = (e.attr('data-is-confirm') == undefined || e.attr('data-is-confirm') == 1) ? 1 : 0;
D
devil_gong 已提交
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939

	if(is_confirm == 1)
	{
		AMUI.dialog.confirm({
			title: title,
			content: msg,
			onConfirm: function(options)
			{
				DataDelete(e);
			},
			onCancel: function(){}
		});
	} else {
		DataDelete(e);
	}
}

D
v1.2.0  
devil_gong 已提交
940
/**
G
充值  
gongfuxiang 已提交
941
 * [AjaxRequest ajax网络请求]
D
v1.2.0  
devil_gong 已提交
942 943 944
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
G
充值  
gongfuxiang 已提交
945
 * @datetime 2019-04-30T00:25:21+0800
D
v1.2.0  
devil_gong 已提交
946 947
 * @param    {[object]}                 e [当前元素对象]
 */
G
充值  
gongfuxiang 已提交
948
function AjaxRequest(e)
D
v1.2.0  
devil_gong 已提交
949
{
G
gongfuxiang 已提交
950 951 952 953 954
	var id = e.attr('data-id');
	var field = e.attr('data-field') || '';
	var value = e.attr('data-value') || '';
	var url = e.attr('data-url');
	var view = e.attr('data-view') || '';
G
充值  
gongfuxiang 已提交
955 956 957 958 959 960

	// ajax
	$.ajax({
		url:url,
		type:'POST',
		dataType:"json",
961
		timeout:e.attr('data-timeout') || 30000,
D
devil_gong 已提交
962
		data:{"id":id, "value": value, "field": field},
G
充值  
gongfuxiang 已提交
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
		success:function(result)
		{
			if(result.code == 0)
			{
				switch(view)
				{
					// 成功则删除数据列表
					case 'delete' :
						Prompt(result.msg, 'success');
						$('#data-list-'+id).remove();
						break;

					// 刷新
					case 'reload' :
						Prompt(result.msg, 'success');
						setTimeout(function()
						{
							window.location.reload();
						}, 1500);
						break;

					// 回调函数
					case 'fun' :
						if(IsExitsFunction(value))
                		{
                			window[value](result);
                		} else {
                			Prompt('['+value+']配置方法未定义');
                		}
						break;

					// 默认提示成功
					default :
						Prompt(result.msg, 'success');
				}
			} else {
				Prompt(result.msg);
			}
		},
		error:function(xhr, type)
		{
			Prompt('网络异常出错');
		}
	});
}

/**
 * [ConfirmNetworkAjax 确认网络请求]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2018-09-24T08:24:58+0800
 * @param    {[object]}                 e [当前元素对象]
 */
function ConfirmNetworkAjax(e)
{
G
gongfuxiang 已提交
1019 1020
	var title = e.attr('data-title') || '温馨提示';
	var msg = e.attr('data-msg') || '操作后不可恢复、确认继续吗?';
D
v1.2.0  
devil_gong 已提交
1021 1022 1023 1024

	AMUI.dialog.confirm({
		title: title,
		content: msg,
D
devil_gong 已提交
1025
		onConfirm: function(result)
D
v1.2.0  
devil_gong 已提交
1026
		{
G
充值  
gongfuxiang 已提交
1027
			AjaxRequest(e);
D
v1.2.0  
devil_gong 已提交
1028 1029 1030 1031 1032
		},
		onCancel: function(){}
	});
}

D
devil_gong 已提交
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
/**
 * 开启全屏
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-03-01
 * @desc    description
 */
function FullscreenOpen()
{
    var elem = document.body;
    if(elem.webkitRequestFullScreen)
    {
        elem.webkitRequestFullScreen();
    } else if (elem.mozRequestFullScreen)
    {
        elem.mozRequestFullScreen();
    } else if (elem.requestFullScreen)
    {
        elem.requestFullScreen();
    } else {
        Prompt("浏览器不支持全屏API或已被禁用");
        return false;
    }
    return true;
}

/**
 * 关闭全屏
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-03-01
 * @desc    description
 */
function FullscreenExit()
{
    var elem = document;
    if (elem.webkitCancelFullScreen)
    {
        elem.webkitCancelFullScreen();
    } else if (elem.mozCancelFullScreen)
    {
        elem.mozCancelFullScreen();
    } else if (elem.cancelFullScreen)
    {
        elem.cancelFullScreen();
    } else if (elem.exitFullscreen)
    {
        elem.exitFullscreen();
    } else {
        Prompt("浏览器不支持全屏API或已被禁用");
        return false;
    }
    return true;
}

G
gongfuxiang 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
/**
 * 全屏ESC监听
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-03-01
 * @desc    description
 */
var fullscreen_counter = 0;
function FullscreenEscEvent()
{
	fullscreen_counter++;
	if(fullscreen_counter%2 == 0)
	{
		var $fullscreen = $('.fullscreen-event');
		if(($fullscreen.attr('data-status') || 0) == 1)
		{
G
gongfuxiang 已提交
1107
			$fullscreen.find('.fullscreen-text').text($fullscreen.attr('data-fulltext-open') || '开启全屏');
G
gongfuxiang 已提交
1108 1109 1110 1111 1112
			$fullscreen.attr('data-status', 0);
		}
	}
}

D
devil_gong 已提交
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
/**
 * url参数替换,参数不存在则添加
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-03-20
 * @desc    description
 * @param   {[string]}        field [字段名称]
 * @param   {[string]}        value [字段值]
 * @param   {[string]}        url   [自定义url]
 */
function UrlFieldReplace(field, value, url)
{
    // 当前页面url地址
    url = url || window.location.href;

    // 锚点
    var anchor = '';
    if(url.indexOf('#') >= 0)
    {
        anchor = url.substr(url.indexOf('#'));
        url = url.substr(0, url.indexOf('#'));
    }

    if(url.indexOf('?') >= 0)
    {
        var str = url.substr(0, url.lastIndexOf('.'));
        var ext = url.substr(url.lastIndexOf('.'));
        if(str.indexOf(field) >= 0)
        {
            var first = str.substr(0, str.lastIndexOf(field));
            var last = str.substr(str.lastIndexOf(field));
                last = last.replace(new RegExp(field+'/', 'g'), '');
                last = (last.indexOf('/') >= 0) ? last.substr(last.indexOf('/')) : '';
                url = first+field+'/'+value+last+ext;
        } else {
            if(ext.indexOf('?') >= 0)
            {
                var p = '';
                exts = ext.substr(ext.indexOf('?')+1);
                if(ext.indexOf(field) >= 0)
                {
                    var params_all = exts.split('&');
                    for(var i in params_all)
                    {
                        var temp = params_all[i].split('=');

                        if(temp.length >= 2)
                        {
                            if(i > 0)
                            {
                                p += '&';
                            }
                            if(temp[0] == field)
                            {
                                p += field+'='+value;
                            } else {
                                p += params_all[i];
                            }
                        }
                    }
                } else {
                    p = exts+'&'+field+'='+value;
                }
                url = str+(ext.substr(0, ext.indexOf('?')))+'?'+p;
            } else {
                url = str+'/'+field+'/'+value+ext;
            }
        }
    } else {
        url += '?'+field+'='+value;
    }
    return url+anchor;
}

G
share  
gongfuxiang 已提交
1188
/**
G
share  
gongfuxiang 已提交
1189
 * 当前手机浏览器环境
G
share  
gongfuxiang 已提交
1190 1191 1192 1193
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2019-04-20T19:48:59+0800
G
share  
gongfuxiang 已提交
1194
 * @return   {string} [weixin,weibo,qq]
G
share  
gongfuxiang 已提交
1195
 */
G
share  
gongfuxiang 已提交
1196
function MobileBrowserEnvironment()
G
share  
gongfuxiang 已提交
1197
{
G
share  
gongfuxiang 已提交
1198
	// 浏览器标识
G
share  
gongfuxiang 已提交
1199
	var ua = navigator.userAgent.toLowerCase();
G
share  
gongfuxiang 已提交
1200 1201

	// 微信
G
share  
gongfuxiang 已提交
1202
	if(ua.match(/MicroMessenger/i) == 'micromessenger')
G
share  
gongfuxiang 已提交
1203
	{
G
share  
gongfuxiang 已提交
1204 1205
		return 'weixin';
	}
G
share  
gongfuxiang 已提交
1206

G
share  
gongfuxiang 已提交
1207
	// 新浪微博
G
share  
gongfuxiang 已提交
1208 1209 1210 1211
	if(ua.match(/WeiBo/i) == 'weibo')
	{
		return 'weibo';
	}
G
share  
gongfuxiang 已提交
1212

G
share  
gongfuxiang 已提交
1213 1214 1215 1216 1217 1218 1219
	// QQ空间
	if(ua.match(/qzone/i) == 'qzone')
	{
		return 'qzone';
	}

	// QQ
G
share  
gongfuxiang 已提交
1220 1221 1222
	if(ua.match(/QQ/i) == 'qq')
	{
		return 'qq';
G
share  
gongfuxiang 已提交
1223
	}
G
share  
gongfuxiang 已提交
1224
	return null;
G
share  
gongfuxiang 已提交
1225 1226
}

G
gongfuxiang 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
/**
 * [pagelibrary 分页按钮获取]
 * @param  {[int]} total      [数据总条数]
 * @param  {[int]} number     [页面数据显示条数]
 * @param  {[int]} page       [当前页码数]
 * @param  {[int]} sub_number [按钮生成个数]
 * @return {[string]}         [html代码]
 */
function PageLibrary(total, number, page, sub_number)
{
	if((total || null) == null) return '';
	if((page || null) == null) page = 1;
	if((number || null) == null) number = 15;
	if((sub_number || null) == null) sub_number = 2;

	var page_total = Math.ceil(total/number);
	if(page > page_total) page = page_total;
	page = (page <= 0) ? 1 : parseInt(page);

	var html = '<ul class="am-pagination am-pagination-centered pagelibrary"><li ';
		html += (page > 1) ? '' : 'class="am-disabled"';
		page_x = page-1;
		html += '><a data-page="'+page_x+'" class="am-radius">&laquo;</a></li>';

		var html_before = '';
		var html_after = '';
		var html_page = '<li class="am-active"><a class="am-radius">'+page+'</a></li>';
		if(sub_number > 0)
		{
			/* 前按钮 */
			if(page > 1)
			{
				total = (page-sub_number < 1) ? 1 : page-sub_number;
				for(var i=page-1; i>=total; i--)
				{
					html_before = '<li><a data-page="'+i+'" class="am-radius">'+i+'</a></li>'+html_before;
				}
			}

			/* 后按钮 */
			if(page_total > page)
			{
				total = (page+sub_number > page_total) ? page_total : page+sub_number;
				for(var i=page+1; i<=total; i++)
				{
					html_after += '<li><a data-page="'+i+'" class="am-radius">'+i+'</a></li>';

				}
			}
		}

		html += html_before+html_page+html_after;

		html += '<li';
		html += (page > 0 && page < page_total) ? '' : ' class="am-disabled"';
		page_y = page+1;
		html += '><a data-page="'+page_y+'" class="am-radius">&raquo;</a></li></ul>';
	return html;
}

D
Devil 已提交
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
/**
 * [RegionNodeData 地区联动]
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2018-09-23T22:00:30+0800
 * @param    {[int]}          pid     	[pid数据值]
 * @param    {[string]}       name      [当前节点name名称]
 * @param    {[string]}       next_name [下一个节点名称(数据渲染节点)]
 * @param    {[int]}          value 	[需要选中的值]
 */
function RegionNodeData(pid, name, next_name, value)
{
	if(pid != null)
	{
		$.ajax({
			url:$('.region-linkage').attr('data-url'),
			type:'POST',
			data:{"pid": pid},
			dataType:'json',
			success:function(result)
			{
				if(result.code == 0)
				{
					/* html拼接 */
					var html = '<option value="">'+$('.region-linkage select[name='+next_name+']').find('option:eq(0)').text()+'</option>';

					/* 没有指定选中值则从元素属性读取 */
					value = value || $('.region-linkage select[name='+next_name+']').attr('data-value') || null;
					for(var i in result.data)
					{
						html += '<option value="'+result.data[i]['id']+'"';
						if(value != null && value == result.data[i]['id'])
						{
							html += ' selected ';
						}
						html += '>'+result.data[i]['name']+'</option>';
					}

					/* 下一级数据添加 */
					$('.region-linkage select[name='+next_name+']').html(html).trigger('chosen:updated');
				} else {
					Prompt(result.msg);
				}
			}
		});
	}

	/* 子级元素数据清空 */
	var child = null;
	switch(name)
	{
		case 'province' :
			child = ['city', 'county'];
			break;

		case 'city' :
			child = ['county'];
			break;
	}
	if(child != null)
	{
		for(var i in child)
		{
			var $temp_obj = $('.region-linkage select[name='+child[i]+']');
			var temp_find = $temp_obj.find('option').first().text();
			var temp_html = '<option value="">'+temp_find+'</option>';
			$temp_obj.html(temp_html).trigger('chosen:updated');
		}
	}
}

/**
 * 编辑窗口额为参数处理
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-08-07
 * @desc    description
 * @param   {[object]}        data [数据]
 * @param   {[string]}        type [edit, add]
 * @return  {[object]}             [处理后的数据]
 */
function FunSaveWinAdditional(data, type)
{
	// 额外处理数据
	if($('#tree').length > 0)
	{
		var additional = $('#tree').data('additional') || null;
		if(additional != null)
		{
			for(var i in additional)
			{
				var value = (type == 'add') ? (additional[i]['value'] || '') : (data[additional[i]['field']] || additional[i]['value'] || '');
				switch(additional[i]['type'])
				{
					// 表单
					case 'input' :
					case 'select' :
					case 'textarea' :
						data[additional[i]['field']] = value;
						break;

					// 样式处理
					case 'css' :
						$(additional[i]['tag']).css(additional[i]['style'], value);
						break;

					// 文件
					case 'file' :
						var $file_tag = $(additional[i]['tag']);
						if($file_tag.val().length > 0)
						{
							$file_tag.after($file_tag.clone().val(''));
							$file_tag.val('');
						}
						break;

					// 属性
					case 'attr' :
						$(additional[i]['tag']).attr(additional[i]['style'], value);
						break;

					// 内容替换
					case 'html' :
						$(additional[i]['tag']).html(value);
						break;
				}
			}
		}
	}
	return data;
}

/**
 * 添加窗口初始化
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-08-06
 * @desc    description
 */
function TreeFormInit()
{
	// 更改窗口名称
	$title = $('#data-save-win').find('.am-popup-title');
	$title.text($title.attr('data-add-title'));

	// 填充数据
	var data = {"id":"", "pid":0, "name":"", "sort":0, "is_enable":1, "icon":""};

	// 额外处理数据
	data = FunSaveWinAdditional(data, 'init');

	// 清空表单
	FormDataFill(data);

	// 移除菜单禁止状态
	$('form select[name="pid"]').removeAttr('disabled');

	// 校验成功状态增加失去焦点
	$('form').find('.am-field-valid').each(function()
	{
		$(this).blur();
	});

	// 多选插件事件更新
	if($('.chosen-select').length > 0)
	{
		$('.chosen-select').trigger('chosen:updated');
	}
}

D
devil_gong 已提交
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
/**
 * 地图初始化
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-11-12
 * @desc    description
 * @param   {[float]}        	lng   [经度]
 * @param   {[float]}        	lat   [维度]
 * @param   {[int]}        		level [层级]
 * @param   {[object]}        	point [中心对象]
 */
function MapInit(lng, lat, level, point)
{
	// 百度地图API功能
    var map = new BMap.Map("map", {enableMapClick:false});
    level = level || $('#map').data('level') || 16;
    point = point || (new BMap.Point(lng || 116.400244, lat || 39.92556));
    map.centerAndZoom(point, level);

    // 添加控件
    var navigationControl = new BMap.NavigationControl({
        // 靠左上角位置
        anchor: BMAP_ANCHOR_TOP_LEFT,
        // LARGE类型
        type: BMAP_NAVIGATION_CONTROL_LARGE,
    });
    map.addControl(navigationControl);

    // 创建标注
    var marker = new BMap.Marker(point);  // 创建标注
    map.addOverlay(marker);              // 将标注添加到地图中
    marker.enableDragging();           // 可拖拽
    marker.addEventListener("dragend", function(e) {
        map.panTo(e.point);
        $('#form-lng').val(e.point.lng);
        $('#form-lat').val(e.point.lat);
    });

    // 设置版权控件位置
    var cr = new BMap.CopyrightControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT});
    map.addControl(cr); //添加版权控件
    var bs = map.getBounds();   //返回地图可视区域
    cr.addCopyright({id: 1, content: "<div class='map-copy'><span>拖动红色图标直接定位</span></div>", bounds:bs});

    //获取地址坐标
    var p = marker.getPosition();
    $('#form-lng').val(p.lng);
	$('#form-lat').val(p.lat);
}

D
Devil 已提交
1511

D
v1.2.0  
devil_gong 已提交
1512 1513 1514
// 公共数据操作
$(function()
{
D
devil_gong 已提交
1515 1516 1517 1518 1519 1520 1521 1522
	// 全屏操作
	$('.fullscreen-event').on('click', function()
	{
		var status = $(this).attr('data-status') || 0;
		if(status == 0)
		{
			if(FullscreenOpen())
			{
G
gongfuxiang 已提交
1523
				$(this).find('.fullscreen-text').text($(this).attr('data-fulltext-exit') || '退出全屏');
D
devil_gong 已提交
1524 1525 1526 1527
			}
		} else {
			if(FullscreenExit())
			{
G
gongfuxiang 已提交
1528
				$(this).find('.fullscreen-text').text($(this).attr('data-fulltext-open') || '开启全屏');
D
devil_gong 已提交
1529 1530 1531
			}
		}
		$(this).attr('data-status', status == 0 ? 1 : 0);
G
gongfuxiang 已提交
1532 1533 1534 1535 1536 1537
		$(this).attr('data-status-y', status);
	});
	
	// esc退出全屏事件
	document.addEventListener("fullscreenchange", function(e) {
	  FullscreenEscEvent();
D
devil_gong 已提交
1538
	});
G
gongfuxiang 已提交
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
	document.addEventListener("mozfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});
	document.addEventListener("webkitfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});
	document.addEventListener("msfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});

D
devil_gong 已提交
1549

D
v1.2.0  
devil_gong 已提交
1550 1551 1552 1553 1554 1555
	// 多选插件初始化
	if($('.chosen-select').length > 0)
	{
		$('.chosen-select').chosen({
			inherit_select_classes: true,
			enable_split_word_search: true,
D
devil_gong 已提交
1556 1557
			search_contains: true,
			no_results_text: '没有匹配到结果'
D
v1.2.0  
devil_gong 已提交
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
		});
	}
	// 多选插件 空内容失去焦点验证bug兼容处理
	$(document).on('blur', 'ul.chosen-choices .search-field, div.chosen-select .chosen-search', function()
	{
		if($(this).parent().find('li').length <= 1 || $(this).parent().parent().find('.chosen-default').length >= 1)
		{
			$(this).parent().parent().prev().trigger('blur');
		}
	});
	
	/**
	 * [submit-delete 删除数据列表]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-10T14:22:39+0800
	 * @param    {[int] 	[data-id] 	[数据id]}
	 * @param    {[string] 	[data-url] 	[请求地址]}
	 */
	$(document).on('click', '.submit-delete', function()
	{
D
devil_gong 已提交
1580
		ConfirmDataDelete($(this));
D
v1.2.0  
devil_gong 已提交
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
	});

	/**
	 * [submit-state 公共数据状态操作]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-10T14:22:39+0800
	 * @param    {[int] 	[data-id] 	[数据id]}
	 * @param    {[int] 	[data-state][状态值]}
	 * @param    {[string] 	[data-url] 	[请求地址]}
	 */
	$(document).on('click', '.submit-state', function()
	{		
		// 获取参数
		var $tag = $(this);
G
gongfuxiang 已提交
1597 1598 1599
		var id = $tag.attr('data-id');
		var state = ($tag.attr('data-state') == 1) ? 0 : 1;
		var url = $tag.attr('data-url');
1600
		var field = $tag.attr('data-field') || '';
G
gongfuxiang 已提交
1601
		var is_update_status = $tag.attr('data-is-update-status') || 0;
D
v1.2.0  
devil_gong 已提交
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
		if(id == undefined || url == undefined)
		{
			Prompt('参数配置有误');
			return false;
		}

		// 请求更新数据
		$.ajax({
			url:url,
			type:'POST',
			dataType:"json",
1613
			timeout:$tag.attr('data-timeout') || 30000,
D
v1.2.0  
devil_gong 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
			data:{"id":id, "state":state, "field":field},
			success:function(result)
			{
				if(result.code == 0)
				{
					Prompt(result.msg, 'success');

					// 成功则更新数据样式
					if($tag.hasClass('am-success'))
					{
						$tag.removeClass('am-success');
						$tag.addClass('am-default');
						if(is_update_status == 1)
						{
							if($('#data-list-'+id).length > 0)
							{
								$('#data-list-'+id).addClass('am-active');
							}
						}
					} else {
						$tag.removeClass('am-default');
						$tag.addClass('am-success');
						if(is_update_status == 1)
						{
							if($('#data-list-'+id).length > 0)
							{
								$('#data-list-'+id).removeClass('am-active');
							}
						}
					}
G
gongfuxiang 已提交
1644
					$tag.attr('data-state', state);
D
v1.2.0  
devil_gong 已提交
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
				} else {
					Prompt(result.msg);
				}
			},
			error:function(xhr, type)
			{
				Prompt('网络异常出错');
			}
		});
	});

	/**
	 * [submit-edit 公共编辑]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-14T13:53:13+0800
	 */
	$(document).on('click', '.submit-edit', function()
	{
		// 窗口标签
G
gongfuxiang 已提交
1666
		var tag = $(this).attr('data-tag') || 'data-save-win';
D
v1.2.0  
devil_gong 已提交
1667 1668 1669 1670 1671

		// 更改窗口名称
		if($('#'+tag).length > 0)
		{
			$title = $('#'+tag).find('.am-popup-title');
G
gongfuxiang 已提交
1672
			$title.text($title.attr('data-edit-title'));
D
v1.2.0  
devil_gong 已提交
1673 1674 1675
		}
		
		// 填充数据
G
gongfuxiang 已提交
1676
		var data = FunSaveWinAdditional($(this).data('json'), 'edit');
D
v1.2.0  
devil_gong 已提交
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694

		// 开始填充数据
		FormDataFill(data, '#'+tag);
	});

	/**
	 * [tree-submit-add-node 公共无限节点 - 新子节点]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-25T22:12:10+0800
	 */
	$('#tree').on('click', '.tree-submit-add-node', function()
	{
		// 清空表单数据
		TreeFormInit();

		// 父节点赋值
G
gongfuxiang 已提交
1695
		var id = parseInt($(this).attr('data-id')) || 0;
G
gongfuxiang 已提交
1696 1697 1698 1699 1700 1701 1702
		$('#data-save-win').find('input[name="pid"], select[name="pid"]').val(id);

		// 多选插件事件更新
		if($('.chosen-select').length > 0)
		{
			$('.chosen-select').trigger('chosen:updated');
		}
D
v1.2.0  
devil_gong 已提交
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
	});

	/**
	 * [tree-submit 公共无限节点]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-25T22:12:10+0800
	 */
	$('#tree').on('click', '.tree-submit', function()
	{
G
gongfuxiang 已提交
1714
		var id = parseInt($(this).attr('data-id')) || 0;
D
v1.2.0  
devil_gong 已提交
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
		// 状态
		if($('#data-list-'+id).find('.tree-submit').attr('state') == 'ok')
		{
			if($(this).hasClass('am-icon-plus'))
			{
				$(this).removeClass('am-icon-plus');
				$(this).addClass('am-icon-minus-square');
				$('.tree-pid-'+id).css('display', 'grid');
			} else {
				$(this).removeClass('am-icon-minus-square');
				$(this).addClass('am-icon-plus');
				$('.tree-pid-'+id).css('display', 'none');
			}
		} else {
G
gongfuxiang 已提交
1729 1730 1731 1732
			var url = $(this).attr('data-url') || '';
			var level = parseInt($(this).attr('data-level')) || 0;
			var is_add_node = parseInt($(this).attr('data-is_add_node')) || 0;
			var is_delete_all = parseInt($(this).attr('data-is_delete_all')) || 0;
D
v1.2.0  
devil_gong 已提交
1733 1734
			if(id > 0 && url != '')
			{
1735
				Tree(id, url, level, is_add_node, is_delete_all);
D
v1.2.0  
devil_gong 已提交
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
			} else {
				Prompt('参数有误');
			}
		}
	});

	/**
	 * [tree-submit-add 公共无限节点新增按钮处理]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-25T22:11:34+0800
	 */
	$('.tree-submit-add').on('click', function()
	{
		TreeFormInit();
	});

	/**
	 * [submit-ajax 公共数据ajax操作]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-10T14:22:39+0800
	 * @param    {[int] 	[data-id] 	[数据id]}
	 * @param    {[int] 	[data-view] [完成操作(delete删除数据, reload刷新页面, fun方法回调(data-value)]}
	 * @param    {[string] 	[data-url] 	[请求地址]}
	 */
	$(document).on('click', '.submit-ajax', function()
	{
G
gongfuxiang 已提交
1766
		var is_confirm = $(this).attr('data-is-confirm');
G
充值  
gongfuxiang 已提交
1767 1768 1769 1770 1771 1772
		if(is_confirm == undefined || is_confirm == 1)
		{
			ConfirmNetworkAjax($(this));
		} else {
			AjaxRequest($(this));
		}
D
v1.2.0  
devil_gong 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
	});

	// 地区联动
	$('.region-linkage select').on('change', function()
	{
		var name = $(this).attr('name') || null;
		var next_name = (name == 'province') ? 'city' : ((name == 'city') ? 'county' : null);
		var value = $(this).val() || null;
		if(next_name != null)
		{
			RegionNodeData(value, name, next_name);
		}
	});
	if($('.region-linkage select').length > 0)
	{
		// 省初始化
		RegionNodeData(0, 'province', 'province');

		// 市初始化
G
gongfuxiang 已提交
1792
		var value = $('.region-linkage select[name=province]').attr('data-value') || 0;
D
v1.2.0  
devil_gong 已提交
1793 1794 1795 1796 1797 1798
		if(value != 0)
		{
			RegionNodeData(value, 'city', 'city');
		}

		// 区/县初始化
G
gongfuxiang 已提交
1799
		var value = $('.region-linkage select[name=city]').attr('data-value') || 0;
D
v1.2.0  
devil_gong 已提交
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
		if(value != 0)
		{
			RegionNodeData(value, 'county', 'county');
		}
	}

	// 根据字符串地址获取坐标位置
	$('#map-location-submit').on('click', function()
	{
		var region = ["province", "city", "county"];
		var province = '';
		var address = '';
		for(var i in region)
		{
			var $temp_obj = $('.region-linkage select[name='+region[i]+']');
D
devil_gong 已提交
1815 1816
			var v = $temp_obj.find('option:selected').val() || null;
			if(v != null)
D
v1.2.0  
devil_gong 已提交
1817
			{
D
devil_gong 已提交
1818 1819 1820 1821 1822
				if(i == 0)
				{
					province = $temp_obj.find('option:selected').text() || '';
				}
				address += $temp_obj.find('option:selected').text() || '';
D
v1.2.0  
devil_gong 已提交
1823 1824 1825
			}
		}
		address += $('#form-address').val();
D
devil_gong 已提交
1826 1827 1828 1829 1830
		if(province.length <= 0 || address.length <= 0)
		{
			Prompt('地址为空');
			return false;
		}
D
v1.2.0  
devil_gong 已提交
1831 1832 1833 1834 1835 1836

		// 创建地址解析器实例
		var myGeo = new BMap.Geocoder();
		// 将地址解析结果显示在地图上,并调整地图视野
		myGeo.getPoint(address, function(point) {
			if (point) {
D
devil_gong 已提交
1837 1838
				MapInit(null, null, null, point);
			} else {
D
v1.2.0  
devil_gong 已提交
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
				Prompt("您选择地址没有解析到结果!");
			}
		}, province);
	});

	// 图片上传
    $(document).on('change', '.images-file-event, .file-event', function()
    {
    	// 显示选择的图片名称
        var fileNames = '';
        $.each(this.files, function()
        {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
        });
G
gongfuxiang 已提交
1853
        $($(this).attr('data-tips-tag')).html(fileNames);
D
v1.2.0  
devil_gong 已提交
1854 1855

        // 触发配合显示input地址事件
G
gongfuxiang 已提交
1856
        var input_tag = $(this).attr('data-choice-one-to') || null;
D
v1.2.0  
devil_gong 已提交
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
        if(input_tag != null)
        {
        	$(input_tag).trigger('blur');
        }
    });

    // 图片预览
    if($('.images-file-event').length > 0)
    {
    	ImageFileUploadShow('.images-file-event');
    }

    // 视频上传
    $(document).on('change', '.video-file-event', function()
    {
    	// 显示选择的图片名称
        var fileNames = '';
        $.each(this.files, function()
        {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
        });
G
gongfuxiang 已提交
1878
        $($(this).attr('data-tips-tag')).html(fileNames);
D
v1.2.0  
devil_gong 已提交
1879 1880

        // 触发配合显示input地址事件
G
gongfuxiang 已提交
1881
        var input_tag = $(this).attr('data-choice-one-to') || null;
D
v1.2.0  
devil_gong 已提交
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
        if(input_tag != null)
        {
        	$(input_tag).trigger('blur');
        }
    });

    // 视频预览
    if($('.video-file-event').length > 0)
    {
    	VideoFileUploadShow('.video-file-event');
    }


	// 颜色选择器
	if($('.colorpicker-submit').length > 0)
	{
	    $('.colorpicker-submit').colorpicker(
	    {
	        fillcolor:true,
	        success:function(o, color)
	        {
	        	var style = o.context.dataset.colorStyle || 'color';
	            $(o.context.dataset.inputTag).css(style, color);
	            $(o.context.dataset.colorTag).val(color);
D
devil_gong 已提交
1906
	            $(o.context.dataset.colorTag).trigger('change');
D
v1.2.0  
devil_gong 已提交
1907 1908 1909 1910 1911 1912
	        },
	        reset:function(o)
	        {
	        	var style = o.context.dataset.colorStyle || 'color';
	            $(o.context.dataset.inputTag).css(style, '');
	            $(o.context.dataset.colorTag).val('');
D
devil_gong 已提交
1913
	            $(o.context.dataset.colorTag).trigger('change');
D
v1.2.0  
devil_gong 已提交
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
	        }
	    });
	}


    // 监听多图上传和上传附件组件的插入动作
    if(typeof(upload_editor) == 'object')
    {
	    upload_editor.ready(function()
	    {
	        // 图片上传动作
	        upload_editor.addListener("beforeInsertImage", function(t, result)
	        {
	            if(result.length > 0)
	            {
	                var $tag = $($('body').attr('view-tag'));
G
gongfuxiang 已提交
1930 1931 1932 1933
	                var max_number = $tag.attr('data-max-number') || 0;
	                var is_delete = ($tag.attr('data-delete') == undefined) ? 1 : $tag.attr('data-delete');
	                var form_name = $tag.attr('data-form-name') || '';
	                var is_attr = $tag.attr('data-is-attr') || null;
D
v1.2.0  
devil_gong 已提交
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943

	                // 只限制一条
	                if(max_number <= 1)
	                {
	                    $tag.find('li').remove();
	                }

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
1944 1945 1946
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
1947
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
1948 1949 1950 1951 1952
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
1953 1954 1955 1956 1957 1958 1959
	                    if(max_number > 0 && $tag.find('li').length >= max_number)
	                    {
	                        Prompt('最多上传'+max_number+'张图片');
	                        break;
	                    }

	                    var html = '<li>';
G
gongfuxiang 已提交
1960
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
	                        html += '<img src="'+result[i].src+'" />';
	                        if(is_delete == 1)
	                        {
	                        	html += '<i>×</i>';
	                        }
	                        html += '</li>';
	                    $tag.append(html);
	                }
	            }
	        });

	        // 视频上传
	        upload_editor.addListener("beforeInsertVideo", function(t, result)
	        {
	            if(result.length > 0)
	            {
	                var $tag = $($('body').attr('view-tag'));
G
gongfuxiang 已提交
1978 1979 1980 1981
	                var max_number = $tag.attr('data-max-number') || 0;
	                var is_delete = ($tag.attr('data-delete') == undefined) ? 1 : $tag.attr('data-delete');
	                var form_name = $tag.attr('data-form-name') || '';
	                var is_attr = $tag.attr('data-is-attr') || null;
D
v1.2.0  
devil_gong 已提交
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991

	                // 只限制一条
	                if(max_number <= 1)
	                {
	                    $tag.find('li').remove();
	                }

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
1992 1993 1994
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
1995
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
1996 1997 1998 1999 2000
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
2001 2002 2003 2004 2005 2006 2007 2008
	                    if(max_number > 0 && $tag.find('li').length >= max_number)
	                    {
	                        Prompt('最多上传'+max_number+'个视频');
	                        break;
	                    }

	                    var $tag = $($('body').attr('view-tag'));
	                    var html = '<li>';
G
gongfuxiang 已提交
2009
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032
	                        html += '<video src="'+result[i].src+'" controls>your browser does not support the video tag</video>';
	                        if(is_delete == 1)
	                        {
	                        	html += '<i>×</i>';
	                        }
	                        html += '</li>';
	                    $tag.append(html);
	                }
	            }
	        });

	        // 文件上传
	        upload_editor.addListener("beforeInsertFile", function(t, result)
	        {
	            var fileHtml = '';
	            for(var i in result){
	                fileHtml += '<li><a href="'+result[i].url+'" target="_blank">'+result[i].url+'</a></li>';
	            }
	            document.getElementById('upload_video_wrap').innerHTML = fileHtml;

	            if(result.length > 0)
	            {
	                var $tag = $($('body').attr('view-tag'));
G
gongfuxiang 已提交
2033 2034 2035 2036
	                var max_number = $tag.attr('data-max-number') || 0;
	                var is_delete = ($tag.attr('data-delete') == undefined) ? 1 : $tag.attr('data-delete');
	                var form_name = $tag.attr('data-form-name') || '';
	                var is_attr = $tag.attr('data-is-attr') || null;
D
v1.2.0  
devil_gong 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046

	                // 只限制一条
	                if(max_number <= 1)
	                {
	                    $tag.find('li').remove();
	                }

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
2047 2048 2049
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
2050
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
2051 2052 2053 2054 2055
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
2056 2057 2058 2059 2060 2061 2062 2063
	                    if(max_number > 0 && $tag.find('li').length >= max_number)
	                    {
	                        Prompt('最多上传'+max_number+'个附件');
	                        break;
	                    }

	                    var $tag = $($('body').attr('view-tag'));
	                    var html = '<li>';
G
gongfuxiang 已提交
2064
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
	                        html += '<a href="'+result[i].src+'">'+result[i].src+'</a>';
	                        if(is_delete == 1)
	                        {
	                        	html += '<i>×</i>';
	                        }
	                        html += '</li>';
	                    $tag.append(html);
	                }
	            }
	        });
	    });
	}

    // 打开编辑器插件
    $(document).on('click', '.plug-file-upload-submit', function()
    {
    	// 组件是否初始化
    	if(typeof(upload_editor) != 'object')
    	{
    		Prompt('组件未初始化');
            return false;
    	}

    	// 容器是否指定
G
gongfuxiang 已提交
2089
        if(($(this).attr('data-view-tag') || null) == null)
D
v1.2.0  
devil_gong 已提交
2090 2091 2092 2093 2094 2095
        {
            Prompt('未指定容器');
            return false;
        }

        // 容器
G
gongfuxiang 已提交
2096
        var $view_tag = $($(this).attr('data-view-tag'));
D
v1.2.0  
devil_gong 已提交
2097 2098 2099

        // 加载组建类型
        var dialog_type = null;
G
gongfuxiang 已提交
2100
        switch($view_tag.attr('data-dialog-type'))
D
v1.2.0  
devil_gong 已提交
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
        {
            // 视频
            case 'video' :
                dialog_type = 'insertvideo';
                break;

            // 图片
            case 'images' :
                dialog_type = 'insertimage';
                break;

            // 文件
            case 'file' :
                dialog_type = 'attachment';
                break;
        }
        if(dialog_type == null)
        {
            Prompt('未指定加载组建');
            return false;
        }

        // 是否指定form名称
G
gongfuxiang 已提交
2124
        if(($view_tag.attr('data-form-name') || null) == null)
D
v1.2.0  
devil_gong 已提交
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
        {
            Prompt('未指定表单name名称');
            return false;
        }

        // 打开组建
        var dialog = upload_editor.getDialog(dialog_type);
        dialog.render();
        dialog.open();

        // 赋值参数
G
gongfuxiang 已提交
2136
        $('body').attr('view-tag',$(this).attr('data-view-tag'));
D
v1.2.0  
devil_gong 已提交
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148
    });

    // 删除容器中的内容
    $(document).on('click', '.plug-file-upload-view li i', function()
    {
        // 容器
        var $tag = $(this).parents('ul.plug-file-upload-view');

        // 删除数据
        $(this).parent().remove();

        // 数据处理
G
gongfuxiang 已提交
2149
        var max_number = $tag.attr('data-max-number') || 0;
D
v1.2.0  
devil_gong 已提交
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182
        if(max_number > 0)
        {
            if($tag.find('li').length < max_number)
            {
                $('.plug-file-upload-submit').show();
            }
        }
    });


    /* 搜索切换 */
	var $more_where = $('.more-where');
	$more_submit = $('.more-submit');
	$more_submit.find('input[name="is_more"]').change(function()
	{
		if($more_submit.find('i').hasClass('am-icon-angle-down'))
		{
			$more_submit.find('i').removeClass('am-icon-angle-down');
			$more_submit.find('i').addClass('am-icon-angle-up');
		} else {
			$more_submit.find('i').addClass('am-icon-angle-down');
			$more_submit.find('i').removeClass('am-icon-angle-up');
		}
	
		if($more_submit.find('input[name="is_more"]:checked').val() == undefined)
		{
			$more_where.addClass('none');
		} else {
			$more_where.removeClass('none');
		}
	});

});