<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <LINK rel="Bookmark" href="/favicon.ico">
    <LINK rel="Shortcut Icon" href="/favicon.ico" />
    <link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/skin/default/skin.css" rel="stylesheet" type="text/css" id="skin" />
    <link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />

    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>返利记录列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    返利记录 <span class="c-gray en">&gt;</span> 收货记录列表 <a
        class="btn btn-success radius r mr-20"
        style="line-height: 1.6em; margin-top: 3px"
        href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="pd-20">
    <form action="${pageContext.request.contextPath }/admin/channel/listChannelRebate" method="post" style="margin-bottom: 20px;text-align: center;">
        <button name=""  class="btn btn-success" type="button" onclick="getChannel();" style="margin-left: -50px;margin-right: 100px;">
            结算
        </button>
        <span class="select-box" style="width: 150px">
					<select id="rebackStatus" name="rebackStatus" class="select">
                        <option value="">收货状态</option>
						<option ${rebackStatus==1?'selected':'' } value="1">待收货</option>
						<option ${rebackStatus==2?'selected':'' } value="2">已收货，待确认</option>
						<option ${rebackStatus==3?'selected':'' } value="3">已收货，已确认</option>
						<option ${rebackStatus==4?'selected':'' } value="4">已取消</option>
					</select>
		</span>
        <input name="salesOrderid" id="salesOrderid" value="${salesOrderid }" placeholder="订单编号" style="width: 150px" class="input-text" type="text">
        创建时间： <input  id="stateDates" value="<fmt:formatDate value="${stateDate}" pattern="yyyy-MM-dd"/>" name="stateDates" class="input-text Wdate" style="width: 120px;" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endDates\')||\'%y-%M-%d\'}'})" readonly>
        - <input  id="endDates" value="<fmt:formatDate value="${endDate}" pattern="yyyy-MM-dd"/>" name="endDates" class="input-text Wdate" style="width: 120px;" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'stateDates\')||\'%y-%M-%d\'}'})" readonly>
        <button name="" id="submitBtn" class="btn btn-success" type="submit">
            <i class="Hui-iconfont"></i> 搜索
        </button>
        <input type="hidden" name="rebackChannelType" value="${rebackChannelType}">
        <input type="hidden" name="rebackChannelId" value="${rebackChannelId}">
    </form>
    <form id="goodsform" >
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="15">收货记录列表</th>
            </tr>
            <tr class="text-c">
                <th width="50"></th>
                <th width="130">订单编号</th>
                <th width="150">订单金额</th>
                <th width="90">支付金额</th>
                <th width="130">交易日期</th>
                <th width="100">产品颜色</th>
                <th width="100">产品数量</th>
                <th width="100">是否自提</th>
                <th width="100">购买人姓名</th>
                <th width="100">购买人电话</th>
                <th width="100">成本统计</th>
                <th width="100">收货状态</th>
                <th width="100">返利日期</th>
                <th width="120">创建日期</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:if test="${! (empty page.dataList) }">
            <c:forEach items="${page.dataList }" var="infolist">
            <tr class="text-c">
                <td>
                    <c:if test="${infolist.rebackStatus == 2 }">
                        <input type="checkbox" name="rebates" value="${infolist.rebateId}">
                    </c:if>
                </td>
                <td>${infolist.salesOrderid }</td>
                <td>${infolist.salesAmount/100 }元</td>
                <td>${infolist.salesYetAmount/100 }元</td>
                <td><fmt:formatDate value="${infolist.salesTransactionDate}" pattern="yyyy-MM-dd"/></td>
                <td>${infolist.colorName}</td>
                <td>${infolist.itemNum}</td>

                <td>
                    <c:if test="${infolist.salesTransportationType == 1 }">邮寄</c:if>
                    <c:if test="${infolist.salesTransportationType == 2 }">自提</c:if>
                </td>
                <td>${infolist.salesAddressName}</td>
                <td>${infolist.salesAddressTel}</td>

                <td>${infolist.rebackAmount/100}元</td>
                <td>${infolist.rebackStatus==1?'待收货':''}${infolist.rebackStatus==2?'已收货，待确认':''}${infolist.rebackStatus==3?'已收货，已确认':''}${infolist.rebackStatus==4?'已取消':''}</td>
                <td><fmt:formatDate value="${infolist.rebackTime}" pattern="yyyy-MM-dd"/></td>
                <td><fmt:formatDate value="${infolist.rebackCreateTime}" pattern="yyyy-MM-dd"/></td>
                <td>
                    <c:if test="${infolist.rebackStatus == 2 }">
                        <a onclick="update_status(${infolist.rebateId})">标记已收货</a>
                    </c:if>
                </td>
                </c:forEach>
                </c:if>
                <c:if test="${empty page.dataList}">
            <tr align="center"><td colspan="15" style="text-align: center;">未查询到该类数据!</td></tr>
            </c:if>
            </tbody>
        </table>
        <div align="right" class="mt-10 mb-10 mr-10">
            <%@include file="/common/other/paper/pager.jsp"%>
        </div>
    </form>
    <input type="hidden" value="${rebackChannelId }" id="channelId">
    <input type="hidden" value="${rebackChannelType }" id="channelType">
    <input type="hidden" value="" id="rebates">
    <div class="layui-layer layui-anim layui-layer-iframe" id="layui-layer4" times="4" showtime="0" contype="string" style="display:none;z-index: 19891018; width: 550px; height: 360px; position: absolute; top: 100px; left: 379px;">
        <div class="layui-layer-title" id="sendOrderNote" style="cursor: move;" move="ok">成本合计</div>
        <br>
        <div class="row cl">
            <label class="form-label col-2">&nbsp;&nbsp;渠道名称：</label>
            <div class="formControls col-3">
                <b><span id="channelName">

					</span></b>
            </div>
        </div>
        <div class="row cl" style="margin-top: 10px;">
            <label class="form-label col-2">&nbsp;&nbsp;成本合计：</label>
            <div class="formControls col-3">
                        <span id="rebackAmount">

                        </span>
            </div>
        </div>
        <br>
        <div class="row cl" style="display: none">
            <div class="formControls col-5">
                <table class="table table-border table-bordered table-bg" style="width: 450px;margin-left: 10px;">
                    <thead>
                    <tr class="text-c">
                        <th width="150" >账户银行</th>
                        <th width="150" >收款账号</th>
                        <th width="150" >开户名称</th>
                        <th width="90">开户支行</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="text-c">
                        <td id="channelBank"></td>
                        <td id="channelBankAccount"></td>
                        <td id="channelBankName"></td>
                        <td id="channelBankBranch"></td>
                    </tbody>
                </table>
            </div>
        </div>
        <br>
        <span style="margin-left: 10px;">请在收货后，点击“确认已收货”按钮，系统将对应的收货记录标记为已收货</span>
        <div class="col-9 col-offset-3" style="margin-top: 10px;">
            <input class="btn btn-danger" type="button" onclick="update_statuss()" value="&nbsp;&nbsp;成本合计&nbsp;&nbsp;">
        </div>
        <span class="layui-layer-setwin">
			<a class="layui-layer-ico layui-layer-close layui-layer-close1" onclick="exitWindowsDiv(this)" href="javascript:;"></a>
		</span>
        <input type="hidden" value="" id="rebackChannelId">
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/tips.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">

    function getChannel(){
        var rebates = "";
        $('input:checkbox[name=rebates]:checked').each(function(i){
            if(0==i){
                rebates = $(this).val();
            }else{
                rebates += (","+$(this).val());
            }
        });
        var channelId = $("#channelId").val();
        var channelType = $("#channelType").val();
        if(rebates == "" || channelId == "" || channelType == ""){
            layer.msg("请至少选中一项收货记录",{icon: 5,time:2000});
            return;
        }
        $.ajax({
            url: '${pageContext.request.contextPath }/admin/channel/settlement',
            type: "POST",
            dataType: "json",
            data: {rebates : rebates,channelId : channelId,channelType : channelType},
            error:function(data){
                layer.msg(data.status,{icon: 5,time:2000});
            },
            success:  function(data){
                if(data.status){
                    $("#layui-layer4").show();
                    if(channelType == 1){
                        $("#channelName").html(data.data.channel.mainChannelName);
                        $("#rebackAmount").html((data.data.channel.rebackAmount/100)+"元");
                        $("#channelBank").html(data.data.channel.mainChannelBank);
                        $("#channelBankAccount").html(data.data.channel.mainChannelBankAccount);
                        $("#channelBankName").html(data.data.channel.mainChannelBankName);
                        $("#channelBankBranch").html(data.data.channel.mainChannelBankBranch);
                    }
                    if(channelType == 2){
                        $("#channelName").html(data.data.channel.childChannelName);
                        $("#rebackAmount").html((data.data.channel.rebackAmount/100)+"元");
                        $("#channelBank").html(data.data.channel.childChannelBank);
                        $("#channelBankAccount").html(data.data.channel.childChannelBankAccount);
                        $("#channelBankName").html(data.data.channel.childChannelBankName);
                        $("#channelBankBranch").html(data.data.channel.childChannelBankBranch);
                    }
                    $("#rebates").val(data.data.rebates);
                }else{
                    layer.msg("操作失败",{icon: 5,time:2000});
                }

            }
        });
    }

    function update_statuss(){
        var rebates = $("#rebates").val();
        $.ajax({
            url: '${pageContext.request.contextPath }/admin/channel/updateRebackStatus',
            type: "POST",
            dataType: "json",
            data: {rebates : rebates},
            error:function(data){
                layer.msg(data.status,{icon: 5,time:2000});
            },
            success:  function(data){
                if(data.status){
                    $("#layui-layer4").hide();
                    layer.msg("状态已修改为已收货，已确认",{icon: 1,time:2000},function () {
                        location.replace(location.href);
                    });

                }else{
                    layer.msg("修改状态失败",{icon: 5,time:2000});
                }

            }
        });
    }
    function update_status(id){
        layer.confirm('确认要修改收货状态吗？',function(index){
                $.ajax({
                    url: '${pageContext.request.contextPath }/admin/channel/updateState',
                    type: "POST",
                    dataType: "json",
                    data: {rebateId : id,rebackStatus : 3},
                    error:function(data){
                        layer.msg(data.status,{icon: 5,time:2000});
                    },
                    success:  function(data){
                        if(data.status){
                            layer.msg("已修改为已收货，已确认",{icon: 1,time:2000},function () {
                                location.replace(location.href);
                            });

                        }else{
                            layer.msg("修改状态失败",{icon: 5,time:2000});
                        }

                    }
                });
            }
        );

    }
    // 关闭窗口
    function exitWindowsDiv(_this) {
        $(_this).parent().parent().hide();
    }
</script>
</body>
</html>