<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li>
			<i class="home-icon fa fa-home"></i>
			<a href="#">营销</a>
		</li>
		<li>
			<a href="#">营销活动管理</a>
		</li>
		<li class="active">编辑拼团</li>
	</ul>
</div>

<div class="content">
	<form action="{url:/market/assemble_update}"  method="post" name='assemble_edit' enctype='multipart/form-data'>
		<input type='hidden' name='id' />
		<table class="table form-table">
			<colgroup>
				<col width="130px" />
				<col />
			</colgroup>

			<tr>
				<th>拼团标题：</th>
				<td><input type='text' class='form-control' name='title' pattern='required' placeholder='请填写拼团标题' /></td>
			</tr>

			<tr>
				<th>是否开启：</th>
				<td>
                    <label class="radio-inline">
                        <input type="radio" name="is_close" value="0" checked=checked >是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="is_close" value="1">否
                    </label>
				</td>
			</tr>
			<tr>
				<th>设置拼团商品：</th>
				<td>
					<table class='table table-bordered'>
						<colgroup>
							<col width="150px" />
							<col />
							<col width="110px" />
							<col width="130px" />
						</colgroup>
						<input type='hidden' name='goods_id' />
						<tbody id='assemble_box'></tbody>
						<tr>
							<td colspan=2>
								<button type='button' class='btn btn-default' onclick='searchGoods({"callback":searchGoodsCallback});'>添加商品</button>
								<p class="help-block">* 添加要拼团的商品</p>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<th>设置成团人数：</th>
				<td>
					<input type='text' class='form-control' name='limit_nums' pattern='^\d{2,}|[2-9]$' placeholder='请填写大于2的正整数值' />
					<p class="help-block">* 多少人可以成团，必须大于2以上的整数</p>
				</td>
			</tr>

			<tr>
				<th>排序：</th>
				<td>
					<input type='text' class='form-control' name='sort' pattern='int' empty />
				</td>
			</tr>

			<tr>
				<th>介绍：</th>
				<td>
					<textarea class="form-control" rows="4" name='intro'></textarea>
				</td>
			</tr>
			<tr><td></td><td><button class='btn btn-primary' type='submit'>确定</button></td></tr>
		</table>
	</form>
</div>

<script type='text/javascript'>
//输入筛选商品的条件
function searchGoodsCallback(goodsList)
{
	goodsList.each(function()
	{
		var temp = $.parseJSON($(this).attr('data'));
		var content = {
			"data":
			{
				"id":temp.goods_id,
				"name":temp.name,
				"img":temp.img,
				"sell_price":temp.sell_price,
				"img":temp.img,
				"store_nums":temp.store_nums
			}
		};
		relationCallBack(content);
	});
}

//关联商品回调处理函数
function relationCallBack(content,assembleImg)
{
	if(content)
	{
		$('[name="goods_id"]').val(content['data']['id']);
		assembleImg = !assembleImg ? content['data']['img'] : assembleImg;
		var imgUrl  = webroot(assembleImg);

		var html = '<tr><td>商品名称：</td><td>'+content['data']['name']+'</td></tr>'
				  +'<tr><td>展示图片：</td><td><img src="'+imgUrl+'" title="'+content['data']['name']+'" style="max-width:140px;" /><br /><input type="file" class="file" name="img" /></td></tr>'
				  +'<tr><td>拼团价格：</td><td><input type="text" class="form-control w-auto" name="assemble_price" pattern="float" placeholder="填写数字" />，目前原价：'+content['data']['sell_price']+'<p class="help-block">* 设置拼团价格</p></td></tr>';
		$('#assemble_box').html(html);
	}
}

//关联商品信息
jQuery(function()
{
	{if:isset($this->assembleRow['goodsRow'])}
	relationCallBack({$this->assembleRow['goodsRow']},"{$this->assembleRow['img']}");
	{/if}

	//表单回填
	var formObj = new Form('assemble_edit');
	formObj.init({echo:JSON::encode($this->assembleRow)});
});
</script>