<extend name="Public:base" />

<block name="content">

<div class="page-header">
</div>	
	
<table class="table table-striped table-bordered table-hover search-form">
	<thead>
		<th><input name="name" type="text" placeholder="输入商品名称" value="{:I('name')}" /></th>
		<th>
			<select name="store_id">
				<option value="">-选择商家-</option>
				
				<volist name="seller_list" id="v" >
					<option <?php if(isset($get_store)&&($get_store==$v['s_id'])){echo ' selected="selected"';} ?> value="{$v.s_id}">{$v.s_true_name}</option>
				
				</volist>	
			</select>
		</th>
		<th>    				
			<select name="category">
				<option value="">-选择分类-</option>
				<volist name="category" id="v" >
					<option <?php if(isset($get_category)&&($get_category==$v['id'])){echo ' selected="selected"';} ?> value="{$v.id}">{$v.name}</option>
				
					<volist name="v.children" id="vv" >
					<option <?php if(isset($get_category)&&($get_category==$vv['id'])){echo ' selected="selected"';} ?> value="{$vv.id}">　　{$vv.name}</option>
						<volist name="vv.children" id="vvv" >
						<option <?php if(isset($get_category)&&($get_category==$vvv['id'])){echo ' selected="selected"';} ?> value="{$vvv.id}">　　　　{$vvv.name}</option>
						</volist>	
					</volist>	
					
				</volist>	
			</select>
		</th>	
		<th>    										
			<select name="type">
				<option value="activity">-全部活动类型-</option>		
				<option <?php if(isset($type)&&($type=='pintuan')){echo ' selected="selected"';} ?> value="pintuan">拼团活动</option>
				
				<option <?php if(isset($type)&&($type=='lottery')){echo ' selected="selected"';} ?> value="lottery">抽奖</option>
				<option <?php if(isset($type)&&($type=='subject')){echo ' selected="selected"';} ?> value="subject">主题活动</option>
				<option <?php if(isset($type)&&($type=='spike')){echo ' selected="selected"';} ?> value="spike">限时秒杀</option>
				
			</select>
		</th>
		<th>    				
			<select name="status">
				<option value="">-选择状态-</option>				
				<option <?php if(isset($get_status)&&($get_status==1)){echo ' selected="selected"';} ?> value="1">启用</option>
				<option <?php if(isset($get_status)&&($get_status==0)){echo ' selected="selected"';} ?> value="0">停用</option>
			</select>
		</th>
		<th>
			<a class="btn btn-primary" href="javascript:;" id="search" url="{:U('Goods/activity')}">查询</a>
		</th>
	</thead>
</table>	
<div class="row">
	<div class="alert alert-info" id="alert_info">
		<button type="button" class="close" data-dismiss="alert">
			<i class="ace-icon fa fa-times"></i>
		</button>
		<p id="alert_content">
		</p>
	</div>
</div>	
<div class="row">
	<div class="col-xs-12">	
		<div class="table-responsive">
			<table id="table" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th class="center">
							<label>
								<input type="checkbox" class="ace check-all" />
								<span class="lbl"></span>
							</label>
						</th>											
						<th>ID</th>
						<th>图片</th> 
						<th>商品名称</th> 
						<th>分类</th> 
						<th>首页推荐</th>
						<th>首页排序</th>
						<th>价格</th>
						<th>库存数量</th>
						<th>所属商家</th>
						<th>状态</th>						
						<th>操作</th>				
					</tr>
				</thead>
				<tbody>
						<volist name="list" id="v" empty="$empty">
						<tr>		
							<td class="center">
							<label>
								<input class="ace ids" type="checkbox" name="id[]" value="{$v.goods_id}"/>
								<span class="lbl"></span>
							</label>
							</td>				
							<td>{$v.goods_id}</td>
							<td>
								<?php if($v['image']){ ?>
								<img src="__ROOT__/{$v.image}" />
								<?php }else{ ?>
								<img src="__ROOT__/Common/image/no_image_50x50.jpg" />
								<?php } ?>	
							</td>
							<td>{$v.name}</td>
							<td>{$v.class_name1}&nbsp;{$v.class_name2}&nbsp;{$v.class_name3}
							<br/>
							<?php 
								switch($v['type'])
								{
									case 'pintuan':
										echo '<b class="red">拼团活动</b>';
									break;
									case 'lottery':
										echo '<b class="red">抽奖活动</b>';
									break;
									case 'subject':
										echo '<b class="red">主题活动</b>';
									break;
									case 'spike':
										echo '<b class="red">限时秒杀</b>';
									break;
								}
							?>
				
							</td>
							<td>
							<label class="inline">
								<input gid="{$v.goods_id}" <?php if($v['is_index_show'] == 1){ ?> checked <?php } ?> type="checkbox" class="id-pills-stacked ace ace-switch ace-switch-5">
								<span class="lbl middle"></span>
							</label>
							</td>
							<td>
								<input type="text" gid="{$v.goods_id}" name="index_sort" value="{$v.index_sort}" class="index_sort" />
							</td>
							<td>{$v.price}</td>
							<td>{$v.quantity}</td>
							<td>
								<?php echo $seller_key_list[$v['store_id']]; ?>
							</td>
							<td>
								<switch name="v.status">
									<case value="1"><span class="green bold">启用</span></case>
									<case value="0"><span class="red">停用</span></case>
								</switch>
							</td>
							<td>
								<a  class="btn btn-xs btn-info" href='{:U("Goods/edit",array("id"=>$v["goods_id"]))}'>
									<i class="icon-edit bigger-120"></i>编辑
								</a> 
								
								<?php if($v['status'] != 4) { ?>
								<a  class="btn btn-xs btn-info backhuiche"  href="javascript:;" rel='{:U("Goods/backhuiche",array("id"=>$v["goods_id"]))}'>
									删除
								</a> 	
								<?php } ?>
							</td>
						</tr>
						</volist>	
						
						<tr>
							<td colspan="20" class="page">{$page}</td>
						</tr>
				</tbody>
				
			</table>
		</div>
	</div>
</div>
</block>
<block name="javascript">
<script>
function alert_show(msg)
{
	$('#alert_content').html(msg);	
	
	$('#alert_info').show();
	setTimeout("$('#alert_info').hide();",2000);
}
$(function(){
	$('.backhuiche').click(function(){
		var rel_url = $(this).attr('rel');
		
		if(!confirm('确认删除吗？'))
		{
			return false;
		}
		$.ajax({
			url:rel_url,
			type:'get',
			dataType:'json',
			success:function(ret){
				if(ret.code == 1)
				{
					alert('删除成功，您的商品已下架!');
					location.href = location.href;
					return false;
				} else {
					alert(ret.msg);
					return false;
				}
			}
		})
	})
	
	$('.index_sort').blur(function(){
		var gid = $(this).attr('gid');
		var index_sort = $(this).val();
		$.ajax({
			url:"{:U('Goods/toggle_index_sort')}",
			type:'post',
			data:{gid:gid,index_sort:index_sort},
			dataType:'json',
			success:function(res){
				alert_show('修改排序成功')
			}
		})
		console.log($(this).val());
	})
	$('.id-pills-stacked').on('click', function(){
		var gid = $(this).attr('gid');
		$.ajax({
			url:"{:U('Goods/toggle_index_show')}",
			type:'post',
			data:{gid:gid},
			dataType:'json',
			success:function(res){
				//code
			}
		})
	});
	
	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });
	
	$('.copy').click(function(){
		$.ajax({
		url: "{:U('Goods/copy_goods')}",
		type: 'post',
		data: $('input:checked'),
		dataType: 'json',
		beforeSend: function() {
			$('.copy').attr('disabled', true);
			$('.copy').after('<span class="wait">&nbsp;<img src="__IMG__/loading.gif" alt="" /></span>');
		},	
		complete: function() {
			$('.copy').attr('disabled', false); 
			$('.wait').remove();
		},			
		success: function(json) {
			$('.warning, .error').remove();
					
			if (json['redirect']) {				
				
				location = json['redirect']
								
			} 
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert('修改失败');
		}
	});	
	});
});		
</script>
</block>