<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>新增企业</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" />
	<link rel="stylesheet" type="text/css" href="../../forstcss/common.css" />
	<style type="text/css">
		.ui-required:before {
			content: "*";
			color: red;
			vertical-align: middle;
		}

		#roleSelectViwe .layui-form-item {
			margin-bottom: 0
		}

		#roleSelectViwe .layui-input-inline {
			width: calc(100% - 110px);
			margin-right: 0;
		}

		.region {
			padding-left: 10px;
			height: 38px;
			line-height: 38px;
			background-color: #fff;
			border-radius: 2px;
			border: 1px solid #e6e6e6;
			width: 100% !important;
			width: calc(100% - 132px) !important;
		}

		.userTip {
			color: #666;
			font-size: 12px;
		}

		.userTip b {
			color: #333;
		}

		#roleSelectViwe .layui-form-item {
			margin-bottom: 0
		}

		#roleSelectViwe .layui-input-inline {
			width: calc(100% - 110px);
			margin-right: 0;
		}

		.region {
			padding-left: 10px;
			height: 38px;
			line-height: 38px;
			background-color: #fff;
			border-radius: 2px;
			border: 1px solid #e6e6e6;
			width: calc(100% - 132px) !important;
		}

		.userTip {
			color: #666;
			font-size: 12px;
		}

		.userTip b {
			color: #333;
		}

		.my-middle {
			line-height: 36px;

		}

		.my-button {
			width: 60%;
			margin-left: 20%;
			height: 40px;
			text-align: center;
			line-height: 40px;
			border: 1px dashed;
			border-radius: 5px;
		}

		.my-inline {
			display: inline-block;
			float: left;
			text-align: center;
			height: 38px;
			line-height: 38px;
			width: 10%;
		}

		.my-images-inline {
			display: inline-block;
			width: 104px;
			height: 104px;
			border: 1px dashed;
			border-radius: 5px;
			padding: 4px;
			vertical-align: top;
			margin: 4px;
		}

		.my-img {
			width: 100%;
			height: 100%;
		}

		.my-images-add {
			display: inline-block;
			text-align: center;
			line-height: 103px;
			font-size: 32px;
			cursor: pointer;
			background-color: #fbfbfb;
		}

		.my-del {
			background-color: black;
			color: white;
		}

		.button-delImage.button-delAssayImage {
			position: relative;
			left: -2px;
			top: -106px;
		}
	</style>
	<script type="text/html" id="typeHtmlTpl">
		<option value="">请选择</option>
		{{# if(!d.list){d.list = []}; layui.each(d.list, function(index, item){ }}
		<option value="{{item.guid}}">{{item.roleName}}</option>
		{{# }); }}
	</script>
</head>

<body>
	<form class="layui-form" action="" lay-filter="addForm" style="padding: 20px 20px 0 0">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label ui-required">企业代码</label>
				<div class="layui-input-block">
					<input type="text" id="ID_orgCode" name="orgCode" lay-verify="mustNumber6" placeholder="请输入企业代码"
						autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-inline">
				<label class="layui-form-label">企业简码</label>
				<div class="layui-input-block">
					<input type="text" id='ID_orgBrevity' name="orgBrevity" placeholder="请输入企业简码" lay-verify="mustNumber3"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<script type="text/javascript">
				(function () {
					let a = document.querySelector('#ID_orgCode');
					let b = document.querySelector('#ID_orgBrevity');
					a.onchange = function () {
						b.value = (this.value + '').substr(-3);
					}
				})();
			</script>
		</div>

		<!-- <div class="layui-form-item">
			<label class="layui-form-label">企业公众号二维码</label>
			<div class="layui-input-block">
				<div id="imageListDiv" style="display: flex;"></div>
				<div class="layui-form-mid layui-word-aux">图片视频上传完毕后请记得按保存哦</div>
			</div>
			<script type="text/html" id="imageHtmlTpl">
				<div class="layui-form-item">
					{{# if(!d.list){d.list = []}; layui.each(d.list, function(index, item){ }}
					<div class="my-images-inline">
						{{#if ("jpg|jpeg|png|gif|bmp".indexOf(item.substring(item.lastIndexOf(".")+1))==-1){}}
						<video class="my-img" src="{{window.hywa.config.href}}/{{item}}" autoplay loop></video>
						{{#}else{}}
						<img class="my-img" src="{{window.hywa.config.href}}/{{item}}">
						{{#} }}
						<i class="layui-icon my-del button-delImage" data-bind="{{index}}" title="删除" data-icon="&#x1006;">&#x1006;</i>
					</div>
					{{# }); }}
					<div class="my-images-inline my-images-add" id="imageUploadBtn">+</div>
				</div>
			</script>
		</div> -->
		<div class="layui-form-item">
			<label class="layui-form-label ui-required">企业名称</label>
			<div class="layui-input-block">
				<input type="text" name="orgName" maxlength="50" lay-verify="required|normal" placeholder="请输入企业名称"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<!-- <div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label ui-required">联系人</label>
				<div class="layui-input-block">
					<input type="text" name="principals" lay-verify="required|normal" placeholder="请输入联系人姓名" maxLength="5" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label ui-required">联系电话</label>
				<div class="layui-input-block">
					<input type="text" name="tel" lay-verify="required|normal" placeholder="请输入联系电话" maxLength="18" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">qq</label>
				<div class="layui-input-block">
					<input type="text" name="qqCode" lay-verify="" placeholder="请输入qq号" maxLength="18" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">企业官网</label>
			<div class="layui-input-block">
				<input type="text" name="companyUrl" placeholder="请输入企业官网" maxLength="100" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">企业地址</label>
			<div class="layui-input-block">
				<input type="text" name="orgAddress" placeholder="请输入企业地址" maxLength="100" autocomplete="off"
					   class="layui-input">
			</div>
		</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label">二维码网址</label>
			<div class="layui-input-block">
				<input type="text" name="qrcodeUrlPrefixe" placeholder="请输入二维码网址" maxLength="100" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label ui-required">系统名称</label>
			<div class="layui-input-block">
				<input type="text" name="systemName" maxlength="50" lay-verify="required|normal" placeholder="请输入系统名称"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label ui-required">溯源模版</label>
			<div class="layui-input-block">
				<select name="templeType" lay-verify="required|normal">
					<option value=""></option>
					<option value="0">标准模板</option>
					<option value="1">大米模板</option>
					<option value="2">林产品模板</option>
				</select>
			</div>
		</div>
		<!-- <div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type="text" name="remark" placeholder="请输入备注" maxLength="500" autocomplete="off"
					   class="layui-input">
			</div>
		</div> -->
		<div class="layui-form-item layui-layer-btn">
			<div class="layui-input-block">
				<button type="reset" class="layui-btn layui-btn-primary" id="closeWin">取消</button>
				<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
			</div>
		</div>
	</form>
	<script type="text/javascript">
		function loadJS(url) {
			document.write("<script src='" + url + "?ver=" + new Date().getTime() + "'><\/script>")
		}
		loadJS("../../layui/layui.js");
		loadJS("../../js/ajaxhook.min.js");
		loadJS("../../js/config.js");
	</script>
	<script type="text/javascript">
		layui.config({
			base: "../../js/layuiPlugins/"
		}).use(["form", 'layer', 'jquery', 'laytpl', 'upload'], function () {
			var form = layui.form,
				layer = layui.layer,
				$ = layui.jquery,
				laytpl = layui.laytpl,
				upload = layui.upload;
			var funcName = "org";
			var formData = {
				guid: (JSON.stringify(location.searchObj()) != "{}") ? location.searchObj().guid || null : null, //带参传入ID
				current: {}, //当前表单数据
				select_data: "select_" + funcName, //查询企业
				save_data: (location.searchObj().guid ? 'edit' : 'add') + '_' + funcName, //查询企业
				formLayFilter: "addForm", //表单容器
				closeModal: function () { //关闭当前窗口
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				}
			};
			var option = {
				elem: '#imageUploadBtn',
				url: 'uploadImage',
				accept: "file",
				exts: "jpg|jpeg|png|gif|bmp|mp4|ogg|webm|avi|wma|rmvb|rm|flash|3gp|flv|mp3",
				size: 10240,//kb
				before: function () {
					uploadMsg = layer.msg('正在上传中……', {
						icon: 16,
						fixed: false,
						time: 0
					});
				},
				done: function (res) {
					layer.close(uploadMsg);
					formData.current.wxQRImg = res.data[0];
					imageTpl({
						elem: "#imageListDiv",
						list: [formData.current.wxQRImg]
					});
				},
				error: function () {
				}
			};
			//图片列表模板
			function imageTpl(obj) {
				laytpl(imageHtmlTpl.innerHTML).render(obj, function (html) {
					$(obj.elem).html(html);
					upload.render(option);
					$(".button-delImage").on("click", function (e) {
						formData.current.wxQRImg = "";
						imageTpl({
							elem: "#imageListDiv",
							list: []
						});
					});
				});
			}
			//初始化
			formData.main = function () {
				var _this = this;
				if (this.guid) {
					_this.getCurrent(_this.guid); //获取并初始化表单角色信息
				} else {
					_this.initialization();

				}
				if (location.searchObj().event == "view") {
					var el = document.getElementsByTagName("INPUT");
					for (var i = 0; i < el.length; i++) {
						el[i].readOnly = true;
					}
					el = document.getElementsByTagName("SELECT");
					for (var i = 0; i < el.length; i++) {
						el[i].disabled = true;
					}
					el = document.getElementsByTagName("checkbox");
					for (var i = 0; i < el.length; i++) {
						el[i].disabled = true;
					}
					el = document.getElementsByTagName("button");
					for (var i = 0; i < el.length; i++) {
						0
						if (el[i].innerText.replace(" ", "") == "保存") {
							el[i].style.display = "none";
						}
					}
				}
				return this;
			};

			//初始化
			formData.initialization = function () {
				var _this = this;
				// 				imageTpl({
				// 				    elem: "#imageListDiv",
				// 				    list: _this.current.wxQRImg?[_this.current.wxQRImg]:[]
				// 				});
				//监听提交
				form.on('submit(formDemo)', function (obj) {
					//必须return false;
					return _this.fusionData(obj.field).submitInfo(); //获取选中权限变数组,提交变化===下拉
				});
				//关闭窗口
				$("#closeWin").on("click", function () {
					_this.closeModal();
				});
				return _this;
			};
			//获取当前信息
			formData.getCurrent = function (id) {
				var _this = this;
				$.ajax({
					url: this.select_data,
					method: 'get',
					data: {
						guid: id || this.guid //当前ID
					},
					success: function (res) {
						_this.current = res.data[0];
						_this.initialization().formVal();
					}
				});
				return _this;
			};
			//表单赋值
			formData.formVal = function () {
				var _this = this;
				form.val(this.formLayFilter, this.current);
				return this;
			};
			//合并表单内容
			formData.fusionData = function (obj) {
				this.current = $.extend(this.current, obj);
				if (this.current.guid) {
					delete this.current.password;
				}
				return this;
			};
			//提交新增修改
			formData.submitInfo = function () {
				var _this = this;
				$.ajax({
					type: 'POST',
					url: this.save_data,//+'?userId='+this.guid
					data: JSON.stringify(this.current),
					contentType: 'application/json',
					success: function (res) {

						if (!(res.code - 0)) {
							parent.layer.msg(res.msg, {
								icon: 1
							});
							_this.closeModal();
						} else {
							layer.msg(res.msg, {
								icon: 2
							});
						}
					}
				});
				return false;
			};
			formData.main();
			//验证规则
			form.verify({
				phoneNumber: function (value) {
					if (value) {
						if (!(/^1[3|4|5|7|8]\d{9}$/).test(value)) {
							return '请输入正确的手机号码';
						}
					}
					return false;
				},
				mustNumber6: [
					/^[0-9]{6}$/,
					"必须是数字6位"
				],
				mustNumber3: [
					/^[0-9]{3}$/,
					"必须是数字3位"
				],
				normal: function () {
					return false;
				}
			});
		});
	</script>
</body>

</html>