<?php 
$this->display(tpl('head',true));
$is_required[intval($edit['is_required'])]=" checked";
if(intval($edit['is_required'])){
	$zzyz="";
}else{
	$zzyz=" style='display: none;'";
}
$zhengzeyanzheng[$edit['ziduan_zhengzeyanzheng']]="selected";
if($edit['is_xss']){
	$XSS="checked";
}
if($edit){
	$selectleibie[$edit['type']]="selected";
}else{
	$selectleibie['Text']="selected";
}
$edit ? $is_search[intval($edit[is_search])]=" checked" :  $is_search['0']=" checked";

?>
<style>
	.layui-tab{
		padding-left: 20px;
	}
	.layui-field-box{
		color: red;
	}
	.layui-form-select {
	    position: relative;
	    width: 30%;
		
	}
	.pattern .layui-form-select{
		float: left;
		margin-left: 10px;
	}
	.layui-input-my {
	    display: block;
	    width: 30%;
	    padding-left: 10px;
	    float: left;
	}
	.layui-input-block p{
		margin-top: 10px;
		color: #aaa;
		width: 100%;
		float: left;
	}
	.layui-input-block span{
		height: 35px;
		line-height: 35px;
		padding-left: 10px;
	}
	.layui-textarea {
	    display: block;
	    width: 30%;
	    padding-left: 10px;
	}
	.layui-form-switch {
	    width: 80px;
		height: 25px;
		line-height: 25px;
	}
	.layui-form-switch em {
	    width: 50px;
	}
	.layui-form-onswitch i {
	    left: 70px;
	    background-color: #fff;
	}
	.name{
		height: 35px;
		line-height: 35px;
	}
</style>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>创建字段</legend>
</fieldset>
<form class="layui-form" method="post">
<div class="layui-tab">
	<ul class="layui-tab-title">
	  <li class="layui-this">网站设置</li>
	  <li>数据验证</li>
	</ul>
	<div class="layui-tab-content">
	  	<div class="layui-tab-item layui-show">
	    	<div class="layui-form-item layui-form-text">
	    		<label class="layui-form-label">所属模型</label>
	    		<div class="layui-input-block name">
	    			<?php echo $data[name] ?>
	    		</div>
	    	</div>
	    	<div class="layui-form-item layui-form-text">
	    		<label class="layui-form-label">属性名称</label>
	    		<div class="layui-input-block">
	    			<input name="post[name]" id="ziduanmingcheng" value="<?php echo $edit[name] ?>"  class="layui-input layui-input-my" type="text">
	    			<p>为字段取个名字，例如：文档标题、作者、来源等等</p>
	    		</div>
	    	</div>
	    	<div class="layui-form-item layui-form-text">
	    		<label class="layui-form-label">属性字段KEY</label>
	    		<div class="layui-input-block">
	    			<input name="post[field]" id="field_key" value="<?php echo $edit[field] ?>"  class="layui-input layui-input-my" type="text">
	    			<p>只能由英文字母、数字组成可带下划线_，可不填写会自动生成。首个字符必须以字母开始。小于三个字符将会自动生成</p>
	    		</div>
	    	</div>
	    	<div class="layui-form-item">
	    		<label class="layui-form-label">类别</label>
	    		<div class="layui-input-block">
	    			<select name="post[type]" lay-filter="field_type">
	    				<option value="">请选择一个类别</option>
	    				<option value="Checkbox" <?php echo $selectleibie['Checkbox'] ?>>复选框(Checkbox) </option>
	    				<option value="Date" <?php echo $selectleibie['Date'] ?>> 日期时间(Date) </option>
	    				<option value="File" <?php echo $selectleibie['File'] ?>> 单文件(File) </option>
	    				<option value="Files" <?php echo $selectleibie['Files'] ?>> 多文件(Files) </option>
	    				<option value="Radio" <?php echo $selectleibie['Radio'] ?>> 单选按钮(Radio) </option>
	    				<option value="Select" <?php echo $selectleibie['Select'] ?>> 下拉选择(Select) </option>
	    				<option value="Text" <?php echo $selectleibie['Text'] ?>> 单行文本(Text) </option>
	    				<option value="Textarea" <?php echo $selectleibie['Textarea'] ?>> 多行文本(Textarea) </option>
	    				<option value="Ueditor" <?php echo $selectleibie['Ueditor'] ?>> 百度编辑器(Ueditor) </option>
						<option value="Price" <?php echo $selectleibie['Price'] ?>> 价格选择器 (用于商城的多属性价格发布)</option>
	    			</select>
	    		</div>
	    	</div>
	    	<div class="layui-form-item">
				<label class="layui-form-label">是否进行检索</label>
				<div class="layui-input-block">
					<input name="post[is_search]" <?php echo $is_search[0] ?> value="0" title="关闭检索" type="radio" >
					<input name="post[is_search]" <?php echo $is_search[1] ?> value="1"  title="开启检索" type="radio">
					<p>只有选择可以检索,才能在前台检索.只对价格选择器有效</p>
				</div>
			</div>
			
			<div id="shuxing"><?php echo $html ?></div>
			<div class="layui-form-item">
				<label class="layui-form-label">单位名称</label>
				<div class="layui-input-block">
					<input name="post[unit]" id="field_key" value="<?php echo $edit[unit] ?>"  class="layui-input layui-input-my" type="text">
					<p>需要时填写，比如:个,吨,件,包</p>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<div class="layui-input-block">
					<input name="post[reorder]" id="field_key" value="<?php echo $edit[reorder] ?>"  class="layui-input layui-input-my" type="text">
					<p>数值高的在上面</p>
				</div>
			</div>
	    	<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="step" id="step" value="post" />
				<?php if($edit){ ?>
					<button class="layui-btn">修改属性</button>
				<?php }else{ ?>
					<button class="layui-btn">创建属性</button>
				<?php } ?>	
				</div>
			</div>
		</div>
		<div class="layui-tab-item">
			<div class="layui-form-item">
				<label class="layui-form-label">是否必填项</label>
				<div class="layui-input-block">
					<input name="post[is_required]" value="1" lay-filter="if_required" title="是" type="radio" <?php echo $is_required[1] ?>>
					<input name="post[is_required]" value="0" lay-filter="if_required" title="不是" type="radio"  <?php echo $is_required[0] ?>>
				</div>
			</div>
			<div class="layui-form-item pattern" id="bt1"<?php echo $zzyz ?>>
				<label class="layui-form-label">正则验证</label>
				<div class="layui-input-block">
					<input name="post[regular]" value="<?php echo $edit[regular] ?>" id="validate_pattern" class="layui-input layui-input-my">
					<select lay-filter="field_validate_pattern">
						<option value="">正则验证</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9.-]+$/'] ?> value="/^[0-9.-]+$/">数字</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9-]+$/'] ?> value="/^[0-9-]+$/">整数</option>
						<option <?php echo $zhengzeyanzheng['/^[a-z]+$/i'] ?> value="/^[a-z]+$/i">字母</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9a-z]+$/i'] ?> value="/^[0-9a-z]+$/i">数字+字母</option>
						<option <?php echo $zhengzeyanzheng['/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/'] ?> value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9]{5,20}$/'] ?> value="/^[0-9]{5,20}$/">QQ</option>
						<option <?php echo $zhengzeyanzheng['/^(http|https):\/\//'] ?> value="/^(http|ftp|https):\/\//">URL链接</option>
						<option <?php echo $zhengzeyanzheng['/^(1)[0-9]{10}$/'] ?> value="/^(1)[0-9]{10}$/">手机号码</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9-]{6,13}$/'] ?> value="/^[0-9-]{6,13}$/">电话号码</option>
						<option <?php echo $zhengzeyanzheng['/^[0-9]{6}$/'] ?>value="/^[0-9]{6}$/">邮政编码</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item"  id="bt2" <?php echo $zzyz ?>>
				<label class="layui-form-label">验证提示</label>
				<div class="layui-input-block">
					<input name="post[regular_msg]" class="layui-input layui-input-my" value="<?php echo $edit[regular_msg] ?>">
					<p>当字段校验未通过时的提示信息，如“标题必须在80字以内”等等</p>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">XSS过滤</label>
				<div class="layui-input-block">
					<input name="post[is_xss]" value="0" id="ziduan_xssguolv" type="checkbox"  lay-filter="ziduan_xssguolv" lay-skin="switch" lay-text="已开启|已关闭" <?php echo $XSS ?>>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">字段提示</label>
				<div class="layui-input-block">
					<input name="post[msg]" id="ziduan_tishi" class="layui-input layui-input-my"  value="<?php echo $edit['msg'] ?>">
					<p>对字段简短的提示，来说明这个字段是用来干什么的</p>
				</div>
			</div>
		</div>
	</div>
</div>
</form>
<script>
	layui.use(['form','element'], function(){
	  	var form = layui.form;
	  	var element = layui.element;
		form.on('select(field_type)', function(data){
			htmlobj=$.ajax({url:"<?php echo admin_module_url ?>/module/ajax_field/type_"+data.value,async:false});
			$("#shuxing").html(htmlobj.responseText);
			form.render();
		});
		form.on('select(field_validate_pattern)', function(data){
			$("#validate_pattern").val(data.value);
		});
		form.on('radio(if_required)', function(data){
			if(data.value==1){
				document.getElementById("bt1").style.display="";
				document.getElementById("bt2").style.display="";
			}else{
				document.getElementById("bt1").style.display="none";
				document.getElementById("bt2").style.display="none";
			}
		});
		
		form.on('radio(ziduan_is_down)', function(data){
			if(data.value==1){
				$('#ziduan_is_down').show();
			}else{
				$('#ziduan_is_down').hide();
			}
		});
		
		form.on('radio(ziduan_play)', function(data){
			if(data.value=='video' || data.value=='audio'){
				$('#ziduan_play').show();
				$('#ziduan_play1').show();
				$('#ziduan_is_down').hide();
				$('#ziduan_down_url_list').hide();
			}else if(data.value=='txt' || data.value=='rar' || data.value=='all'){
				$('#ziduan_is_down').show();
				$('#ziduan_down_url_list').show();
				$('#ziduan_play').hide();
				$('#ziduan_play1').hide();
			}else{
				$('#ziduan_is_down').hide();
				$('#ziduan_down_url_list').hide();
				$('#ziduan_play').hide();
				$('#ziduan_play1').hide();
			}
		});
		form.on('radio(ziduan_is_play)', function(data){
			if(data.value==1){
				$('#ziduan_is_play').show();
			}else{
				$('#ziduan_is_play').hide();
			}
		});
		form.on('switch(ziduan_xssguolv)', function(data){
		    if(this.checked==true){
		    	$("#ziduan_xssguolv").val('1');
		    	layer.tips('温馨提示：已开启XSS过滤', data.othis);
		    }else{
		    	$("#ziduan_xssguolv").val('0');
		    	layer.tips('温馨提示：已关闭XSS过滤', data.othis);
		    }
		});
	});
</script>

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