<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 method='post' action='{url:/market/ticket_excel}'>
		<table class="table list-table">
			<colgroup>
			    <col width="30px" />
				<col width="120px" />
				<col width="70px" />
				<col width="80px" />
				<col width="90px" />
				<col width="170px"  />
				<col />
				<col width="120px" />
			</colgroup>
			<caption>
                <a class="btn btn-default" href='{url:/market/ticket_edit}'>
                    <i class="fa fa-plus"></i>添加优惠券
                </a>

                <button class="btn btn-default" type="submit">
                    <i class="fa fa-file-excel-o"></i>生成EXCEL
                </button>
			</caption>
			<thead>
				<tr>
				    <th></th>
					<th>名称</th>
					<th>面值</th>
					<th>数量</th>
					<th>兑换积分</th>
					<th>有效期</th>
					<th>限制说明</th>
					<th>操作</th>
				</tr>
			</thead>

			<tbody>
			    {set:$queryObj=Api::run('getListByTicket');$resultData=$queryObj->find()}
                {foreach:items=$resultData}
				{set:$ticket_num = statistics::getTicketCount($item['id'])}
				<tr>
				    <td><input type='checkbox' name='id[]' value='{$item['id']}' /></td>
					<td>{$item['name']}</td>
					<td>{$item['value']} 元</td>
					<td>{$ticket_num} 张</td>
					<td>{echo:($item['point']==0) ? '免费领取':$item['point']}</td>
					<td>{$item['start_time']} ～ {$item['end_time']}</td>
					<td>{echo:ticket::noteFull($item['id'])}</td>
					<td>
						<a href='{url:/market/ticket_edit/id/$item['id']}' title="编辑">
							<i class='operator fa fa-edit'></i>
						</a>

						<a href='{url:/market/ticket_more_list/ticket_id/$item['id']}' title="查看优惠券">
							<i class='operator fa fa-eye'></i>
						</a>

						<a href='javascript:create_dialog("{$item['id']}");' title="生成实体优惠券">
							<i class='operator fa fa-money'></i>
						</a>

						{if:$ticket_num > 0}
						<a href='javascript:void(0)' title="生成EXCEL" onclick="delModel({msg:'是否要生成excel表格？',link:'{url:/market/ticket_excel/id/$item[id]}'});">
							<i class='operator fa fa-file-excel-o'></i>
						</a>
						{/if}

						<a href='javascript:void(0)' onclick="delModel({link:'{url:/market/ticket_del/id/$item['id']}'});">
							<i class='operator fa fa-close'></i>
						</a>
					</td>
				</tr>
				{/foreach}
			</tbody>
		</table>
	</form>
</div>
{$queryObj->getPageBar()}

<script type='text/javascript'>
//创建优惠券
function create_dialog(ticket_id)
{
	art.dialog.prompt('请输入生成线下实体优惠券数量：',function(num)
	{
		var num = parseInt(num);
		if(isNaN(num) || num <= 0)
		{
			alert('请填写正确的数量');
			return false;
		}

		var url = '{url:/market/ticket_create/ticket_id/@ticket_id@/num/@num@}';
		    url = url.replace('@ticket_id@',ticket_id).replace('@num@',num);
		window.location.href = url;
	});
}
</script>
