<article class="col-lg-12">
	<div class="card forms">
		<div class="card-header d-flex align-items-center justify-content-between">
			<h3>共享商品列表</h3>
			<div>
				<input type="button" class="btn btn-primary" onclick="filterResult();" value="检索" />
				<input type="button" class="btn btn-primary" onclick="selectAll('id[]')" value="全选" />
				<input type="button" class="btn btn-primary" onclick="copyGoods();" value="复制商品" title="复制后可以销售此商品" />
			</div>
		</div>

		<div class="card-body">
			<form action="{url:/seller/goods_copy}" method="post" class="form-horizontal">
				<table class="table">
					<colgroup>
						<col width="40px" />
						<col />
						<col width="250px" />
						<col width="90px" />
						<col width="90px" />
						<col width="70px" />
					</colgroup>

					<thead>
						<tr>
							<th></th>
							<th>商品名字</th>
							<th>分类</th>
							<th>销售价</th>
							<th>库存</th>
							<th>操作</th>
						</tr>
					</thead>

					<tbody>
						{foreach:items=$this->query->find()}
						<tr>
							<td><input name="id[]" class="checkbox-template" type="checkbox" value="{$item['id']}" /></td>
							<td><img src='{url:/pic/thumb/img/$item['img']/w/70/h/70}' class="ico" /><a href="javascript:jumpUrl('{$item['is_del']}','{url:/site/products/id/$item[id]}')" title="{$item['name']}">{$item['name']}</a></td>
							<td>
								{set:$catName = array()}
								{foreach:items=Api::run('getCategoryExtendNameByCategoryid',array('id'=>$item["id"]))
								item=$catData}
								{set:$catName[] = $catData['name']}
								{/foreach}
								{echo:join(',',$catName)}
							</td>
							<td>{$item['sell_price']}</td>
							<td>{$item['store_nums']}</td>
							<td>
								<a href="javascript:copyGoods({$item['id']});"><i class="fa fa-lg fa-copy" title="复制商品"></i></a>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
			</form>
			{$this->query->getPageBar()}
		</div>
	</div>
</article>

<script type="text/html" id="filterTemplate">
<form action="{url:/}" method="get" name="filterForm" class="form-horizontal">
	<input type='hidden' name='controller' value='seller' />
	<input type='hidden' name='action' value='share_list' />

	<div class="form-group">
		<label>商品名称</label>
		<input name="search[go.name=]" class="form-control" value="" type="text" />
	</div>

	<div class="form-group">
		<label>商品货号</label>
		<input name="search[go.goods_no=]" class="form-control" value="" type="text" />
	</div>

	<div class="form-group">
		<label>商品分类</label>
    	<span id="__categoryBox" style="margin-bottom:8px"></span>
    	<input type="button" class="btn btn-sm btn-primary" name="_goodsCategoryButton" value="设置分类" />
	</div>
</form>
</script>
{set:plugin::trigger('goodsCategoryWidget',array("name" => "search[ce.category_id=]"))}

<script type="text/javascript">
//检索商品
function filterResult()
{
	var goodsHeadHtml = template.render('filterTemplate');
	art.dialog(
	{
		"init":function()
		{
			var filterPost = {echo:JSON::encode(IReq::get('search'))};
			var formObj = new Form('filterForm');
			for(var index in filterPost)
			{
				formObj.setValue("search["+index+"]",filterPost[index]);
			}
		},
		"title":"检索条件",
		"content":goodsHeadHtml,
		"okVal":"立即检索",
		"ok":function(iframeWin, topWin)
		{
			iframeWin.document.forms[0].submit();
		}
	});
}

//商品详情的跳转连接
function copyGoods(idVal)
{
	if(!idVal)
	{
		var idString = [];
		$('input:checkbox[name="id[]"]:checked').each(function(i)
		{
			idString.push(this.value);
		});
		idVal = idString.join(',');
	}

	if(idVal)
	{
		$.get("{url:/seller/goods_copy}",{"id":idVal},function(content)
		{
			if(content == 'success')
			{
				window.location.href = "{url:/seller/goods_list}";
			}
			else
			{
				alert(content);
			}
		});
	}
	else
	{
		alert("请选择您要操作的商品");
	}
}

//商品详情的跳转连接
function jumpUrl(is_del,url)
{
	is_del == 0 ? window.open(url) : alert("该商品没有上架无法查看");
}
</script>