<?php $this->display(tpl('head')); ?>
<?php 
	if($edit['bold']){
		$bold='checked';
	}
	if($nid>1){
		$display="style='display:none'";
	}
	$is_comment[$edit['is_comment']] ='checked';
?>
<style>
	.layui-form-select{
		width: 30%;
	}
	.special{
		width: 200px;
	}
</style>
<script src="/public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>添加文章</legend>
</fieldset>
<form class="layui-form" method="post" action="">
	<div class="layui-tab">
		<ul class="layui-tab-title" $display>
			<li class="layui-this">网站设置</li>
			<li>模型</li>
			<li>专题设置</li>
			<li>其它</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<table class="layui-table my-tabel">
					<tbody>
						<tr>
							<td>所属栏目</td>
							<td>
								<select name="post[cid]" lay-filter="ciddb" class=" my-input">
		    						<option value="">请选择要发布到的栏目</option>
									<?php
									foreach($allcidDB AS $rs){
										$selected="";
										if($rs['cid']==$cid){
											$selected=" selected";
										}
										$dis="";
										if($rs[type] !==0){
											$dis="disabled";
										}
									?>
									<option value="<?php echo $rs[cid] ?>" type="<?php echo $rs[type] ?>"  mid="<?php echo $rs[cmid] ?>" <?php echo $selected;echo  $dis ?>><?php echo $rs[levels];echo $rs[name]?></option>\r\n
									<?php } ?>
			    				</select>
							</td>
						</tr>
						<tr>
							<td>标题</td>
							<td>
								<input name="post[title]" value="<?php echo $edit[title] ?>"  lay-verify="required|title" placeholder="请输入标题" class="layui-input my-input" type="text">
								颜色
								<input name="post[color]" id="color" class="layui-input my-input color" type="text" value="<?php echo $edit[color] ?>">
								<input name="post[bold]" title="加粗" type="checkbox" value="1" <?php echo $bold ?>>
								<div id="picker"></div>
				    			<script type="text/javascript">
				    				$("#color").css('background-color','#<?php echo $edit[color] ?>');
				    				$("#color").css('color','#fff');
				    				$('#color').colpick({
										layout:'hex',
										submit:0,
										colorScheme:'dark',
										onChange:function(hsb,hex,rgb,el,bySetColor) {
											$(el).css('border-color','#'+hex);
											$(el).css('color','#FFF');
											$(el).css('background-color','#'+hex);
											if(!bySetColor) $(el).val(hex);
										}
									}).keyup(function(){
										$(this).colpickSetColor(this.value);
									});
				    			</script>
				    			
							</td>
						</tr>
						<tr>
							<td>关键字</td>
							<td>
								<input name="post[keyword]"  class="layui-input my-input" type="text" value="<?php echo $edit[keyword] ?>">
								<p>作为相关文章的索引,如多个用空格隔开</p>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<table class="layui-table my-tabel">
									<tbody>
										<tr>
											<td>作者</td>
											<td><input name="post[author]" class="layui-input" type="text" value="<?php echo $edit[author] ?>"></td>
											<td>来源</td>
											<td><input name="post[source]" class="layui-input" type="text" value="<?php echo $edit[source] ?>"></td>
											<td>来源网址</td>
											<td><input name="post[source_url]" class="layui-input" type="text" value="<?php echo $edit[source_url] ?>"></td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="2">
								<table class="layui-table my-tabel">
									<tbody>
										<tr>
											<td>是否禁止评论</td>
											<td><input name="post[is_comment]" class="layui-input" type="checkbox" value="1" title="勾选禁止评论" <?php echo $is_comment[1] ?>></td>
											<td>查看积分</td>
											<td><input name="post[sell_jifen]" class="layui-input" type="text" value="<?php echo $edit[sell_jifen] ?>"></td>
											<td>查看密码</td>
											<td><input name="post[password]" class="layui-input" type="text" value="<?php echo $edit[password] ?>"></td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
						<tr>
							<td>缩略图</td>
							<td>
								<input name="post[thumb]" id="thumb" class="layui-input  my-input" type="text" value="<?php echo $edit[thumb] ?>">
			    				<button type="button" class="layui-btn layui-btn-normal" id="select_pic">选择图片上传</button>
							</td>
						</tr>
						<tr>
							<td>内容</td>
							<td>
								<?php
									$num=count($cont_query);
									if($num >1){
								?>
								<div class="page">
									<?php
										$i=0;
										$num=count($cont_query);
										if($num >1)
										foreach($cont_query AS $row){
											$i++;
									?>
										<a href="javascript:void(0);" onclick="return content('<?php echo $row[nid] ?>','<?php echo $row[content] ?>',this);"> 第<?php echo $i ?>页</a>
									<?php } ?>
								</div>
								<?php } ?>
								<p>如果是多页在要分页的地方插入##page##</p>
								<textarea name="post[content]" style="height:300px; width: 100%; z-index: 1;" id="content" placeholder="请输入内容" ><?php echo $cont_query['0'][content] ?></textarea>
								<script type="text/javascript">
									var ue = UE.getEditor('content',{
										zIndex : 900,
										autoHeightEnabled:false,
								        // 服务器统一请求接口路径
								        serverUrl: "/admin/index/plugin/ueditor/index/ueditor_config/",
								        toolbars: [[
								             'source', '|', 'undo', 'redo', '|',
								            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
								            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
								            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
								            'directionalityltr', 'directionalityrtl', 'indent', '|',
								            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
								            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
								            'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
								            'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
								            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
								            'print', 'preview', 'searchreplace', 'drafts', 'help'
								        ]]});
								</script>
							</td>
						</tr>
						<tr>
							<td colspan="2" align="center">
								<input type="hidden" name="post[aid]" value="<?php echo $edit[aid] ?>" />
								<input type="hidden" id="nid" name="post[nid]" value="<?php echo $cont_query['0'][nid] ?>" />
								<input type="hidden" name="post[step]" value="post" />
								<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
							</td>
							<script>
								var _this='';
								function content(nid,content,THIS){
									console.log(nid);
									if(_this){
										_this.style.backgroundColor='';
										_this.style.color ='';
										_this.style.fontWeight ='';
									}
									_this=THIS;
									ue.setContent(content);
									$("#nid").val(nid);
									console.log(THIS);
									THIS.style.backgroundColor='red';
									THIS.style.color ='#fff';
									THIS.style.fontWeight ='bold';
								}
								
							</script>
						</tr>
					</tbody>
				</table>
					
			</div>

			<div class="layui-tab-item">
				<table class="layui-table my-tabel">
					<tr>
						<td>所属内容模型</td>
						<td>
							<select name="post[mid]"  lay-filter="middb">
		    				<option value="">不使用模型</option>
<?php
foreach($moduleDB AS $rs){
	if($mid){
		$m[$mid]="selected";
	}
?>
               				<option value="<?php echo $rs[id] ?>" <?php echo $m[$rs['id']] ?>><?php echo $rs[name] ?></option>
<?php } ?>

		    				</select>
						</td>
					</tr>
				</table>
				<table class="layui-table my-tabel" id="model_content">
					<tr>
						<td>
							<?php echo $Custom_Model_Template ?>
						</td>
					</tr>
				</table>
			</div>
			<div class="layui-tab-item">
				<style>
					.special_select input[type="checkbox"]{
						width: 35px;
					}
				</style>
				<table class="layui-table my-tabel special_select">
					<tr>
						<td>所属专题(可多选)</td>
						<td>
							<?php foreach($special_list AS $row){ 
								$checked="";
								if(in_array($row[id],$selected_special_list)){
									$checked=" checked";
								}
							?>
							<label><input type="checkbox" lay-ignore name="special[]"  value="<?php echo $row[id] ?>" <?php echo $checked ?>/><?php echo $row[name] ?></label>
							<?php } ?>
						</td>
					</tr>
				</table>
				
			</div>
			<div class="layui-tab-item">
				<table class="layui-table my-tabel">
					<tbody>
						<tr>
							<td>发布时间</td>
							<td><input name="post[posttime]" id="posttime" class="layui-input my-input" type="text" value="<?php echo $edit[posttime] ?>"></td>
						</tr>
						<tr>
							<td>访问量</td>
							<td>
								<input name="post[clicks]" class="layui-input my-input" type="text" value="<?php echo $edit[clicks] ?>">
							</td>
						</tr>
						<tr>
							<td>简介</td>
							<td>
								<textarea class="layui-textarea  my-input" id="description" name="post[description]"><?php echo $edit[description] ?></textarea>
							</td>
						</tr>
						<tr>
							<td>SEO标题</td>
							<td>
								<input name="post[seotitle]" class="layui-input my-input" type="text" value="<?php echo $edit[seotitle] ?>">
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
  	</div>
</div>
</form>
<script>
	layui.config({
		version: '<?php echo NOWTIME ?>'
	});
	layui.use(['upload','form','layer','element','laydate'], function(){
	  	var $ = layui.jquery
	  	,element = layui.element
	  	,upload = layui.upload;
	   	var $ = layui.jquery, layer = layui.layer;
		var form = layui.form;
		form.on('select(ciddb)', function(data){
			var type=data.elem.selectedOptions[0].attributes.type.value;
			var mid=data.elem.selectedOptions[0].attributes.mid.value;
			if(type !=0){
				$('.layui-btn').attr("disabled",true);
				alert("只有栏目才可以发布内容，请重新选择");
				return false;
			}else if(data.value > 0){
				<?php if($edit){ ?>
					window.location.href='/admin/articles/edit/cid_'+data.value+'/aid_<?php echo $edit[aid] ?>';
				<?php }else{ ?>
					window.location.href='/admin/articles/add/cid_'+data.value;
				<?php } ?>
				$('.layui-btn').attr("disabled",false); 
			}
		});
		var laydate = layui.laydate;
		laydate.render({
			elem: '#posttime',
			type: 'datetime'
		});
		form.verify({
		    title: function(value){
			    if(value.length < 5){
			        return '标题至少得5个字符啊';
			    }
		    }
	  	});
	
		form.on('select(middb)', function(data){
			if(data.value !=0){
				htmlobj=$.ajax({url:"/admin/articles/ajax_module/mid_"+data.value,async:false});
				$("#model_content").html(htmlobj.responseText);
				form.render();
				return false;
			}
		});
		
		
		//选完文件后不自动上传
		upload.render({
		    elem: '#select_pic',
		    url: '/admin/upfile/up/thumb_1/json_true/',
		    auto: true,
		    bindAction: '#star_upload',
		    before: function(obj){
		    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
		    	loading = layer.load();
		    },
		    done: function(res, index, upload){
		    	layer.close(loading);
			    if(res.code != 0){
			    	layer.msg(res.text);
			    }else{
			      	$('#thumb').val(res.url); 
			    }
			    delete files[index]; //删除对应的文件
		    }
		});
	});	  
</script>

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