<!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="../../css/common.css" />
	<style type="text/css">
		body {
			font-family: 'Microsoft YaHei';
		}

		.ui-required:before {
			content: "*";
			color: red;
			vertical-align: middle;
		}

		.my-head {
			border: 1px solid #e9e9e9;
			background-color: #fafafa;
			color: #000000d8;
		}

		.mybox {
			border-right: 1px solid #e9e9e9;
			margin-right: 10px;
			text-align: center;
			font-size: 16px;
			margin: 10px 0;
		}

		.mybox h2 {
			margin-bottom: 15px;
			font-weight: bold;
		}

		.no-border {
			border: none;
		}

		.margin-top {
			margin-top: 10px;
		}

		.text-right {
			text-align: right;
		}

		.my-btn {
			margin: 10px;
		}

		.my-head-1 {
			border-bottom: 1px solid #e9e9e9;
			padding-bottom: 10px;
		}

		.my-title {
			line-height: 100%;
			font-size: 16px;
			padding-top: 10px;
			color: #3398db;
		}

		.text-center {
			text-align: center;
		}

		.article-title {
			margin: 30px 0 5px 15px;
		}

		.article-content {
			padding-top: 5px;
			padding-left: 45px;
		}

		#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;
			position: relative;
		}

		.my-images-inline .layui-icon {
			position: absolute;
			top: -10px;
			right: -4px;
			width: 17px;
			height: 16px;
			line-height: 16px;
			z-index: 9999;
		}

		.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="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="{{d.elem}}BTN">+</div>
			</div>
		</script>
</head>

<body class="childrenBody" style="padding: 15px 15px 65px 15px;">
	<div class="layui-fluid">
		<form class="layui-form" action="" lay-filter="addForm" style="background: #fff;">
			<div class="layui-card">
				<div class="layui-card-header my-head">企业信息：</div>
				<div class="layui-card-body">
					<div class="layui-form-item">
						<label class="layui-form-label ui-required">企业名称:</label>
						<div class="layui-input-block">
							<input type="text" disabled="disabled" name="orgName" maxlength="50" lay-verify="required|normal"
								placeholder="请输入企业名称" autocomplete="off" class="layui-input layui-disabled">
						</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">
						<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">企业电话:</label>
								<div class="layui-input-block">
									<input type="text" name="companyTel" lay-verify="" 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="12" autocomplete="off"
									class="layui-input">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">企业及品牌介绍:</label>
						<div class="layui-input-block">
							<textarea name="remark" placeholder="请输入企业及品牌介绍" class="layui-textarea"></textarea>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">企业LOGO</label>
						<div class="layui-input-block">
							<div id="imageListDivLOGO" style="display: flex;"></div>
							<div class="layui-form-mid layui-word-aux">图片上传完毕后请记得按保存哦</div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">企业相关资质</label>
						<div class="layui-input-block">
							<div id="imageListxgzz" style="display: flex;"></div>
							<div class="layui-form-mid layui-word-aux">图片上传完毕后请记得按保存哦</div>
						</div>
					</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>
					</div>
					<h2 style="font-size:18px;margin-bottom:18px;border-bottom: 1px solid #ddd;padding-bottom: 11px;">购买渠道</h2>
					<div class="layui-form-item">
						<label class="layui-form-label">天猫商城地址:</label>
						<div class="layui-input-block">
							<input type="text" name="tmallUrl" 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="jdUrl" 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="companyUrl" placeholder="请输入企业官网" maxLength="100" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-layer-btn">
						<div class="layui-input-block" style="padding-right: 20px;">
							<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</body>
<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>
	layui.use(["form", 'layer', 'jquery', 'laytpl', 'upload'], function () {
		var form = layui.form,
			layer = layui.layer,
			$ = layui.jquery,
			laytpl = layui.laytpl,
			upload = layui.upload;
		var formData = {
			guid: true, //带参传入ID
			current: {}, //当前表单数据
			select_data: "select_Info_org", //查询企业
			save_data: 'edit_Info_org', //查询企业
			formLayFilter: "addForm", //表单容器
			closeModal: function () { //关闭当前窗口
				parent.layer.close(parent.layer.getFrameIndex(window.name));
			}
		};
		//图片列表模板
		function imageTpl(obj, name, model) {
			laytpl(imageHtmlTpl.innerHTML).render(obj, function (html) {
				let delelem = $("#" + obj.elem).html(html);
				upload.render({
					elem: "#" + obj.elem + "BTN",
					url: 'uploadImage',
					accept: "file",
					exts: "jpg|jpeg|png|bmp|gif",
					size: 10240, //kb
					before: function () {
						uploadMsg = layer.msg('正在上传中……', {
							icon: 16,
							fixed: false,
							time: 0
						});
					},
					done: function (res) {
						layer.close(uploadMsg);
						if (model === 'single') {
							formData.current[name] = res.data[0];
						} else {
							let list;
							if (formData.current[name] === "" || !formData.current[name]) {
								list = []
							} else {
								list = formData.current[name].split(';')
							}
							list.push(res.data[0])
							formData.current[name] = list.join(";");
						}
						imageTpl({
							elem: obj.elem,
							list: model === 'single' ? [formData.current[name]] : formData.current[name].split(";")
						}, name, model);

					},
					error: function () { }
				});
				$(delelem[0].querySelectorAll('.button-delImage')).on("click", function (e) {
					let showList;
					if (model === 'single') {
						formData.current[name] = ""
						showList = []
					} else {
						let index = $(this).attr("data-bind");
						let list = formData.current[name].split(";")
						list.splice(index, 1)
						formData.current[name] = list.join(";");
						showList = formData.current[name].split(';')
						if (list.length == 0) {
							showList = [];
							formData.current[name] = ""
						}
					}
					imageTpl({
						elem: obj.elem,
						list: showList
					}, name, model);
				});
			});
		}
		//初始化
		formData.main = function () {
			var _this = this;
			if (this.guid) {
				_this.getCurrent(_this.guid); //获取并初始化表单角色信息
			} else {
				_this.initialization();
			}
			return this;
		};

		//初始化
		formData.initialization = function () {
			var _this = this;
			// console.log(_this.current.qualificaImgs)
			imageTpl({
				elem: "imageListDiv",
				list: _this.current.wxQRImg ? [_this.current.wxQRImg] : [],
			}, 'wxQRImg', 'single');
			imageTpl({
				elem: "imageListDivLOGO",
				list: _this.current.ico ? [_this.current.ico] : [],
			}, 'ico', 'single');
			imageTpl({
				elem: "imageListxgzz",
				list: _this.current.qualificaImgs ? _this.current.qualificaImgs.split(';') : [],
			}, 'qualificaImgs', 'Multi');
			//监听提交
			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) {
					try {
						_this.current = res.data[0] || {};

					} catch (e) { }
					_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;
			// console.log(_this.current)
			$.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;
			},
			normal: function () {
				return false;
			}
		});
	});
</script>

</html>