common.js 59.7 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

	// 是否需要返回json对象
	if(is_json === true)
	{
		var json = {};
D
devil_gong 已提交
149 150 151 152 153 154 155
		object.forEach(function(value, key)
		{
			if((key || null) != null)
			{
				json[key] = value
			}
		});
G
gongfuxiang 已提交
156 157
		return json;
	}
D
v1.2.0  
devil_gong 已提交
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 229 230 231 232 233 234
	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 已提交
235 236 237 238
	if($form.length <= 0)
	{
		return false;
	}
D
v1.2.0  
devil_gong 已提交
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
	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 已提交
263
				var tag = $(validity.field).attr('data-choice-one-to');
D
v1.2.0  
devil_gong 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
				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 已提交
280
			var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
D
v1.2.0  
devil_gong 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
			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 已提交
299 300
					var msg = $editor_tag.data('validationMessage') || $editor_tag.getValidationMessage(validity);
					console.log(msg);
D
v1.2.0  
devil_gong 已提交
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 358 359 360 361 362 363
					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 已提交
364 365 366 367 368
				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 已提交
369

G
gongfuxiang 已提交
370
				// 是form表单直接通过
D
v1.2.0  
devil_gong 已提交
371 372 373 374 375 376
				if(request_type == 'form')
				{
					return true;
				}

				// 参数校验
G
gongfuxiang 已提交
377
				if(ajax_all.indexOf(request_type) == -1)
D
v1.2.0  
devil_gong 已提交
378 379
				{
	            	$button.button('reset');
G
gongfuxiang 已提交
380
	            	Prompt('表单[类型]参数配置有误');
D
v1.2.0  
devil_gong 已提交
381 382 383 384
	            	return false;
				}

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

G
gongfuxiang 已提交
392 393 394 395 396 397
				// 同步调用方法
				if(request_type == 'sync')
				{
            		$button.button('reset');
					if(IsExitsFunction(request_value))
            		{
D
devil_gong 已提交
398
            			window[request_value](GetFormVal(form_name, true));
G
gongfuxiang 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
            		} 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 已提交
415 416 417 418 419
				// ajax请求
				$.ajax({
					url:action,
					type:method,
	                dataType:"json",
G
gongfuxiang 已提交
420
	                timeout:$form.attr('timeout') || 30000,
D
v1.2.0  
devil_gong 已提交
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 464 465 466 467 468 469
	                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 已提交
470
		            	Prompt('服务器错误');
D
v1.2.0  
devil_gong 已提交
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 505 506 507 508 509 510
		            }
	            });
			}
			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 已提交
511 512 513 514 515 516 517 518 519 520
		// 是否存在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 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
		// 多选插件事件更新
		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 已提交
547
		timeout:30000,
D
v1.2.0  
devil_gong 已提交
548 549 550 551 552 553 554
		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 已提交
555
				var is_astrict_rank = parseInt($('#tree').attr('data-rank')) || 0;
D
v1.2.0  
devil_gong 已提交
556 557 558 559 560 561 562 563 564 565 566 567
				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')
					{
568
						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 已提交
569 570 571 572 573 574 575 576 577 578 579
						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 已提交
580
						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 已提交
581 582 583 584 585 586 587 588 589 590 591 592
					}
					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 已提交
593
						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 已提交
594 595 596
					}

					// 编辑
G
gongfuxiang 已提交
597
					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 已提交
598 599
					if(result.data[i]['is_son'] != 'ok' || is_delete_all == 1)
					{
600 601 602
						// 是否需要删除子数据
						var pid_class = is_delete_all == 1 ? '.tree-pid-'+result.data[i]['id'] : '';

D
v1.2.0  
devil_gong 已提交
603
						// 删除
G
gongfuxiang 已提交
604
						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 已提交
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 643 644 645 646 647 648
					}
					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 已提交
649
		show_img = $(this).attr('data-image-tag') || null;
D
v1.2.0  
devil_gong 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
		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 已提交
673
		var default_img = $(show_img).attr('data-default') || null;
D
v1.2.0  
devil_gong 已提交
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
		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 已提交
691
		show_video = $(this).attr('data-video-tag') || null;
D
v1.2.0  
devil_gong 已提交
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
		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 已提交
715
		var default_video = $(show_video).attr('data-default') || null;
D
v1.2.0  
devil_gong 已提交
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
		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>';
D
devil 已提交
784
	    html += '<iframe src="'+url+'" width="100%" height="100%"></iframe>';
D
v1.2.0  
devil_gong 已提交
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 824 825 826 827 828 829
		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 已提交
830 831 832 833 834
	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 已提交
835

D
devil_gong 已提交
836 837 838 839 840 841 842 843 844 845 846
	if((id || null) == null || (url || null) == null)
	{
		Prompt('参数配置有误');
		return false;
	}

	// 请求删除数据
	$.ajax({
		url:url,
		type:'POST',
		dataType:"json",
847
		timeout:e.attr('data-timeout') || 30000,
D
devil_gong 已提交
848 849
		data:{"id":id},
		success:function(result)
D
v1.2.0  
devil_gong 已提交
850
		{
D
devil_gong 已提交
851
			if(result.code == 0)
D
v1.2.0  
devil_gong 已提交
852
			{
D
devil_gong 已提交
853 854 855 856 857 858 859 860 861
				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 已提交
862
						{
D
devil_gong 已提交
863 864 865
							$(ext_delete_tag).remove();
						}
						break;
D
v1.2.0  
devil_gong 已提交
866

D
devil_gong 已提交
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
					// 刷新
					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 已提交
893
							{
D
devil_gong 已提交
894 895
								window.location.href = value;
							}, 1500);
D
v1.2.0  
devil_gong 已提交
896
						}
D
devil_gong 已提交
897 898 899 900 901 902 903 904 905 906
						break;

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

D
devil_gong 已提交
916 917 918 919 920 921 922 923 924 925
/**
 * [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 已提交
926 927 928
	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 已提交
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945

	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 已提交
946
/**
G
充值  
gongfuxiang 已提交
947
 * [AjaxRequest ajax网络请求]
D
v1.2.0  
devil_gong 已提交
948 949 950
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
G
充值  
gongfuxiang 已提交
951
 * @datetime 2019-04-30T00:25:21+0800
D
v1.2.0  
devil_gong 已提交
952 953
 * @param    {[object]}                 e [当前元素对象]
 */
G
充值  
gongfuxiang 已提交
954
function AjaxRequest(e)
D
v1.2.0  
devil_gong 已提交
955
{
G
gongfuxiang 已提交
956 957 958 959 960
	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 已提交
961 962 963 964 965 966

	// ajax
	$.ajax({
		url:url,
		type:'POST',
		dataType:"json",
967
		timeout:e.attr('data-timeout') || 30000,
D
devil_gong 已提交
968
		data:{"id":id, "value": value, "field": field},
G
充值  
gongfuxiang 已提交
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 1019 1020 1021 1022 1023 1024
		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 已提交
1025 1026
	var title = e.attr('data-title') || '温馨提示';
	var msg = e.attr('data-msg') || '操作后不可恢复、确认继续吗?';
D
v1.2.0  
devil_gong 已提交
1027 1028 1029 1030

	AMUI.dialog.confirm({
		title: title,
		content: msg,
D
devil_gong 已提交
1031
		onConfirm: function(result)
D
v1.2.0  
devil_gong 已提交
1032
		{
G
充值  
gongfuxiang 已提交
1033
			AjaxRequest(e);
D
v1.2.0  
devil_gong 已提交
1034 1035 1036 1037 1038
		},
		onCancel: function(){}
	});
}

D
devil_gong 已提交
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 1090 1091 1092 1093 1094 1095
/**
 * 开启全屏
 * @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 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
/**
 * 全屏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 已提交
1113
			$fullscreen.find('.fullscreen-text').text($fullscreen.attr('data-fulltext-open') || '开启全屏');
G
gongfuxiang 已提交
1114 1115 1116 1117 1118
			$fullscreen.attr('data-status', 0);
		}
	}
}

D
devil_gong 已提交
1119 1120 1121 1122 1123 1124 1125 1126
/**
 * url参数替换,参数不存在则添加
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-03-20
 * @desc    description
 * @param   {[string]}        field [字段名称]
D
devil 已提交
1127
 * @param   {[string]}        value [字段值, null 则去除字段]
D
devil_gong 已提交
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
 * @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('/')) : '';
D
devil 已提交
1153 1154 1155 1156 1157 1158
                if(value === null)
                {
                	url = first+last+ext;
                } else {
                	url = first+field+'/'+value+last+ext;
                }
D
devil_gong 已提交
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
        } 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)
                            {
D
devil 已提交
1179 1180 1181 1182
                            	if(value !== null)
                            	{
                            		p += field+'='+value;
                            	}
D
devil_gong 已提交
1183 1184 1185 1186 1187 1188
                            } else {
                                p += params_all[i];
                            }
                        }
                    }
                } else {
D
devil 已提交
1189 1190 1191 1192 1193 1194
                	if(value === null)
                	{
                		p = exts;
                	} else {
                		p = exts+'&'+field+'='+value;
                	}
D
devil_gong 已提交
1195 1196 1197
                }
                url = str+(ext.substr(0, ext.indexOf('?')))+'?'+p;
            } else {
D
devil 已提交
1198 1199 1200 1201 1202 1203
            	if(value === null)
            	{
            		url = str+ext;
            	} else {
            		url = str+'/'+field+'/'+value+ext;
            	}
D
devil_gong 已提交
1204 1205 1206
            }
        }
    } else {
D
devil 已提交
1207 1208 1209 1210
    	if(value !== null)
    	{
    		url += '?'+field+'='+value;
    	}
D
devil_gong 已提交
1211 1212 1213 1214
    }
    return url+anchor;
}

G
share  
gongfuxiang 已提交
1215
/**
G
share  
gongfuxiang 已提交
1216
 * 当前手机浏览器环境
G
share  
gongfuxiang 已提交
1217 1218 1219 1220
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2019-04-20T19:48:59+0800
G
share  
gongfuxiang 已提交
1221
 * @return   {string} [weixin,weibo,qq]
G
share  
gongfuxiang 已提交
1222
 */
G
share  
gongfuxiang 已提交
1223
function MobileBrowserEnvironment()
G
share  
gongfuxiang 已提交
1224
{
G
share  
gongfuxiang 已提交
1225
	// 浏览器标识
G
share  
gongfuxiang 已提交
1226
	var ua = navigator.userAgent.toLowerCase();
G
share  
gongfuxiang 已提交
1227 1228

	// 微信
G
share  
gongfuxiang 已提交
1229
	if(ua.match(/MicroMessenger/i) == 'micromessenger')
G
share  
gongfuxiang 已提交
1230
	{
G
share  
gongfuxiang 已提交
1231 1232
		return 'weixin';
	}
G
share  
gongfuxiang 已提交
1233

G
share  
gongfuxiang 已提交
1234
	// 新浪微博
G
share  
gongfuxiang 已提交
1235 1236 1237 1238
	if(ua.match(/WeiBo/i) == 'weibo')
	{
		return 'weibo';
	}
G
share  
gongfuxiang 已提交
1239

G
share  
gongfuxiang 已提交
1240 1241 1242 1243 1244 1245 1246
	// QQ空间
	if(ua.match(/qzone/i) == 'qzone')
	{
		return 'qzone';
	}

	// QQ
G
share  
gongfuxiang 已提交
1247 1248 1249
	if(ua.match(/QQ/i) == 'qq')
	{
		return 'qq';
G
share  
gongfuxiang 已提交
1250
	}
G
share  
gongfuxiang 已提交
1251
	return null;
G
share  
gongfuxiang 已提交
1252 1253
}

G
gongfuxiang 已提交
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 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
/**
 * [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 已提交
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 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
/**
 * [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 已提交
1487 1488 1489 1490 1491 1492 1493
/**
 * 地图初始化
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2019-11-12
 * @desc    description
D
devil_gong 已提交
1494 1495 1496 1497 1498
 * @param   {[float]}        	lng   		[经度]
 * @param   {[float]}        	lat   		[维度]
 * @param   {[int]}        		level 		[层级]
 * @param   {[object]}        	point 		[中心对象]
 * @param   {[boolean]}        	is_dragend 	[标注是否可拖拽]
D
devil_gong 已提交
1499
 */
D
devil_gong 已提交
1500
function MapInit(lng, lat, level, point, is_dragend)
D
devil_gong 已提交
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
{
	// 百度地图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);

    // 创建标注
D
devil_gong 已提交
1518 1519 1520
    // 将标注添加到地图中
    var marker = new BMap.Marker(point);
    map.addOverlay(marker);
D
devil_gong 已提交
1521

D
devil_gong 已提交
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
    // 标注是否可拖拽
    if(is_dragend == undefined || is_dragend == true)
    {
    	marker.enableDragging();
	    marker.addEventListener("dragend", function(e) {
	        map.panTo(e.point);
	        if($('#form-lng').length > 0 && $('#form-lat').length > 0)
		    {
		    	$('#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});
    }
D
devil_gong 已提交
1541 1542 1543

    //获取地址坐标
    var p = marker.getPosition();
D
devil_gong 已提交
1544 1545 1546 1547 1548
    if($('#form-lng').length > 0 && $('#form-lat').length > 0)
    {
    	$('#form-lng').val(p.lng);
		$('#form-lat').val(p.lat);
    }
D
devil_gong 已提交
1549 1550
}

D
Devil 已提交
1551

D
v1.2.0  
devil_gong 已提交
1552 1553 1554
// 公共数据操作
$(function()
{
D
devil_gong 已提交
1555 1556 1557 1558 1559 1560 1561 1562
	// 全屏操作
	$('.fullscreen-event').on('click', function()
	{
		var status = $(this).attr('data-status') || 0;
		if(status == 0)
		{
			if(FullscreenOpen())
			{
G
gongfuxiang 已提交
1563
				$(this).find('.fullscreen-text').text($(this).attr('data-fulltext-exit') || '退出全屏');
D
devil_gong 已提交
1564 1565 1566 1567
			}
		} else {
			if(FullscreenExit())
			{
G
gongfuxiang 已提交
1568
				$(this).find('.fullscreen-text').text($(this).attr('data-fulltext-open') || '开启全屏');
D
devil_gong 已提交
1569 1570 1571
			}
		}
		$(this).attr('data-status', status == 0 ? 1 : 0);
G
gongfuxiang 已提交
1572 1573 1574 1575 1576 1577
		$(this).attr('data-status-y', status);
	});
	
	// esc退出全屏事件
	document.addEventListener("fullscreenchange", function(e) {
	  FullscreenEscEvent();
D
devil_gong 已提交
1578
	});
G
gongfuxiang 已提交
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
	document.addEventListener("mozfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});
	document.addEventListener("webkitfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});
	document.addEventListener("msfullscreenchange", function(e) {
	  FullscreenEscEvent();
	});

D
devil_gong 已提交
1589

D
v1.2.0  
devil_gong 已提交
1590 1591 1592 1593 1594 1595
	// 多选插件初始化
	if($('.chosen-select').length > 0)
	{
		$('.chosen-select').chosen({
			inherit_select_classes: true,
			enable_split_word_search: true,
D
devil_gong 已提交
1596 1597
			search_contains: true,
			no_results_text: '没有匹配到结果'
D
v1.2.0  
devil_gong 已提交
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
		});
	}
	// 多选插件 空内容失去焦点验证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 已提交
1620
		ConfirmDataDelete($(this));
D
v1.2.0  
devil_gong 已提交
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
	});

	/**
	 * [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 已提交
1637 1638 1639
		var id = $tag.attr('data-id');
		var state = ($tag.attr('data-state') == 1) ? 0 : 1;
		var url = $tag.attr('data-url');
1640
		var field = $tag.attr('data-field') || '';
G
gongfuxiang 已提交
1641
		var is_update_status = $tag.attr('data-is-update-status') || 0;
D
v1.2.0  
devil_gong 已提交
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652
		if(id == undefined || url == undefined)
		{
			Prompt('参数配置有误');
			return false;
		}

		// 请求更新数据
		$.ajax({
			url:url,
			type:'POST',
			dataType:"json",
1653
			timeout:$tag.attr('data-timeout') || 30000,
D
v1.2.0  
devil_gong 已提交
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
			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 已提交
1684
					$tag.attr('data-state', state);
D
v1.2.0  
devil_gong 已提交
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
				} 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 已提交
1706
		var tag = $(this).attr('data-tag') || 'data-save-win';
D
v1.2.0  
devil_gong 已提交
1707 1708 1709 1710 1711

		// 更改窗口名称
		if($('#'+tag).length > 0)
		{
			$title = $('#'+tag).find('.am-popup-title');
G
gongfuxiang 已提交
1712
			$title.text($title.attr('data-edit-title'));
D
v1.2.0  
devil_gong 已提交
1713 1714 1715
		}
		
		// 填充数据
G
gongfuxiang 已提交
1716
		var data = FunSaveWinAdditional($(this).data('json'), 'edit');
D
v1.2.0  
devil_gong 已提交
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734

		// 开始填充数据
		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 已提交
1735
		var id = parseInt($(this).attr('data-id')) || 0;
G
gongfuxiang 已提交
1736 1737 1738 1739 1740 1741 1742
		$('#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 已提交
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
	});

	/**
	 * [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 已提交
1754
		var id = parseInt($(this).attr('data-id')) || 0;
D
v1.2.0  
devil_gong 已提交
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
		// 状态
		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 已提交
1769 1770 1771 1772
			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 已提交
1773 1774
			if(id > 0 && url != '')
			{
1775
				Tree(id, url, level, is_add_node, is_delete_all);
D
v1.2.0  
devil_gong 已提交
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
			} 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 已提交
1806
		var is_confirm = $(this).attr('data-is-confirm');
G
充值  
gongfuxiang 已提交
1807 1808 1809 1810 1811 1812
		if(is_confirm == undefined || is_confirm == 1)
		{
			ConfirmNetworkAjax($(this));
		} else {
			AjaxRequest($(this));
		}
D
v1.2.0  
devil_gong 已提交
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
	});

	// 地区联动
	$('.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 已提交
1832
		var value = $('.region-linkage select[name=province]').attr('data-value') || 0;
D
v1.2.0  
devil_gong 已提交
1833 1834 1835 1836 1837 1838
		if(value != 0)
		{
			RegionNodeData(value, 'city', 'city');
		}

		// 区/县初始化
G
gongfuxiang 已提交
1839
		var value = $('.region-linkage select[name=city]').attr('data-value') || 0;
D
v1.2.0  
devil_gong 已提交
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854
		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 已提交
1855 1856
			var v = $temp_obj.find('option:selected').val() || null;
			if(v != null)
D
v1.2.0  
devil_gong 已提交
1857
			{
D
devil_gong 已提交
1858 1859 1860 1861 1862
				if(i == 0)
				{
					province = $temp_obj.find('option:selected').text() || '';
				}
				address += $temp_obj.find('option:selected').text() || '';
D
v1.2.0  
devil_gong 已提交
1863 1864 1865
			}
		}
		address += $('#form-address').val();
D
devil_gong 已提交
1866 1867 1868 1869 1870
		if(province.length <= 0 || address.length <= 0)
		{
			Prompt('地址为空');
			return false;
		}
D
v1.2.0  
devil_gong 已提交
1871 1872 1873 1874 1875 1876

		// 创建地址解析器实例
		var myGeo = new BMap.Geocoder();
		// 将地址解析结果显示在地图上,并调整地图视野
		myGeo.getPoint(address, function(point) {
			if (point) {
D
devil_gong 已提交
1877 1878
				MapInit(null, null, null, point);
			} else {
D
v1.2.0  
devil_gong 已提交
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
				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 已提交
1893
        $($(this).attr('data-tips-tag')).html(fileNames);
D
v1.2.0  
devil_gong 已提交
1894 1895

        // 触发配合显示input地址事件
G
gongfuxiang 已提交
1896
        var input_tag = $(this).attr('data-choice-one-to') || null;
D
v1.2.0  
devil_gong 已提交
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
        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 已提交
1918
        $($(this).attr('data-tips-tag')).html(fileNames);
D
v1.2.0  
devil_gong 已提交
1919 1920

        // 触发配合显示input地址事件
G
gongfuxiang 已提交
1921
        var input_tag = $(this).attr('data-choice-one-to') || null;
D
v1.2.0  
devil_gong 已提交
1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
        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 已提交
1946
	            $(o.context.dataset.colorTag).trigger('change');
D
v1.2.0  
devil_gong 已提交
1947 1948 1949 1950 1951 1952
	        },
	        reset:function(o)
	        {
	        	var style = o.context.dataset.colorStyle || 'color';
	            $(o.context.dataset.inputTag).css(style, '');
	            $(o.context.dataset.colorTag).val('');
D
devil_gong 已提交
1953
	            $(o.context.dataset.colorTag).trigger('change');
D
v1.2.0  
devil_gong 已提交
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969
	        }
	    });
	}


    // 监听多图上传和上传附件组件的插入动作
    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 已提交
1970 1971 1972 1973
	                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 已提交
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983

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

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
1984 1985 1986
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
1987
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
1988 1989 1990 1991 1992
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
1993 1994 1995 1996 1997 1998 1999
	                    if(max_number > 0 && $tag.find('li').length >= max_number)
	                    {
	                        Prompt('最多上传'+max_number+'张图片');
	                        break;
	                    }

	                    var html = '<li>';
G
gongfuxiang 已提交
2000
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
	                        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 已提交
2018 2019 2020 2021
	                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 已提交
2022 2023 2024 2025 2026 2027 2028 2029 2030 2031

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

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
2032 2033 2034
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
2035
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
2036 2037 2038 2039 2040
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
2041 2042 2043 2044 2045 2046 2047 2048
	                    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 已提交
2049
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072
	                        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 已提交
2073 2074 2075 2076
	                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 已提交
2077 2078 2079 2080 2081 2082 2083 2084 2085 2086

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

	                // 循环处理
	                for(var i in result)
	                {
D
devil_gong 已提交
2087 2088 2089
	                	// 是否直接赋值属性
	                	if(i == 0 && is_attr != null)
	                	{
G
gongfuxiang 已提交
2090
	                		$('form [name="'+form_name+'"]').val(result[i].src);
D
devil_gong 已提交
2091 2092 2093 2094 2095
	                		$tag.attr(is_attr, result[i].src);
	                		break;
	                	}

	                	// 是否限制数量
D
v1.2.0  
devil_gong 已提交
2096 2097 2098 2099 2100 2101 2102 2103
	                    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 已提交
2104
	                        html += '<input type="text" name="'+form_name+'" value="'+result[i].src+'" />';
D
v1.2.0  
devil_gong 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
	                        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 已提交
2129
        if(($(this).attr('data-view-tag') || null) == null)
D
v1.2.0  
devil_gong 已提交
2130 2131 2132 2133 2134 2135
        {
            Prompt('未指定容器');
            return false;
        }

        // 容器
G
gongfuxiang 已提交
2136
        var $view_tag = $($(this).attr('data-view-tag'));
D
v1.2.0  
devil_gong 已提交
2137 2138 2139

        // 加载组建类型
        var dialog_type = null;
G
gongfuxiang 已提交
2140
        switch($view_tag.attr('data-dialog-type'))
D
v1.2.0  
devil_gong 已提交
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
        {
            // 视频
            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 已提交
2164
        if(($view_tag.attr('data-form-name') || null) == null)
D
v1.2.0  
devil_gong 已提交
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
        {
            Prompt('未指定表单name名称');
            return false;
        }

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

        // 赋值参数
G
gongfuxiang 已提交
2176
        $('body').attr('view-tag',$(this).attr('data-view-tag'));
D
v1.2.0  
devil_gong 已提交
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188
    });

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

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

        // 数据处理
G
gongfuxiang 已提交
2189
        var max_number = $tag.attr('data-max-number') || 0;
D
v1.2.0  
devil_gong 已提交
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
        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');
		}
	});

});