<div class="panel panel-warning">
	<div class="panel-heading">
		<h4 class="panel-title">
			<span class="glyphicon glyphicon-filter btn-xs"></span>
			查找/筛选/过滤
			<small>(带*项目可模糊查询)</small>
		</h4>
	</div>
	<div class="panel-body">
		<form class="form-inline" action="" method="GET" onsubmit="return procFilterData();">
			{% for i in textitems %}
				<div class="form-group">
					<label class="sr-only" for="{{i.ctid}}">{{i.title}}</label>
					<input type="text" class="form-control" id="{{i.ctid}}" name="{{i.ctname}}" placeholder="{{i.title}}" value="{{i.value}}" />
				</div>
			{% endfor %}
			{% for i in valitems %}
				<div class="form-group">
					<label class="sr-only" for="{{i.ctid}}">{{i.title}}</label>
					<input type="text" class="form-control" id="{{i.ctid}}" name="{{i.ctname}}" placeholder="{{i.title}}" value="{{i.value}}" />
				</div>
			{% endfor %}
			{% for i in dateeqi %}
				<div class="form-group">
					<label class="sr-only" for="{{i.ctid}}">{{i.title}}</label>
					<input type="text" class="form-control" id="{{i.ctid}}" name="{{i.ctname}}" placeholder="{{i.title}}" value="{{i.value}}" />
				</div>
			{% endfor %}
			{% for i in datergi %}
				<div class="form-group">
					<label class="sr-only" for="{{i.ctid}}">{{i.title}}</label>
					<input type="hidden" id="{{i.ctid}}" class="datergi-res" name="{{i.ctname}}"/>
					<input type="text" class="form-control datergi-st" id="rgl_{{i.ctid}}" name="{{i.ctname}}" placeholder="{{i.title}}（起始日期）" value="{{i.valuest}}" />~
					<input type="text" class="form-control datergi-ed" id="rgr_{{i.ctid}}" name="{{i.ctname}}" placeholder="{{i.title}}（结束日期）" value="{{i.valueed}}" />
				</div>
			{% endfor %}
			{% for i in scitems %}
				<div class="form-group">
					<label for="{{i.ctid}}">{{i.title}}</label>
					<select class="form-control" id="{{i.ctid}}" name="{{i.ctname}}">
						<option value="all">全部</option>
						{% for j in i.oplst %}
							<option value="{{forloop.counter0}}">{{j}}</option>
						{% endfor %}
					</select>
				</div>
			{% endfor %}
			{% for i in mcitems %}
				<div class="form-group">
					<label for="{{i.ctid}}">{{i.title}}</label>
					<input type="hidden" id="smf_{{i.ctid}}" class="cmcres" name="{{i.ctname}}"/>
					<select multiple class="form-control cmcbox" id="{{i.ctid}}">
						{% for j in i.oplst %}
							<option value="{{forloop.counter0}}">{{j}}</option>
						{% endfor %}
					</select>
				</div>
			{% endfor %}
			<button type="submit" class="btn btn-primary">
				<span class="glyphicon glyphicon-ok btn-xs"></span>
				提交
			</button>
		</form>
		<script type="text/javascript">
			function InitSC(){
				{% for i in scitems %}
				$("#{{i.ctid}}").val("{{i.value}}");
				{% endfor %}
			}
			function MCSet(ctid,sllt){
				var ar=Array();
				ar=sllt.split(',');
				for (var i = ar.length - 1; i >= 0; i--) {
					var ia=ar[i];
					console.log("#"+ctid+" option[value="+ia+"]");
					$("#"+ctid+" option[value="+ia+"]").attr('selected',true);
				};
				$("#"+ctid).val("{{i.value}}");
			}
			function InitMC(){
				{% for i in mcitems %}
				MCSet("{{i.ctid}}","{{i.value}}");
				{% endfor %}
			}
			function procFilterData(){
				$(".datergi-res").each(
					function(){
						var oid=$(this).attr('id');
						if($('#rgl_'+oid).val() && $('#rgr_'+oid).val()){
							$(this).val($('#rgl_'+oid).val()+"~"+$('#rgr_'+oid).val());
						}else{
							$(this).remove();
						}
						$('#rgl_'+oid).remove();
						$('#rgr_'+oid).remove();
					}
				);
				$(".cmcbox").each(
					function(){
						var sla=Array();
						var oid=$(this).attr('id');
						var sol=$("#"+oid+' option:selected');
						for (var i = sol.length - 1; i >= 0; i--) {
							var iv=$(sol[i]);
							sla.push(iv.val());
						};
						$("#smf_"+oid).val(sla.join(','));
						//$(this).remove();
					}
				);
				
				$("select").each(
					function(){
						if(!$(this).val()){
							$(this).remove();
						}
						if($(this).val()=="all"){
							$(this).remove();
						}
					}
				);
				$("input").each(
					function(){
						if(!$(this).val()){
							$(this).remove();
						}
					}
				);
				//return confirm('确认***吗？？');
			}
			InitSC();
			InitMC();
		</script>
	</div>
</div>