<extend name="Public:base" />

<block name="content">	
<div class="row">
	<div class="col-xs-12">
		<div class="alert alert-info">
			<i class="icon-hand-right"></i> 
				请从<a href="{:U('Member/index', array('order_status_id' => 1))}">《前台用户》</a>中导出指定会员的excel后，进行上传发送指定优惠券,<font color="red"></font>
			
										<button class="close" data-dismiss="alert">
				<i class="icon-remove"></i>
			</button>
		</div>
		
		<div class="table-responsive">
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>											
						<th>编号</th>
						<th>优惠券名称</th> 
						<th>优惠券金额</th>  
						<th>订单满多少可用</th>
						<th>总生成张数</th>
						<th>已发送张数</th>
						<th>状态</th> 
						<th>使用时间</th>
					</tr>
				</thead>
				<tbody>
						<tr>
							<td>{$data.id}</td>
							<td>{$data.voucher_title}</td>
							<td>{$data.credit}</td>
							<td>{$data.limit_money}</td>
							<td>{$data.total_count}</td>
							<td>{$data.send_count}</td>
							<td>
							<?php 
								if($data['total_count'] > $data['send_count']){
									echo '<span class="green bold">剩余'.($data['total_count'] - $data['send_count']).'张</font>';
								}else {
									echo '<span class="red bold">已发完</font>';
								}
							?>
							</td>
							
							<td>
								开始时间：<?php echo date('Y-m-d H:i:s',$data['begin_time']); ?>
								<br/>
								结束时间：<?php echo date('Y-m-d H:i:s', $data['end_time']); ?>
							</td>
						</tr>
					</tbody>
				</table>
		</div>	
		<div id="thumb">
			
        		<a href="#" data-toggle="image" class="img-thumbnail">
                 	<img osctype="image" data-placeholder="__ROOT__/Common/image/no_image_100x100.jpg"  src="__ROOT__/Common/image/no_image_100x100.jpg"  />
					</a>
                 <input osctype="image_input" type="hidden" name="image" value="" id="input-image" />
        	
		</div>
		<div id="dropzone">
			
		</div>
		
	</div>
</div>

</block>
<block name="javascript">
<script src="__PUBLIC__/ztree/jquery.ztree.all-3.5.min.js"></script>
<script src="__PUBLIC__/fileupload/jquery.ui.widget.js"></script>
<script src="__PUBLIC__/fileupload/jquery.fileupload.js"></script>
<script>
$(function(){
	
	<present name="Think.get.id">
			Oscshop.setValue("status", {$blog.status|default=1});		
			Oscshop.setValue("allow_reply", {$blog.allow_reply|default=1});		
	</present>
	
	
	// tooltips on hover button-upload
	$('[data-toggle=\'tooltip\']').tooltip({container: 'body', html: true});

	// Makes tooltips work on ajax generated content
	$(document).ajaxStop(function() {
		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
	});	
	
	
	
	$(document).delegate('a[data-toggle=\'image\']', 'click', function(e) {
		e.preventDefault();
		
		var index=$(this).attr('num');
				
		var element = this;
		
		if(index==undefined){
			$(element).popover({
				html: true,
				placement: 'right',
				trigger: 'manual',
				content: function() {
					return '<button type="button" id="thumb-image"  class="btn btn-primary"><i class="icon-edit"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="icon-trash"></i></button>';
				}
			});
		}else{
			$(element).popover({
				html: true,
				placement: 'right',
				trigger: 'manual',
				content: function() {
					return '<button type="button" n="'+index+'"  class="btn btn-primary button-image"><i class="icon-edit"></i></button> <button type="button" id="button-clear" class="btn btn-danger"><i class="icon-trash"></i></button>';
				}
			});
		}
		

		
		$(element).popover('toggle');	
		
		//博客图片
		$('#thumb-image').on('click', function() {		
			
			$('#modal-image').remove();
			
			$('#form-upload').remove();
			
			$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_image" type="file" name="file" /></form>');
	
			$('#form-upload input[name=\'file\']').trigger('click');
			
			$(element).popover('hide');
			
			$('[osctype="btn_upload_image"]').fileupload({
				
	        	dataType: 'json',
	            url: "{:U('Voucher/sendvoucher_tomember_excel_done',array('dir'=>'category','voucher_id' => $id))}",
	            add: function(e, data) {
	                $parent = $('#thumb');
	                $input = $parent.find('[osctype="image_input"]');
	                $img = $parent.find('[osctype="image"]');
	                data.formData = {old_blog_images:$input.val()};
	                $img.attr('src', "__IMG__/loading.gif");
	                data.submit();
	            },
	            done: function (e,data) {
					
	            	alert('批量送券成功');
	            	location.href =location.href;
	            	return false;
	            }
   		 });
		});

		
	
		$('#button-clear').on('click', function() {
			$(element).find('img').attr('src', $(element).find('img').attr('data-placeholder'));
			
			$(element).parent().find('input').attr('value', '');
	
			$(element).popover('hide');
		});
	});
});
</script>
</block>