<{include file="index/header_shop.html"}> 
<div class="tab_name"><span>分销管理</span></div>
<style type="text/css">
table{ } 
table tr th{ font-size:12px; padding:8px 0 6px; } 
table tbody tr th{ color:#000000; }
table tbody tr td{ text-align:center; color:#333; padding:0 0 8px 0;} 
a.simg{ width:60px; height:60px; line-height:60px; border:1px solid #efefef; padding:1px; float:left;}
a.simg img{ max-height:60px; max-width:60px; }
.ttl{ width:100%; padding:12px 0 0 5px; float:left;}
.ttl a{ text-align:left; font-size:12px; color:#333; padding:0 10px 0 10px; line-height:22px; float:left;  }
.ttl span{font-size:12px;line-height:22px; padding:0 10px 0 20px; color:#999999; text-align:left; float: left;} 

.intro{ width:440px; text-align:left; line-height:18px; padding:6px 0 0 15px; color:#999999; float:left;}
input.bfb{ padding:4px; text-align:center; }
input.submit2{ background:#00AB00; color:#fff; padding:5px 15px; float:left; }

.comm_box{ width:100%; float:left;  }
.comm_box span{ width:65px; margin-left:10px; float:left; }
.comm_box span i{ width:50px; padding:3px; border:1px solid #efefef; background:#f2f2f2; text-align:center; float:left; }
.comm_box span input{ width:50px; padding:3px; text-align:center; float:left; }
.comm_box a{ background:#D4D5D7; color:#333; padding:4px 5px 4px;border-radius:2px; float:left; } 
</style> 
<div class="actbtn">
	<a href="?m=distribute&a=add" class="add">添加分销</a>
</div>
<div class="lbox">
	<table class="ltable">
		<thead>
			<tr> 
				<th width="30">&nbsp;</th>
				<th>商品名</th> 
				<th width="100">推广数</th>
				<th width="100">佣金支出</th>
				<th width="120">佣金设置（百分比）</th> 
				<th width="100">取消分销</th> 
			</tr>
		</thead> 
		<tbody>  
	<{if $data.list}>	
		<{foreach item=i from=$data.list}>		 
			<tr style="border-bottom:1px solid #efefef; border-top:none;"> 
				<td style="padding:15px 0 15px 10px;"> 
					 <a class="simg" href="index.php?m=goods&a=detail&id=<{$i.id}>"><img src="<{$__IMG__}><{$i.images|img_size:60x60}>"/></a>
				</td>
				<td valign="top">
					<div class="ttl"><a href="index.php?m=goods&a=detail&id=<{$i.id}>" target="_blank"><{$i.title}></a></div> 
					<div class="intro">
						价格：<{if $i.discount_price == ''}> <{$i.price}><{else}> <{$i.discount_price}></s><{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						库存：<{if $i.stock == '0'}>无货<{else}><{$i.stock}><{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						状态：<{if $i.sell_status == '1'}>上架<{else}>下架<{/if}>
					</div>
				</td>  
				<td><{$i.total_num}></td>
				<td><{$i.total_fee}></td>
				<td>
					<div class="comm_box comm_box_<{$i.id}>" data-id="<{$i.id}>">
						<span><i><{$i.commission_rate}></i></span><a href="javascript:;" class="comm_edit" data-id="<{$i.id}>" data-act="1">编辑</a>
					</div>
				</td> 
				<td><a href="javascript:;" class="edit cancel_distribute" data-id="<{$i.id}>">取消分销</a></td>
			</tr>
		<{/foreach}> 
	<{else}> 
		<tr><td colspan="7" class="btm"><div class="nomsg"><i></i><span>暂无分销产品~</span></div></td></tr>
	<{/if}>	
	</table>
	<{if $data.page}><div class="page"><{$data.page}></div><{/if}>
</div>
<{include file="index/footer.html"}>
<script type="text/javascript">
$(function(){ 
	$(document).on('click',".comm_edit",function(){
		$this = $(this);
		var id = $this.attr('data-id');
		act_status = $this.attr('data-act'); 
		if(act_status == '1'){
			$this.html('保存').attr('data-act','0');
			rate_value = $(".comm_box_"+id+" span i").html(); 
			$(".comm_box_"+id+" span").html('<input type="text" class="comm_value" value="'+rate_value+'" min="0.01" max="100"/>'); 
		}else{
			rate_value = $(".comm_box_"+id+" span input").val(); 
			if(rate_value >=0.01 && rate_value <= 100){
				$.post('?m=distribute&a=commission_rate_save',{gid:id,rate_value:rate_value},function(data){ 
					if(data == '1'){
						$this.html('编辑').attr('data-act','1');
						$(".comm_box_"+id+" span").html('<i>'+rate_value+'</i>'); 			
					}else{
						alert('设置失败');
					}
				});
			}else{
				alert('佣金设置为0.01至100');
			} 
		}
	});
	// 取消分销
	$(".cancel_distribute").click(function(){
		var $this = $(this);
		var goods_id = $this.attr('data-id'); 
		$.post('?m=distribute&a=add_distribute',{gid:goods_id},function(result){ 
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				location.reload();
			}else{
				$.alert(data.msg);
			}
		}); 
	}); 
	
});
</script>