<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="webkit" name="renderer" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="PoweredByJeeSiteV4.0" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta name="description" content="PoweredByJeeSiteV4.0" />
<meta content="no-cache" http-equiv="Pragma" />
<meta http-equiv="Expires" content="0" />
<meta content="width=device-width, initial-scale=1, user-scalable=1" name="viewport" />
<title>公司管理 - JeeSite Demo</title>
<script th:src="${setting.domain + 'global.min.js'}"></script>
<script th:src="${setting.domain + 'jquery/jquery-1.12.4.min.js'}"></script>
<script th:src="${setting.domain + 'jquery/jquery-migrate-1.4.1.min.js'}"></script>
<!--[if lt IE 9]><script src="/js/static/common/h5fix.min.js"></script><![endif]-->
<link rel="stylesheet" th:href="${setting.domain + 'fonts/font-icons.min.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'bootstrap/css/bootstrap.min.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'select2/4.0/select2.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'icheck/1.0/minimal/grey.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'adminlte/css/AdminLTE.min.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'common/jeesite.css'}">
<link rel="stylesheet" th:href="${setting.domain + 'common/common.css'}">
</head>
<body class="hold-transition ">
	<div class="wrapper">
		<div class="main-content">
			<div class="box box-main">
				<div class="box-header">
					<div class="box-title">
						<i class="fa icon-fire"></i> 编辑公司
					</div>
					<div class="box-tools pull-right">
						<button type="button" class="btn btn-box-tool"
							data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<form id="inputForm" action="/js/a/sys/company/save" method="post"
					class="form-horizontal">
					<div class="box-body">
						<div class="form-unit">基本信息</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4">上级公司：</label>
									<div class="col-sm-8">
										<div class="input-group treeselect" id="parentDiv">
											<input id="parentCode" type="hidden" name="parentCode" v-model="company.parentCode" class="isReset" /> 
											<input id="parentName" type="text" name="parentName" v-model="company.parentName" class="form-control" readonly="readonly" />
											<span class="input-group-btn">
												<a id="parentButton" @click="showCompanyDialog" href="javascript:" class="btn btn-default ">
													<i class="fa fa-search"></i>
												</a> 
											</span>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> <span
										class="required ">*</span> 公司名称：<i
										class="fa icon-question hide"></i></label>
									<div class="col-sm-8">
										<input type="text" id="name" name="name"
											v-model="company.name" maxlength="200" class="form-control required " @change="changeCompanyName"/>
									</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> <span
										class="required ">*</span> 公司编码：<i
										class="fa icon-question hide"></i></label>
										<div class="col-sm-8">
											<input type="text" id="code" name="code" v-model="company.id" maxlength="64" class="form-control required abc" />
										</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> 
										<span class="required ">*</span> 公司全称：<i class="fa icon-question hide"></i></label>
										<div class="col-sm-8">
											<input type="text" id="fullName" name="fullName" v-model="company.fullName" maxlength="200" class="form-control required " />
										</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> <span
										class="required ">*</span> 排序号：<i
										class="fa icon-question hide"></i></label>
									<div class="col-sm-8">
										<input type="text" id="treeSort" name="treeSort" value="30"
											maxlength="10" class="form-control required digits" />
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> <span
										class="required hide">*</span> 归属区域：<i
										class="fa icon-question hide"></i></label>
									<div class="col-sm-8">
										<div class="input-group treeselect" id="areaDiv"
											data-url="/js/a/sys/area/treeData">
											<input id="areaCode" type="hidden" name="area.areaCode"
												value="" class="isReset" /> <input id="areaName" type="text"
												name="area.areaName" value="" class="form-control   "
												readonly="readonly" /><span class="input-group-btn"><a
												id="areaButton" href="javascript:" class="btn btn-default "><i
													class="fa fa-search"></i></a> </span>
										</div>
										<script>
											$("#areaButton,#areaName")
													.click(
															function() {
																if ($(
																		"#areaButton")
																		.hasClass(
																				"disabled")) {
																	return true;
																}
																var options = {
																	type : 2,
																	maxmin : true,
																	shadeClose : true,
																	title : '区域选择',
																	area : [
																			'300px',
																			'400px' ],
																	content : '/js/tags/treeselect',
																	contentFormData : {
																		url : $(
																				'#areaDiv')
																				.attr(
																						'data-url'),
																		checkbox : 'false',
																		expandLevel : '-1',
																		selectCodes : $(
																				"#areaCode")
																				.val(),
																		isReturnValue : 'false'
																	},
																	success : function(
																			layero,
																			index) {
																		if ($(
																				js.layer.window)
																				.width() < 300
																				|| $(
																						js.layer.window)
																						.height() < 400) {
																			js.layer
																					.full(index);
																		}
																	},
																	btn : [ '<i class="fa fa-check"></i> 确定' ],
																	btn1 : function(
																			index,
																			layero) {
																		var win = js.layer
																				.iframeWindow(index);
																		win
																				.$(
																						'#keyword')
																				.val(
																						'')
																				.change();
																		var codes = [], names = [], nodes;
																		if ("false" == "true") {
																			nodes = win.tree
																					.getCheckedNodes(true);
																		} else {
																			nodes = win.tree
																					.getSelectedNodes();
																		}
																		for (var i = 0; i < nodes.length; i++) {
																			if (nodes[i].level == 0
																					&& nodes[i].isParent) {
																				js
																						.showMessage("不能选择根节点（"
																								+ nodes[i].name
																								+ "）请重新选择。");
																				return false;
																			}
																			if (nodes[i].isParent) {
																				js
																						.showMessage("不能选择父节点（"
																								+ nodes[i].name
																								+ "）请重新选择。");
																				return false;
																			}
																			var code = nodes[i]['false' == 'true' ? 'value'
																					: 'id'], name = nodes[i]['name'];
																			var pNode = nodes[i]
																					.getParentNode();
																			while (!!pNode) {
																				name = pNode.name
																						+ '/'
																						+ name;
																				pNode = pNode
																						.getParentNode();
																			}
																			codes
																					.push(code
																							.replace(
																									/^u_/g,
																									''));
																			names
																					.push(name
																							.replace(
																									/\([0-9]*\)/g,
																									''));
																			break;
																		}
																		if (typeof treeselectCheck == 'function') {
																			if (!treeselectCheck(
																					'area',
																					nodes)) {
																				return false;
																			}
																		}
																		$(
																				"#areaCode")
																				.val(
																						codes
																								.join(','))
																				.change();
																		$(
																				"#areaName")
																				.val(
																						names
																								.join(','))
																				.change();
																		try {
																			$(
																					'#areaCode,#areaName')
																					.valid();
																		} catch (e) {
																		}
																		if (typeof treeselectCallback == 'function') {
																			treeselectCallback(
																					'area',
																					'ok',
																					index,
																					layero,
																					nodes);
																		}
																	}
																};
																options.btn
																		.push('<i class="fa fa-eraser"></i> 清除');
																options['btn'
																		+ options.btn.length] = function(
																		index,
																		layero) {
																	$(
																			"#areaCode")
																			.val(
																					'')
																			.change();
																	$(
																			"#areaName")
																			.val(
																					'')
																			.change();
																	if (typeof treeselectCallback == 'function') {
																		treeselectCallback(
																				'area',
																				'clear',
																				index,
																				layero);
																	}
																};
																options.btn
																		.push('<i class="fa fa-close"></i> 关闭');
																options['btn'
																		+ options.btn.length] = function(
																		index,
																		layero) {
																	if (typeof treeselectCallback == 'function') {
																		treeselectCallback(
																				'area',
																				'cancel',
																				index,
																				layero);
																	}
																};
																js.layer
																		.open(options);
															});
										</script>
									</div>
								</div>
							</div>
							<div class="col-xs-6">
								<div class="form-group">
									<label class="control-label col-sm-4" title=""> <span
										class="required hide">*</span> 包含机构：<i
										class="fa icon-question hide"></i></label>
									<div class="col-sm-8">
										<div class="input-group treeselect" id="companyOfficeListDiv"
											data-url="/js/a/sys/office/treeData">
											<input id="companyOfficeListCode" type="hidden" name=""
												value="" class="isReset" /> <input
												id="companyOfficeListName" type="text" name="" value=""
												class="form-control  " readonly="readonly" /><span
												class="input-group-btn"><a
												id="companyOfficeListButton" href="javascript:"
												class="btn btn-default "><i class="fa fa-search"></i></a> </span>
										</div>
										<script>
											$(
													"#companyOfficeListButton,#companyOfficeListName")
													.click(
															function() {
																if ($(
																		"#companyOfficeListButton")
																		.hasClass(
																				"disabled")) {
																	return true;
																}
																var options = {
																	type : 2,
																	maxmin : true,
																	shadeClose : true,
																	title : '机构选择',
																	area : [
																			'300px',
																			'400px' ],
																	content : '/js/tags/treeselect',
																	contentFormData : {
																		url : $(
																				'#companyOfficeListDiv')
																				.attr(
																						'data-url'),
																		checkbox : 'true',
																		expandLevel : '-1',
																		selectCodes : $(
																				"#companyOfficeListCode")
																				.val(),
																		isReturnValue : 'false'
																	},
																	success : function(
																			layero,
																			index) {
																		if ($(
																				js.layer.window)
																				.width() < 300
																				|| $(
																						js.layer.window)
																						.height() < 400) {
																			js.layer
																					.full(index);
																		}
																	},
																	btn : [ '<i class="fa fa-check"></i> 确定' ],
																	btn1 : function(
																			index,
																			layero) {
																		var win = js.layer
																				.iframeWindow(index);
																		win
																				.$(
																						'#keyword')
																				.val(
																						'')
																				.change();
																		var codes = [], names = [], nodes;
																		if ("true" == "true") {
																			nodes = win.tree
																					.getCheckedNodes(true);
																		} else {
																			nodes = win.tree
																					.getSelectedNodes();
																		}
																		for (var i = 0; i < nodes.length; i++) {
																			if (nodes[i].isParent) {
																				continue;
																			}
																			if (nodes[i].level == 0
																					&& nodes[i].isParent) {
																				js
																						.showMessage("不能选择根节点（"
																								+ nodes[i].name
																								+ "）请重新选择。");
																				return false;
																			}
																			if (nodes[i].isParent) {
																				js
																						.showMessage("不能选择父节点（"
																								+ nodes[i].name
																								+ "）请重新选择。");
																				return false;
																			}
																			var code = nodes[i]['false' == 'true' ? 'value'
																					: 'id'], name = nodes[i]['name'];
																			codes
																					.push(code
																							.replace(
																									/^u_/g,
																									''));
																			names
																					.push(name
																							.replace(
																									/\([0-9]*\)/g,
																									''));
																		}
																		if (typeof treeselectCheck == 'function') {
																			if (!treeselectCheck(
																					'companyOfficeList',
																					nodes)) {
																				return false;
																			}
																		}
																		$(
																				"#companyOfficeListCode")
																				.val(
																						codes
																								.join(','))
																				.change();
																		$(
																				"#companyOfficeListName")
																				.val(
																						names
																								.join(','))
																				.change();
																		try {
																			$(
																					'#companyOfficeListCode,#companyOfficeListName')
																					.valid();
																		} catch (e) {
																		}
																		if (typeof treeselectCallback == 'function') {
																			treeselectCallback(
																					'companyOfficeList',
																					'ok',
																					index,
																					layero,
																					nodes);
																		}
																	}
																};
																options.btn
																		.push('<i class="fa fa-eraser"></i> 清除');
																options['btn'
																		+ options.btn.length] = function(
																		index,
																		layero) {
																	$(
																			"#companyOfficeListCode")
																			.val(
																					'')
																			.change();
																	$(
																			"#companyOfficeListName")
																			.val(
																					'')
																			.change();
																	if (typeof treeselectCallback == 'function') {
																		treeselectCallback(
																				'companyOfficeList',
																				'clear',
																				index,
																				layero);
																	}
																};
																options.btn
																		.push('<i class="fa fa-close"></i> 关闭');
																options['btn'
																		+ options.btn.length] = function(
																		index,
																		layero) {
																	if (typeof treeselectCallback == 'function') {
																		treeselectCallback(
																				'companyOfficeList',
																				'cancel',
																				index,
																				layero);
																	}
																};
																js.layer
																		.open(options);
															});
										</script>
										<input type="hidden" id="companyOfficeListJson"
											name="companyOfficeListJson" value="" />
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<div class="form-group">
									<label class="control-label col-sm-2" title=""> <span
										class="required hide">*</span> 备注信息：<i
										class="fa icon-question hide"></i></label>
									<div class="col-sm-10">
										<textarea id="remarks" name="remarks" rows="4" maxlength="500"
											class="form-control "></textarea>
									</div>
								</div>
							</div>
						</div>
					<div class="box-footer">
						<div class="row">
							<div class="col-sm-offset-2 col-sm-10">
								<button type="submit" class="btn btn-sm btn-primary"
									id="btnSubmit" @click="submit()">
									<i class="fa fa-check"></i> 保 存
								</button>
								&nbsp;
								<button type="button" class="btn btn-sm btn-default"
									id="btnCancel" onclick="js.closeCurrentTabPage()">
									<i class="fa fa-reply-all"></i> 关 闭
								</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>

<a id="scroll-up" href="#" class="btn btn-sm"><i class="fa fa-angle-double-up"></i></a>
<script th:src="${setting.domain + 'bootstrap/js/bootstrap.min.js'}"></script>
<script th:src="${setting.domain + 'select2/4.0/select2.js'}"></script>
<script th:src="${setting.domain + 'select2/4.0/i18n/zh_CN.js'}"></script>
<script th:src="${setting.domain + 'layer/3.1/layer.js'}"></script>
<script th:src="${setting.domain + 'my97/WdatePicker.js'}"></script>
<script th:src="${setting.domain + 'jquery-validation/1.16/jquery.validate.js'}"></script>
<script th:src="${setting.domain + 'jquery-validation/1.16/localization/messages_zh_CN.js'}"></script>
<script th:src="${setting.domain + 'jquery-validation/1.16/jquery.validate.extend.js'}"></script>
<script th:src="${setting.domain + 'common/jeesite.js'}"></script>
<script th:src="${setting.domain + 'common/i18n/jeesite_zh_CN.js'}"></script>
<script th:src="${setting.domain + 'common/common.js'}"></script>

<!-- VUE -->
<script th:src="${setting.domain + 'vue/vue.min.js'}"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
var vm = new Vue({
	el:'#inputForm',
	data:{
		company:{
			
		}
	},
	methods: {
		submit:function(){
			$("#inputForm").validate({
				submitHandler: function(form){
					var companyOfficeData = $('#companyOfficeListCode').val().split(',');
					$("#companyOfficeListJson").val(JSON.stringify(companyOfficeData));
					js.ajaxSubmitForm($(form), function(data){
						js.showMessage(data.message);
						if(data.result == Global.TRUE){
							js.closeCurrentTabPage(function(contentWindow){
								contentWindow.$('#dataGrid').dataGrid('refreshTreeChildren',$('#parentCode').val(), 'SDJN');
							});
						}
					}, "json");
			     }
			});
		},
		getCompany:function(code){
			axios.get(ctx + "sys/company/info/"+code).then(function(response){
			    vm.company = response.data.result;
			})
		},
		changeCompanyName:function(){
			if(vm.company.fullName == ''){
				Vue.set(vm.company , 'fullName' , vm.company.name);
			}
		},
		showCompanyDialog:function(){
			if ($("#parentButton").hasClass("disabled")) {
				return true;
			}
			var options = {
				type : 2,
				maxmin : true,
				shadeClose : true,
				title : '上级公司',
				area : ['300px','400px' ],
				content : ctx + 'sys/treeselect',
				contentFormData : {
					url : 'sys/company/treeData?excludeId=' + vm.company.id,
					checkbox : 'false',
					expandLevel : '-1',
					selectCodes : $("#parentCode").val(),
					isReturnValue : 'false'
				},
				success : function(layero,index) {
					if ($(js.layer.window).width() < 300 || $(js.layer.window).height() < 400) {
						js.layer.full(index);
					}
				},
				btn : [ '<i class="fa fa-check"></i> 确定' ],
				btn1 : function(index,layero) {
					var win = js.layer.iframeWindow(index);
					win.$('#keyword').val('').change();
					var codes = [], names = [], nodes;
					if ("false" == "true") {
						nodes = win.tree.getCheckedNodes(true);
					} else {
						nodes = win.tree.getSelectedNodes();
					}
					for (var i = 0; i < nodes.length; i++) {
						var code = nodes[i]['false' == 'true' ? 'value' : 'id'], name = nodes[i]['name'];
						codes.push(code.replace(/^u_/g,''));
						names.push(name.replace(/\([0-9]*\)/g,''));
						break;
					}
					if (typeof treeselectCheck == 'function') {
						if (!treeselectCheck('parent',nodes)) {
							return false;
						}
					}
					vm.company.parentCode = codes.join(',');
					vm.company.parentName = names.join(',');
					try {
						$('#parentCode,#parentName').valid();
					} catch (e) {
					}
					if (typeof treeselectCallback == 'function') {
						treeselectCallback('parent','ok',index,layero,nodes);
					}
				}
			};
			options.btn.push('<i class="fa fa-eraser"></i> 清除');
			options['btn'+ options.btn.length] = function(index,layero) {
				$("#parentCode").val('').change();
				$("#parentName").val('').change();
				if (typeof treeselectCallback == 'function') {
					treeselectCallback('parent','clear',index,layero);
				}
			};
			options.btn.push('<i class="fa fa-close"></i> 关闭');
			options['btn'+ options.btn.length] = function(index,layero) {
				if (typeof treeselectCallback == 'function') {
					treeselectCallback('parent','cancel',index,layero);
				}
			};
			js.layer.open(options);
		}
	},
	watch:{
	}
});
var id = '[[${id}]]';
if(!/^(undefined|null|\s*)?$/.test(id)){
	vm.getCompany(id);
}
</script>