<?php
	$this->display(tpl('head',true));
	$attention=unserialize($settingDB['attention']);
?>
<style>
	.layui-form-label {
	    float: left;
	    display: block;
	    padding: 9px 15px;
	    width: 10%;
	    font-weight: 400;
	    text-align: right;
	}
	.layui-input, .layui-textarea {
	    display:  inline;
	    width: 80%;
	    padding-left: 10px;
	}
	.hr{
		margin-top: 10px;
		border: 1px solid #ddd;
	}
	.picurl{
		width: 58%;
		float: left;
	}
	.picurlbutton{
		float: left;
		margin-left: 10px;
	}
	.left{
		width: 80%;
	}
	.right{
		height: 300px;
		line-height: 300px;
		vertical-align:middle
	}
	.del{
		padding: 10px 20px;
		background-color: #1e9fff;
		color: #fff;
		border-radius: 5px;
	}.del:hover{
		color: red;
	}
</style>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	  	<legend>微信用户关注时回复内容设置</legend>
	</fieldset>
	<form class="layui-form" method="post">
		<table class="layui-table">
			<tbody>
				<tr>
					<td width="200">新用户关注微信时回复的纯文本内容：</td>
					<td>
						<textarea class="layui-textarea" name="wechat[attention][text]"><?php echo $attention[text] ?></textarea>
					</td>
				</tr>
				<tr>
					<td width="200">新用户关注微信时回复的图文并茂内容：<a onclick="add()">添加一组</a></td>
					<td>
						<div id="list">
							<div class="layui-form-item">
								<label class="layui-form-label">标题</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][0][title]" value="<?php echo $attention['list'][0][title] ?>"  placeholder="请输入标题" class="layui-input" type="text">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">描述</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" placeholder="描述内容" name="wechat[attention][list][0][description]"><?php echo $attention['list'][0][description] ?></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">图片</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][0][picurl]" id="pic0" value="<?php echo $attention['list'][0][picurl] ?>"  placeholder="请输入图片" class="layui-input picurl" type="text">
									<button type="button" class="layui-btn layui-btn-normal picurlbutton" id="select_pic">选择图片上传</button>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">链接</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][0][url]" value="<?php echo $attention['list'][0][url] ?>"  placeholder="请输入链接" class="layui-input" type="text">
								</div>
							</div>
						</div>
						<?php foreach($attention['list'] as $key=>$row){ if($key=='0'){continue;} ?>
							<div id="list<?php echo $key ?>"><hr>	<div class="left">	<div class="layui-form-item">
								<label class="layui-form-label">标题</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][<?php echo $key ?>][title]" value="<?php echo $attention['list'][$key][title] ?>"  placeholder="请输入标题" class="layui-input" type="text">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">描述</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" placeholder="描述内容" name="wechat[attention][list][<?php echo $key ?>][description]"><?php echo $attention['list'][$key][description] ?></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">图片</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][<?php echo $key ?>][picurl]" id="pic<?php echo $key ?>" value="<?php echo $attention['list'][$key][picurl] ?>"  placeholder="请输入图片" class="layui-input picurl" type="text">
									<button type="button" class="layui-btn layui-btn-normal picurlbutton" id="select_pic<?php echo $key ?>">选择图片上传</button>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">链接</label>
								<div class="layui-input-block">
									<input name="wechat[attention][list][<?php echo $key ?>][url]" value="<?php echo $attention['list'][$key][url] ?>"  placeholder="请输入链接" class="layui-input" type="text">
								</div>
							</div></div><div class="right"><a onclick="del('<?php echo $key ?>')" class="del" >移除</a></div>	</div>
							<script>
	layui.use(["form","table", "upload"], function(){
  	var $ = layui.jquery,table=layui.table;
	var form = layui.form;
	upload = layui.upload;
	upload.render({
	    elem: "#select_pic<?php echo $key ?>",
	    url: "/admin/upfile/up",
	    auto: true,
	    before: function(obj){
	    	files = obj.pushFile(); 
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.Result==0){
		    	layer.msg(res.content);
		    }else{
		      	$("#pic<?php echo $key ?>").val(res.url); 
		    }
		    delete files[index]; 
	    }
	});
});
</script>
						<?php }?>
						
					</td>
				</tr>
			</tbody>
		</table>
		<div class="layui-form-item">
			<div class="layui-input-block my_button">
				<input type="hidden" name="step" value="post" />
				<button class="layui-btn">立即设置</button>
			</div>
		</div>
	</form>
	<blockquote class="layui-elem-quote layui-text">
		<li>非认证的公众号，不能同时使用纯文本与图文信息，如果要使用第二种图文方式的话，就请把第一项清空</li>
		<li>如果要使用第二种图文方式的话，标题，描述，图片，链接务必都要填写</li>
		<li>图片链接，支持JPG、PNG格式，较好的效果为大图360*200，小图200*200</li>
	</blockquote>
<script>
function del(a){
	$("#list"+a).remove();
}
var num= '<?php intval(count($attention['list'])); ?>';
function add(){
	num = Number(num)+1;
	if(num>6){
		alert('只允许创建7条');
		return false;
	}
	
	var str=	'<div id="list'+num+'"><hr>	<div class="left">	<div class="layui-form-item">'
			+'				<label class="layui-form-label">标题</label>'
			+'				<div class="layui-input-block">'
			+'					<input name="wechat[attention][list]['+num+'][title]" value=""  placeholder="请输入标题" class="layui-input" type="text">'
			+'				</div>'
			+'			</div>'
			+'			<div class="layui-form-item">'
			+'				<label class="layui-form-label">描述</label>'
			+'				<div class="layui-input-block">'
			+'					<textarea class="layui-textarea" placeholder="描述内容" name="wechat[attention][list]['+num+'][description]"></textarea>'
			+'				</div>'
			+'			</div>'
			+'			<div class="layui-form-item">'
			+'				<label class="layui-form-label">图片</label>'
			+'				<div class="layui-input-block">'
			+'					<input name="wechat[attention][list]['+num+'][picurl]" id="pic'+num+'" value=""  placeholder="请输入图片" class="layui-input picurl" type="text">'
			+'					<button type="button" class="layui-btn layui-btn-normal picurlbutton" id="select_pic'+num+'">选择图片上传</button>'
			+'				</div>'
			+'			</div>'
			+'			<div class="layui-form-item">'
			+'				<label class="layui-form-label">链接</label>'
			+'				<div class="layui-input-block">'
			+'					<input name="wechat[attention][list]['+num+'][url]" value=""  placeholder="请输入链接" class="layui-input" type="text">'
			+'				</div>'
			+'			</div></div><div class="right"><a onclick="del(\''+num+'\')" class="del" >移除</a></div>	</div><script>layui.use(["form","table","upload"],function(){var $=layui.jquery,table=layui.table;var form=layui.form;upload=layui.upload;upload.render({elem:"#select_pic'+num+'",url:"/admin/upfile/up",auto:true,exts:"jpg|png",before:function(obj){files=obj.pushFile();loading=layer.load()},done:function(res,index,upload){layer.close(loading);if(res.Result==0){layer.msg(res.content)}else{$("#pic'+num+'").val(res.url)}delete files[index]}})});<\/script>';
	
	$("#list").append( str );
}
layui.config({
	version: '<?php echo NOWTIME ?>'
});
layui.use(['form','table', 'upload'], function(){
  	var $ = layui.jquery,table=layui.table;
	var form = layui.form;
	upload = layui.upload;
	upload.render({
	    elem: '#select_pic',
	    url: '/admin/upfile/up',
	    auto: true,
	    exts:'jpg|png',
	    before: function(obj){
	    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.Result==0){
		    	layer.msg(res.content);
		    }else{
		      	$('#pic0').val(res.url); 
		    }
		    delete files[index]; //删除对应的文件
	    }
	});
});
	


</script>
<?php
	$this->display(tpl('foot',true));
?>
