{extend name="base"}

{block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="card-box">
			<div class="row">
				<div class="col-sm-12">
					<form class="form-inline" role="form" action="" method="get">
	                    <div class="form-group">
							<select name="paytype" class="form-control">
								<option value="" {if $Think.get.paytype==''}selected{/if}>全部方式</option>
								{foreach $pay_product as $k => $v}
								<option value="{$k}" {if $Think.get.paytype==$k}selected{/if}>{$v}</option>
								{/foreach}
							</select>
	                    </div>
						<div class="form-group">
							<select name="goods_id" class="form-control">
								<option value="" {if $Think.get.goods_id==''}selected{/if}>全部商品</option>
								{foreach $goods as $v}
								<option value="{$v.id}" {if $Think.get.goods_id==$v.id}selected{/if}>{$v.name}</option>
								{/foreach}
							</select>
						</div>
						<div class="form-group">
							<input class="form-control"  style="width:200px;" type="text" name="trade_no" value="{$Think.get.trade_no}" placeholder="请输入订单编号">
						</div>
						<div class="form-group">
							<input class="form-control input-daterange-datepicker"  style="width:200px;" type="text" name="date_range" value="{:urldecode($Think.get.date_range)}" placeholder="点击选择查询日期">
						</div>
						<button type="submit" class="btn btn-purple waves-effect waves-light"><i class="fa fa-search"></i> 搜索</button>
	                </form>
				</div>
				<div class="col-sm-12" style="margin-top: 10px;">
					<form class="form-inline">
						<div class="form-group">
							<input class="form-control"  style="" type="text" name="" readonly="readonly" value="总收入：{$total_price}" placeholder="总收入：0.00">
						</div>
						<div class="form-group">
							<input class="form-control"  style="" type="text" name="" readonly="readonly" value="总成本：{$total_cost_price}" placeholder="总成本：0.00">
						</div>
						<div class="form-group">
							<input class="form-control"  style="" type="text" name="" readonly="readonly" value="总利润：{$total_profit}" placeholder="总利润：0.00">
						</div>
					</form>
				</div>
			</div>
			<!-- end row -->
			<div class="row">
				<table class="table table-striped m-0">
					<thead>
						<tr>
							<th>订单号</th>
							<th>商品名称</th>
							<th>支付方式</th>
							<th>总价</th>
							<th>购买者信息</th>
							<th>状态</th>
							<th>取卡状态</th>
							<th>交易时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{foreach $orders as $v}
						<tr>
							<td><a href="/orderquery?orderid={$v.trade_no}" target="_blank">{$v.trade_no}</a></td>
							<td>
								{$v.goods_name}
								{eq name="v.status" value="1"}
								<a class="fetch" href="/merchant/order/fetchcard?id={$v.id}">（{$v.quantity}张）</a>
								{else}
								（{$v.quantity}张）
								{/eq}
								{if $v.coupon_type==1}
								<span class="label label-pink">券</span>
								{/if}
								{if $v.take_card_type==1}
								{eq name="v.status" value="1"}
								<a href="/merchant/order/fetchcard?id={$v.id}"><span class="label label-primary">取</span></a>
								{else}
								<span class="label label-primary">取</span>
								{/eq}
								{/if}
							</td>
							<td>{:get_paytype_name($v.paytype)}</td>
							<td>{$v.total_product_price}</td>
							<td>{$v.contact}</td>
							<td>
								{switch name="v.status"}
								{case value="1"}已付款{/case}
								{case value="0"}未付款{/case}
								{/switch}
							</td>
							<td>
								{if $v.cards_count>0}
									{if $v.cards_count>=$v.quantity}
									已取
									{else/}
									已取部分
									{/if}
								{else/}
								未取
								{/if}
							</td>
							<td>{$v.create_at|date="Y-m-d H:i:s",###}</td>
							<td>
                                <!-- <a href="javascript:void(0);" onclick="del(this,{$v.id})">删除</a> -->
								<!-- <span> | </span> -->
								{if $v.status==1 && $v.cards_count==0}
								<a class="fetch" href="/merchant/order/fetchcard?id={$v.id}">提卡</a>
                                <a href="/merchant/order/dumpCards?trade_no={$v.trade_no}" target="_blank">导出</a>
								{/if}
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
			</div>
			<!-- end row -->
		</div>
		{$page}
	</div>
</div>
{/block}

{block name="appendJS"}

<script>

	function change_status(obj,id)
	{
		var status=$(obj).prop('checked');
		if(status){
			status=1;
		}else{
			status=0;
		}
		$.post('/merchant/order/changeStatus',{
			id:id,
			status:status
		},function(res){
			if(res.code!=0){
				alert(res.msg);
			}
		});
	}

	function del(obj,id)
	{
		swal({
			title: "确定删除吗？",
			text: "你将无法恢复该操作！",
			type: "warning",
			showCancelButton: true,
			confirmButtonColor: "#DD6B55",
			confirmButtonText: "确定删除！",
			closeOnConfirm: false
		},
		function(){
			$.post('/merchant/order/fetch',{
				id:id
			},function(res){
				if(res.code!=0){
					swal('删除失败', res.msg, "error");
				}else{
					swal(res.msg, '', "success");
				}
			});
		});
	}
</script>

{/block}
