{js:my97date}

<div class="headbar">
	<div class="position"><span>营销</span><span>></span><span>营销活动管理</span><span>></span><span>{if:isset($this->promotionRow['id'])}编辑{else:}添加{/if}限时抢购</span></div>
</div>
<div class="content_box">
	<div class="content form_content">
		<form action="{url:/market/pro_speed_edit_act}"  method="post" name='pro_edit'>
			<input type='hidden' name='id' />
			<table class="form_table">
				<col width="150px" />
				<col />
				<tr>
					<th>限时抢购名称：</th>
					<td><input type='text' class='normal' name='name' pattern='required' alt='限时抢购名称' /><label>* 限时抢购名称</label></td>
				</tr>
				<tr>
					<th>限时抢购时间：</th>
					<td>
						<input type='text' name='start_time' class='Wdate' pattern='datetime' readonly=true onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" alt='请填写一个日期' /> ～
						<input type='text' name='end_time' class='Wdate' pattern='datetime' readonly=true onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" alt='请填写一个日期' />
						<label>* 此限时抢购时间段</label>
					</td>
				</tr>
				<tr>
					<th>是否开启：</th>
					<td>
						<label class='attr'><input type='radio' name='is_close' value='0' checked=checked />是</label>
						<label class='attr'><input type='radio' name='is_close' value='1' />否</label>
					</td>
				</tr>
				<tr>
					<th>允许参与人群：</th>
					<td>
						<ul class='attr_list clearfix'>
							<li><label class='attr'><input type='checkbox' name='user_group' value='all' onchange='select_all();' />全部</label></li>
							{query:name=user_group}
							<li><label class='attr'><input type='checkbox' name='user_group[]' value='{$item['id']}' />{$item['group_name']}</label></li>
							{/query}
						</ul>
						<label>* 此限时抢购允许参加的用户组</label>
					</td>
				</tr>

				<tr>
					<th>设置抢购商品：</th>
					<td>
						<table class='border_table' style='width:65%'>
							<col width="100px" />
							<col width="200px" />
							<col />
							<input type='hidden' name='condition' />
							<thead>
								<tr>
									<th>图片</th>
									<th>名称</th>
									<th>原价格</th>
									<th>限时抢购价格</th>
								</tr>
							</thead>
							<tbody>
								<tr id='speed_goods' class='td_c'></tr>
								<tr>
									<td colspan='4'>
										<button type='button' onclick="searchGoods('{url:/block/search_goods/type/radio}',searchGoodsCallback);" class='btn'><span>选择商品</span></button>
										<label>* 设置要限时抢购的商品，仅能设置一种商品</label>
									</td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<th>介绍：</th>
					<td><textarea class='textarea' name='intro'>{$this->promotionRow['intro']}</textarea></td>
				</tr>
				<tr><td></td><td><button class="submit" type='submit'><span>确 定</span></button></td></tr>
			</table>
		</form>
	</div>
</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
			}
		};
		relationCallBack(content);
	});
}

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

		var html =   '<td><img src="'+imgUrl+'" title="'+content['data']['name']+'" style="max-width:140px;" /></td>'
					+'<td>'+content['data']['name']+'</td>'
					+'<td>'+content['data']['sell_price']+'</td>'
					+'<td><input text="text" class="small" name="award_value" pattern="float" alt="请填写一个数字" />元 </td>';

		$('#speed_goods').html(html);
	}
}

//选择参与人群
function select_all()
{
	var is_checked = $('[name="user_group"]').prop('checked');
	if(is_checked == true)
	{
		var checkedVal  = true;
		var disabledVal = true;
	}
	else
	{
		var checkedVal  = false;
		var disabledVal = false;
	}

	$('input:checkbox[name="user_group[]"]').each(
		function(i)
		{
			$(this).prop('checked',checkedVal);
			$(this).prop('disabled',disabledVal);
		}
	);
}

jQuery(function()
{
	//预定义商品绑定
	relationCallBack({$this->promotionRow['goodsRow']});

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

	//根据默认值进行用户组选择
	select_all();
	var userGroup = "{echo:trim($this->promotionRow['user_group'],',')}";
	if(userGroup)
	{
		var userGroupArray = userGroup.split(',');
		for(var i in userGroupArray)
		{
			$('[name="user_group[]"][value="'+userGroupArray[i]+'"]').prop('checked',true);
		}
	}
});
</script>