{include "header.inc.html"}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>商品打折信息</strong><br />
		<span class="english"></span> </span> </div>
	</div>

<div class="tool">
<form action="{$adminUrl}taoke/coupon/list" method="get" class="form">
<label class="label">搜索：</label>分类ID：<input type="text" class="w100" name="cid" value="{$smarty.get.cid}" /> 店铺类型：<select name="shop_type"><option value="all">所有</option><option value="b"{if $smarty.get.shop_type=='b'} selected{/if}>商城</option><option value="c"{if $smarty.get.shop_type=='c'} selected{/if}>集市</option></select><input type="submit" class="btn_sub" value="{$lang.form.search}"> 
</form>
<div class="clr"></div>
</div><!--.tool-->
{if $smarty.get.act=="edit"}
<div class="adminForm">
<form  action="{$adminUrl}taoke/shop" method="post" class="form">
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
<div class="form-line"><label class="label"></label><div class="element"><input type="text" class="text" name="" value="" /></div></div>
</form>
</div>
{else}
 <table class="table-ca table_1" id="tInfo">
 <tr>
<th class="w60">编号</th><th class="">商品名</th><th class="w120">昵称</th><th class="">价格</th><th class="">所在地</th><th class="w40">信用</th><th class="">图片</th><th class="" title="折扣比率">折扣</th><th class="" title="折扣价格">价格</th><th class="" title="折扣活动开始时间">开始时间</th><th class="" title="折扣活动结束时间">结束时间</th><th>佣金</th><th title="累计成交量.注：返回的数据是30天内累计推广量">成交量 </th><th>交易量</th><th>类型</th><th class="w60">操作</th>
 </tr>
 {$lim = $smarty.get.limit|default:20}
 {if $couponList}
{foreach from=$couponList item=item}
<tr>
<td>{$item.num_iid}</td><td><a href="{$item.click_url}" target="_blank">{$item.title}</a></td><td><a href="{$item.shop_click_url}" target="_blank">{$item.nick}</a></td><td>{$item.price}</td><td>{$item.item_location}</td><td>{$item.seller_credit_score}</td><td><a href="{$item.pic_url}_400x400.jpg" target="_blank" class="lightbox" title="{$item.title}" rel="roadtrip">图片</a></td><td>{$item.coupon_rate}</td><td>{$item.coupon_price}</td><td>{$item.coupon_start_time}</td><td>{$item.coupon_end_time}</td><td title="佣金比率：{$commission_rate /100}%">{$item.commission}</td><td>{$item.commission_num}</td><td>{$item.volume}</td><td>{$item.shop_type}</td><td><a href="javascript:void(0)" sid="{$item.num_iid}" title="" class="addGoods">添加</a></td>
</tr>
{/foreach}
{/if}
</table>
<div class="page">
{if $cid = $smarty.get.cid}
{$cid = "&cid=$cid"}
{/if}
{if $shop_type=$smarty.get.shop_type}
{$shop_type= "&shop_type=$shop_type"}
{/if}{$limit = 40}
	<div class="pagin fr">{pager allCount="3960" url="/qkadmin/taoke/coupon/list?$cid$shop_type&page=" number="false"}</div>
</div>
</div><!--.content_box-->
{/if}
<div class="goodsForm none w700">
<form class="form" method="post" id="goodsForm">
	<div class="form-line"><label class="label">商品分类：</label><div class="element"><select name="catId"><option value="0">{$lang.form.selectCat}</option>
	{foreach from=$category item=item}
	<option value="{$item.id}"{if $goodsInfo.catId==$item.id || ($smarty.get.act=="add" and $smarty.session.catId==$item.id)} selected{/if}>{for $foo=1 to $item.grade*4}&nbsp;{/for}{$item.name}</option>
	{/foreach}
	</select>
	</div></div>
<div class="form-line"><label class="label">商品品牌：</label><div class="element"><input type="text" class="text w400" name="brand" value="" /> </div></div>
<div class="form-line"><label class="label">商品IID：</label><div class="element"><input type="text" class="text" name="iid" value="" /> <a href="" target="_blank" id="detail_url">查看</a></div></div>
<div class="form-line"><label class="label">商品名称：</label><div class="element"><input type="text" class="text w400" name="name" value="" /> <a href="" target="_blank" id="click_url">查看</a></div></div>
<div class="form-line"><label class="label">价格：</label><div class="element"><input type="text" class="text" name="price" value="" /></div></div>
<div class="form-line"><label class="label">佣金：</label><div class="element"><input type="text" class="text" name="commission" value="" /></div></div>
<div class="form-line"><label class="label">折扣名称：</label><div class="element"><input type="text" class="text" name="promoteName" value="" /> <a href="javascript:void(0)" id="getCouponName">获取折扣名称</a></div></div>
<div class="form-line"><label class="label">折扣价格：</label><div class="element"><input type="text" class="text" name="promotePrice" value="" /></div></div>
<div class="form-line"><label class="label">开始时间：</label><div class="element"><input type="text" class="text" name="promoteStarttime" value="" /></div></div>
<div class="form-line"><label class="label">结束时间：</label><div class="element"><input type="text" class="text" name="promoteEndtime" value="" /></div></div>
<div class="form-line"><label class="label">商品图片：</label><div class="element"><input type="text" class="text w400" name="pic_url" value="" /></div></div>
<div class="form-line"><label class="label">库存：</label><div class="element"><input type="text" class="text" name="inventory" value="" /></div></div>
<div class="form-line"><label class="label">商品详细：</label><div class="element"><textarea name="content"></textarea></div></div>

</form>
</div>
<script type="text/javascript">
$(function(){
	var sdata = {};
	$("#getCouponName").click(function(){
				$.ajax({
					type:"POST",
					url:"{$adminUrl}taoke/data",
					data:"inajax=1&act=getCoupon&iid="+$("input[name='iid']").val(),
					cache:false,
					dataType:"json",
					success:function(json){
						if(json.success){
							sdata.promoteName = json.data.name;
							$("input[name='promoteName']").val(json.data.name);
						}else{
							alert(json.message);
						}
					}
				});		
	})
	$(".addGoods").click(function(){
		var tr = $(this).parent("td").parent("tr");
		var tds = tr.find('td');
		sdata.iid = tds.eq(0).text();
		sdata.promoteName = '';
		sdata.promotePrice = tds.eq(8).text();
		sdata.commission = tds.eq(11).text();
		sdata.promoteStarttime = tds.eq(9).text();
		sdata.promoteEndtime = tds.eq(10).text();
		sdata.name = tds.eq(1).text();
		sdata.price = tds.eq(3).text();
		sdata.picUrl = tds.eq(6).find("a").attr('href').replace("_400x400.jpg","");
		sdata.link = "http://item.taobao.com/item.htm?id="+sdata.iid;
		sdata.linkPrice = sdata.price;
		sdata.marketPrice = sdata.price;
		sdata.nick = tds.eq(2).text();
		sdata.clickUrl = tds.eq(1).find("a").attr("href");
		sdata.shopClickUrl = tds.eq(2).find("a").attr('href');
		sdata.promotion = 1;

		var form = $("#goodsForm");
		$("#detail_url").attr("href",sdata.link);
		$("#click_url").attr("href",sdata.clickUrl);
		form.find("input[name='iid']").val(sdata.iid);
		form.find("input[name='name']").val(sdata.name);
		form.find("input[name='price']").val(sdata.price);
		form.find("input[name='promotePrice']").val(sdata.promotePrice);
		form.find("input[name='promoteStarttime']").val(sdata.promoteStarttime);
		form.find("input[name='promoteEndtime']").val(sdata.promoteEndtime);
		form.find("input[name='pic_url']").val(sdata.picUrl);
		form.find("input[name='commission']").val(sdata.commission);
		var formDialog = $(".goodsForm").dialog({ title:'添加淘宝客商品到本地',modal:false,width:720,height:450,buttons:{
			"获取信息":function(){
				$.ajax({
					type:"POST",
					url:"{$baseUrl}goods/add",
					data:"inajax=1&act=getinfo&iid="+sdata.iid,
					cache:false,
					dataType:"json",
					success:function(json){
						if(json.success){
							sdata.inventory = json.data.item.num;
							sdata.content = json.data.item.desc;
							$("input[name='inventory']").val(json.data.item.num);
							$("textarea[name='content']").val(json.data.item.desc);
						}else{
							alert(json.message);
						}
					}
				});
			},
			"确认添加":function(e){
				if($("input[name='inventory']").val()==''){ alert("还没有获取库存及详细信息");return false; }
				sdata.act='add';sdata.inajax=1;
				sdata.catId = $("select[name='catId']").val();
				$(e.srcElement).attr("disabled",true);
				$.ajax({
					type:"POST",
					url:"{$adminUrl}goods",
					data:sdata,
					cache:false,
					dataType:"json",
					success:function(json){
						$(e.srcElement).removeAttr("disabled");
						if(json.success){
							Msg('成功');
							$("#goodsForm").find("input").val("");
							$("#goodsForm").find("textarea").val("");
						}else{
							alert(json.message);
						}
					}
				});
			},
			"取消":function(){
				formDialog.dialog("destroy");
			}
		}
		});
	});




	$("#updatecat").button().click(function(){
		var dia = $("<div>是否向淘宝同步所有分类？</div>").css({ fontSize:14 }).dialog({ modal:true,width:300,height:160,resizable:false,title:'确认更新分类',buttons:{
			"确认":function(e){
				dia.html('<img src="{$baseUrl}static/images/loading.gif" width="16px" height="16px" /> 正在同步，请稍候...');
				var btn = $(e.srcElement);
				btn.attr("disabled","disabled");
				$.ajax({
					type:"POST",
					url:"{$adminUrl}taoke/cat",
					data:"inajax=1&act=update",
					dataType:"json",
					success:function(json){
						if(json.success){
							dia.dialog("destroy");
						}else{
							dia.html(json.message);
							btn.removeAttr("disabled");
						}
					}
				});
				
			},
			"取消":function(){
				dia.dialog("destroy");
			}
		}
		});
	});
});
</script>
{include "footer.inc.html"}