<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>{echo admin_title()}</title>
	{template _header}
	<style>
	.check-status-0 {color:#DDDDDD;}
	.check-status-1 {color:#009688;}
	.check-status-2 {color:#FF5722;}
	.check-status--1 {color:#FFB800;}
	.select-autoComplete{
		display: none;
		top: 10px!important;
		line-height: 2em;
		position: relative;
		padding: 1em 0.5em;
		color:rgb(85, 85, 85);
		box-shadow:rgba(0, 0, 0, 0.5) 0px 3px 5px;
		transform: scale(1);
		z-index: 999; background: #fff;
	}
	.tips .weui-dialog__bd{ font-size: 14px; text-align: left;}
	</style>
</head>
<body>
	<div class="weui-tab">
		<div class="weui-tab__panel">
			<form enctype="multipart/form-data" method="post" name="form1">
				<input type="hidden" name="merchant_id" value="{$value[merchant_id]}">
				<div class="weui-form">
					<div class="weui-cells__title" style="margin-bottom:8px">进件类型</div>
					<div class="weui-cells weui-cells_checkbox sign_type">
						<label class="weui-cell weui-cell_active weui-check__label" for="sign_alipay">
							<div class="weui-cell__hd">
								<input type="checkbox" class="weui-check" id="sign_alipay" {if !empty($value[alipay])}checked="checked"{/if} required tips="请选择至少一个进件类型" />
								<i class="weui-icon-checked"></i>
							</div>
							<div class="weui-cell__bd"><p>支付宝</p></div>
						</label>
						<label class="weui-cell weui-cell_active weui-check__label" for="sign_weixin">
							<div class="weui-cell__hd">
								<input type="checkbox" class="weui-check" id="sign_weixin" {if !empty($value[weixin])}checked="checked"{/if} />
								<i class="weui-icon-checked"></i>
							</div>
							<div class="weui-cell__bd"><p>微信</p></div>
						</label>
					</div>
					<input type="hidden" id="weixin" name="weixin" value="{$value[weixin]}">
					<div class="weui-cells__title" style="margin-bottom:8px">商户信息</div>
					<div class="weui-cells weui-cells_form">
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">商户名称</label></div>
							<div class="weui-cell__bd"><input id="merchant_name" name="merchant_name" class="weui-input" placeholder="填写营业执照商户名称" value="{$value[merchant_name]}" required /></div>
						</div>
						<div class="weui-cell weui-cell_select weui-cell_select-after">
							<div class="weui-cell__hd"><label class="weui-label">商户类型</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select" id="merchant_type" name="merchant_type" dir="rtl">
									<!--{loop model('Merchant')->get_type() $key $val}-->
									<option value="{$val}" {if $val == $value[merchant_type]}selected{/if}>{$val}</option>
									<!--{/loop}-->
								</select>
							</div>
						</div>
						<div class="weui-cell weui-cell_select weui-cell_select-after">
							<div class="weui-cell__hd"><label class="weui-label">行业类型</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select" id="merchant_industry" name="merchant_industry" dir="rtl">
									<!--{loop model('Merchant')->get_industry() $key $val}-->
									<option value="{$val}" {if $val == $value[merchant_industry]}selected{/if}>{$val}</option>
									<!--{/loop}-->
								</select>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">商户简称</label></div>
							<div class="weui-cell__bd"><input id="merchant_shortname" name="merchant_shortname" class="weui-input" value="{$value[merchant_shortname]}" placeholder="填写商户简称" required /></div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">客服电话</label></div>
							<div class="weui-cell__bd"><input id="service_phone" name="service_phone" class="weui-input" value="{$value[service_phone]}" placeholder="填写客服电话" required /></div>
						</div>
					</div>
					<div class="weui-cells__title" style="margin-bottom:8px">联系人信息</div>
					<div class="weui-cells weui-cells_form">
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">负责人姓名</label></div>
							<div class="weui-cell__bd"><input id="per_name" name="per_name" class="weui-input" placeholder="填写负责人姓名" value="{$value[per_name]}" required /></div>
						</div>
						<div class="weui-cell" {if empty($value[weixin])}style="display:none"{/if}>
							<div class="weui-cell__hd"><label class="weui-label">负责人身份证号</label></div>
							<div class="weui-cell__bd"><input id="per_id_number" name="per_id_number" class="weui-input" placeholder="填写负责人身份证号" value="{$value[per_id_number]}" /></div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">联系电话</label></div>
							<div class="weui-cell__bd"><input id="per_phone" name="per_phone" class="weui-input" placeholder="填写联系电话" value="{$value[per_phone]}" required /></div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">联系邮箱</label></div>
							<div class="weui-cell__bd"><input id="per_email" name="per_email" class="weui-input" placeholder="填写联系邮箱" value="{$value[per_email]}" required /></div>
						</div>
					</div>
					<div class="weui-cells__title" style="margin-bottom:8px">门店信息(与开户银行地区一致)</div>
					<div class="weui-cells weui-cells_form" id="area-picker">
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">省市区</label></div>
							<div class="weui-cell__bd"><p class="area-selector" style="text-align: right;">{$value[province]}{$value[city]}{$value[county]}</p></div>
						</div>
						<input type="hidden" id="province" name="province" value="{$value[province]}">
						<input type="hidden" id="city" name="city" value="{$value[city]}">
						<input type="hidden" id="county" name="county" value="{$value[county]}">
						<input type="hidden" id="area_code" name="area_code" value="{$value[area_code]}">
						<!-- <div class="weui-cell weui-cell_select weui-cell_select-after">
							<div class="weui-cell__hd"><label class="weui-label">所属省级</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select province-selector" id="province" name="province">
									<option value="">请选择省</option>
								</select>
							</div>
						</div>
						<div class="weui-cell weui-cell_select weui-cell_select-after">
							<div class="weui-cell__hd"><label class="weui-label">所属市级</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select city-selector" id="city" name="city">
									<option value="">请选择市</option>
								</select>
							</div>
						</div>
						<div class="weui-cell weui-cell_select weui-cell_select-after">
							<div class="weui-cell__hd"><label class="weui-label">所属区级</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select county-selector" id="county" name="county">
									<option value="">请选择区</option>
								</select>
							</div>
						</div> -->
						<div class="weui-cell">
							<div class="weui-cell__hd"><label class="weui-label">经营地址</label></div>
							<div class="weui-cell__bd"><input id="address" name="address" class="weui-input" placeholder="填写详细经营地址" value="{$value[address]}" required /></div>
						</div>
					</div>
					<div class="weui-cells__title" style="margin-bottom:8px">商户收款账户</div>
					<div class="weui-cells weui-cells_form">
						<div class="weui-cell" {if empty($value[alipay])}style="display:none"{/if}>
							<div class="weui-cell__hd"><label class="weui-label">支付宝账号</label></div>
							<div class="weui-cell__bd"><input id="alipay" name="alipay" class="weui-input" placeholder="填写支付宝账号" value="{$value[alipay]}" /></div>
						</div>
						<div class="weui-cell weui-cell_select weui-cell_select-after" {if empty($value[weixin])}style="display:none"{/if}>
							<div class="weui-cell__hd"><label class="weui-label">银行账户类型</label></div>
							<div class="weui-cell__bd">
								<select class="weui-select" id="bank_account_type" name="bank_account_type" dir="rtl">
									<option value="BANK_ACCOUNT_TYPE_CORPORATE" {if 'BANK_ACCOUNT_TYPE_CORPORATE' == $value[bank_account_type]}selected{/if}>对公银行账户</option>
									<option value="BANK_ACCOUNT_TYPE_PERSONAL" {if 'BANK_ACCOUNT_TYPE_PERSONAL' == $value[bank_account_type]}selected{/if}>经营者个人银行卡</option>
								</select>
							</div>
						</div>
						<div class="weui-cell" {if empty($value[weixin])}style="display:none"{/if}>
							<div class="weui-cell__hd" style="width:105px; overflow: hidden;">
								<label class="weui-label">银行全称
									<i class="iconfont icon-tips" data-tips="需要与门店地址保持一致"></i>
								</label>
							</div>
							<div class="weui-cell__bd"><input id="account_bank" name="account_bank" class="weui-input" placeholder="填写开户银行全称" value="{$value[account_bank]}" /></div>
						</div>
						<!-- <div class="weui-cell" {if empty($value[weixin])}style="display:none"{/if}>
							<div class="weui-cell__hd"><label class="weui-label">开户名称</label></div>
							<div class="weui-cell__bd"><input id="account_name" name="account_name" class="weui-input" placeholder="填写开户名称" value="{$value[account_name]}" /></div>
						</div> -->
						<div class="weui-cell" {if empty($value[weixin])}style="display:none"{/if}>
							<div class="weui-cell__hd"><label class="weui-label">银行卡号</label></div>
							<div class="weui-cell__bd"><input id="account_number" name="account_number" class="weui-input" placeholder="填写银行卡号" value="{$value[account_number]}" /></div>
						</div>
					</div>
					<div class="weui-cells__title" style="margin-bottom:8px">备注信息</div>
					<div class="weui-cells weui-cells_form">
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<textarea class="weui-textarea" placeholder="请填写备注" rows="3" id="remarks" name="remarks">{$value[remarks]}</textarea>
								<div class="weui-textarea-counter"><span>{echo strlen($value['remarks'])}</span>/200</div>
							</div>
						</div>
					</div>
					<div class="weui-cells__title" style="margin-bottom:8px">附件上传</div>
					<div class="weui-cells weui-cells_form" id="uploader">
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">法人身份证人像面</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[id_card_copy]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[id_card_copy]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value[id_card_copy]}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="id_card_copy" accept="image/*" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">法人身份证国徽面</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[id_card_national]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[id_card_national]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value[id_card_national]}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="id_card_national" accept="image/*" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">营业执照</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[license_copy]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[license_copy]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value[license_copy]}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="license_copy" accept="image/*" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">门店门口照片
											<i class="iconfont icon-tips" data-tips="门店场所：提交门店门口照片，要求招牌清晰可见<br>流动经营/便民服务：提交经营/服务现场照片<br>线上商品/服务交易：提交店铺首页截图"></i>
										</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[store_door]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[store_door]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value[store_door]}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="store_door" accept="image/*" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">店内环境照片
											<i class="iconfont icon-tips" data-tips="门店场所：提交店内环境照片<br>流动经营/便民服务：可提交另一张经营/服务现场照片<br>线上商品/服务交易：提交店铺管理后台截图"></i>
										</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[store_inside]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[store_inside]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value[store_inside]}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="store_inside" accept="image/jpeg, image/jpg, image/bmp, image/png" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="weui-cell">
							<div class="weui-cell__bd">
								<div class="weui-uploader">
									<div class="weui-uploader__hd">
										<p class="weui-uploader__title">特殊资质照片
											<i class="iconfont icon-tips" data-tips="特殊行业：如餐饮食品，需提供《食品流通许可证》或《食品卫生许可证》，详情参见特殊资质类目"></i>
										</p>
									</div>
									<div class="weui-uploader__bd">
										<ul class="weui-uploader__files uploaderFiles">
											<!--{if $value[qualifications]}-->
											<li class="weui-uploader__file" style="background-image:url({$value[qualifications]})"></li>
											<!--{/if}-->
										</ul>
										<div class="weui-uploader__input-box" {if $value['qualifications']}style="display:none"{/if}>
											<input class="uploaderInput weui-uploader__input" type="file" name="qualifications" accept="image/jpeg, image/jpg, image/bmp, image/png" multiple/>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<!--{if in_array($value['check_status'], [0, 2])}-->
					<div class="weui-form__tips-area" style="background: #fff; padding:24px 0;">
						<p class="weui-form__tips" style="font-size: 12px; color:rgba(0,0,0,.5); text-align: center;">
							上传图片支持jpeg、jpg、bmp、png格式，<br>图片大小不超过2M
						</p>
					</div>
					<div class="weui-form__opr-area" style="background: #fff; padding: 0 1em 2em;">
						<button class="weui-btn weui-btn_primary" type="button" name="submit2">保存</button>
						<button class="weui-btn weui-btn_warn" type="button" name="submit3">提交审核</button>
					</div>
					<!--{/if}-->
				</div>
			</form>
		</div>
		{template _main_nav}
	</div>

	<div class="weui-gallery" id="gallery">
		<span class="weui-gallery__img" id="galleryImg"></span>
		<div class="weui-gallery__opr">
			<a href="javascript:" class="weui-gallery__del">
				<i class="weui-icon-delete weui-icon_gallery-delete"></i>
			</a>
		</div>
	</div>
	<script src="/public/js/autoComplete.js"></script>
	<script src="/public/m/areaSelect.js"></script>
	<script>
	var areaSelect = new AreaSelect({
		style: 'weui',
		defaultAreaCode: "{$value[area_code]}",
		defaultArea: ["{$value[province]}",'{$value[city]}','{$value[county]}'],
		onChange: data => {
			$('#area_code').val(data.countyCode);
			$('#province').val(data.province);
			$('#city').val(data.city);
			$('#county').val(data.county);
		}
	});

	var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)"></li>',
		gallery = $("#gallery"), galleryImg = $("#galleryImg"), galleryImgOrigin,
		uploader = $('#uploader'), maxsize = 1024 * 1024 * 2
		;
	uploader.on("change", '.uploaderInput', function(e){
		let uploaderFiles = $(this).parent().prev();
		if(uploaderFiles.children().length >= 1){
			return alert('一张图片够了');
		}
		var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
		for (var i = 0, len = files.length; i < len; ++i) {
			var file = files[i];
			if (!'image/jpeg, image/jpg, image/bmp, image/png'.match(file.type)) {
				return weui.topTips('图片格式不支持');
			}
			if (file.size > maxsize) {
				return weui.topTips('图片不能大于2M');
			}
			if (url) {
				src = url.createObjectURL(file);
			} else {
				src = e.target.result;
			}
			uploaderFiles.append($(tmpl.replace('#url#', src)));
		}
		$(this).parent().hide();
	});
	uploader.on("click", ".uploaderFiles li", function(){
		galleryImgOrigin = $(this);
		galleryImg.attr("style", this.getAttribute("style"));
		gallery.fadeIn(100);
	});
	gallery.on("click", function(){
		gallery.fadeOut(100);
	});
	$(".weui-gallery__del").click(function() {
		galleryImgOrigin.parent().next().show();
		galleryImgOrigin.remove();
	});

	$('textarea.weui-textarea').change(function(e){
		$(this).next().html('<span>' + this.value.length + '</span>/200');
	})

	//提交
	$('form button[name^="submit"]').click(function(ev) {
		weui.form.validate('form[name=form1]', function (error) {
			if (!error) {
				var data = new FormData(document.querySelector("form"));
				let submitType = $(this).attr('name') || 'submit2';
				data.append(submitType, submitType);
				var loading = weui.loading('加载中');
				$.ajax({
					type: 'POST',
					url:'/mo/merchant/detail',
					data: data,
					contentType: false,
					processData: false,
					success: result => {
						loading.hide();
						if(result.status == 1){
							weui.toast('操作成功');
							location.reload();
						}else{
							weui.topTips('修改失败:' + result.message);
						}
					},
					error: (xhr, errorType, error) => {
						loading.hide();
						weui.topTips('请求出错:' + xhr.status + ' ' + error);
					}
				})
			}
		});
		ev.preventDefault();
		return false;
	});

	//银行账户全称自动完成
	jQuery('form input[name=account_bank]').autoComplete({
		url: "{echo url('banks/index')}",
		field: "",
		value: "{$value[account_bank]}",
		name_hidden: "bank_code",
		value_hidden: "{$value[bank_code]}",
	});
	$('form input[name=account_bank]').focus(function() {
		$(this).parents('.weui-cell__bd').prev().animate({width: '0px'}, 200, 'ease-out')
	});
	$('form input[name=account_bank]').blur(function() {
		$(this).parents('.weui-cell__bd').prev().animate({width: '105px'}, 200, 'ease-out')
	});
	//根据进件类型显示字段
	$('.sign_type').on('click', 'input[type=checkbox]', e => {
		if (e.target.id == 'sign_alipay') {
			if (e.target.checked) {
				$('#alipay').parents('.weui-cell').show();
			}else{
				$('#alipay').parents('.weui-cell').hide();
			}
		}
		if (e.target.id == 'sign_weixin') {
			if (e.target.checked) {
				$('#per_id_number').parents('.weui-cell').show();
				$('input#weixin').val(1);
				$('#bank_account_type').parents('.weui-cell').show();
				$('#account_bank').parents('.weui-cell').show();
				$('#account_name').parents('.weui-cell').show();
				$('#account_number').parents('.weui-cell').show();
			}else{
				$('#per_id_number').parents('.weui-cell').hide();
				$('input#weixin').val(0);
				$('#bank_account_type').parents('.weui-cell').hide();
				$('#account_bank').parents('.weui-cell').hide();
				$('#account_name').parents('.weui-cell').hide();
				$('#account_number').parents('.weui-cell').hide();
			}
		}
	})
	$('.icon-tips').on('click', e => {
		weui.alert($(e.target).data('tips'), {className: 'tips'});
	})
	</script>
</body>
</html>