<%@ 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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!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" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <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>
<!-- 后台备注 -->
<div class="layui-layer layui-anim layui-layer-iframe" id="layui-address" times="4" showtime="0" contype="string" style="display:none;z-index: 19891018; width: 400px; height: 260px; position: absolute; top: 100px; left: 379px;">
    <form action="" method="post" class="form form-horizontal" id="form-admin-remark">
        <div class="layui-layer-title" id="sendOrderNote" style="cursor: move;" move="ok">订单备注</div>
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>&nbsp;&nbsp;物流公司：</label>
            <div class="formControls col-5">
                <span id="postFirm" name="postFirm"></span>
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>&nbsp;&nbsp;物流单号：</label>
            <div class="formControls col-5">
                <span id="postNum" name="postNum"></span>
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>&nbsp;&nbsp;收货地址：</label>
            <div class="formControls col-5">
                <span id="addressInfo" name="addressInfo"></span>
            </div>
            <div class="col-4"> </div>
        </div>
        <br/>
        <div class="col-9 col-offset-3">
            <input class="btn btn-primary radius" type="button" onclick="close_address()" value="&nbsp;&nbsp;关闭&nbsp;&nbsp;">
        </div>
    </form>
    <span class="layui-layer-setwin">
			<a class="layui-layer-ico layui-layer-close layui-layer-close1" onclick="close_address()" href="javascript:;"></a>
		</span>
</div>
<!-- 同步订单状态 -->
<div class="layui-layer layui-anim layui-layer-iframe" id="layui-SynOrder" times="4" showtime="0" contype="string" style="display:none;z-index: 19891018; width: 400px; height: 260px; position: absolute; top: 100px; left: 379px;">
    <form action="" method="post" class="form form-horizontal" id="form-admin-SynOrder">
        <div class="layui-layer-title" id="synOrder" style="cursor: move;" move="ok">同步订单状态</div>
        <br>
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>&nbsp;订单编号：</label>
            <div class="formControls col-5">
                <input type="hidden" id="url">
                <input type="text" id="efastOrderId" class="input-text" value="" placeholder="请输入百胜订单号" name="postNum" datatype="*2-20" nullmsg="订单编号不能为空">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <div class="formControls col-8">&nbsp;&nbsp;&nbsp;<span class="c-red" id="msge"></span></div>
        </div>
        <br>
        <div class="col-9 col-offset-3">
            <input class="btn btn-primary radius" onclick="return submitSynOrder()" type="button" value="&nbsp;&nbsp;同步&nbsp;&nbsp;">
        </div>
    </form>
    <span class="layui-layer-setwin">
				<a class="layui-layer-ico layui-layer-close layui-layer-close1" onclick="close_synOrder()" href="javascript:;"></a>
		</span>
</div>
<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">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <form action="${pageContext.request.contextPath }/admin/agentTooth/select_agent_order_list" method="post" id="searchForm">
            <div class="text-c">
                <select name="agentStatus" style="height: 30px;">
                    <option value="">订单状态</option>
                    <option <c:if test="${agentStatus == 0}">selected = "selected"</c:if> value="0">取消订单</option>
                    <option <c:if test="${agentStatus == 1}">selected = "selected"</c:if> value="1">待支付</option>
                    <option <c:if test="${agentStatus == 2}">selected = "selected"</c:if> value="2">已支付、待发货</option>
                    <option <c:if test="${agentStatus == 5}">selected = "selected"</c:if> value="5">已发货</option>
                </select>
                <input type="text" class="input-text" style="width:130px" placeholder="请输入代理商姓名" value="${agentName}" name="agentName">
                <input type="text" class="input-text" style="width:130px" placeholder="请输入代理商电话" value="${agentTel}" name="agentTel">
                <input type="text" class="input-text" style="width:130px" placeholder="请输入收货人名称" value="${agentAddressName}" name="agentAddressName">
                <input type="text" class="input-text" style="width:130px" placeholder="请输入收货人电话" value="${agentAddressTel}" name="agentAddressTel">
                <input type="text" placeholder="开始日期" readonly="readonly" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')||\'2020-10-01\'}'})" id="beginDate" value="${beginDate }" name="beginDate" class="input-text Wdate" style="width: 120px;">
                - <input type="text" placeholder="结束日期" readonly="readonly" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'beginDate\')}',maxDate:'2020-10-01'})" id="endDate" value="${endDate }" name="endDate" class="input-text Wdate" style="width: 120px;">
                <button type="submit" class="btn btn-success radius" id="searchButton" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
            </div>
        </form>
    </div>
    <form id="configform" >
        <table class="table table-border table-bordered table-bg" id="example">
            <thead>
            <tr>
                <th scope="col" colspan="11">代理商采购订单列表</th>
            </tr>
            <tr class="text-c">
                <th width="100">订单状态</th>
                <th width="100">代理商姓名</th>
                <th width="100">代理商电话</th>
                <th width="100">收货人姓名</th>
                <th width="100">收货人电话</th>
                <th width="90">订单金额(元)</th>
                <th width="90">支付金额(元)</th>
                <th width="130">采购数量</th>
                <th width="130">采购日期</th>
                <th width="130">订单备注</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:if test="${! (empty agentOrderList) }">
            <c:forEach items="${agentOrderList }" var="order">
            <tr class="text-c">
                <input type="hidden" value="${order.agentOrderid }" id="agentOrderid" name="agentOrderid">
                <td>
                    <c:if test="${order.agentStatus == 0}">
                        取消订单
                    </c:if>
                    <c:if test="${order.agentStatus == 1}">
                        待支付
                    </c:if>
                    <c:if test="${order.agentStatus == 2}">
                        已支付、待发货
                    </c:if>
                    <c:if test="${order.agentStatus == 5}">
                        已发货
                    </c:if>
                </td>
                <td>${order.agentName }</td>
                <td>${fn:substring(order.agentTel,0,3)}****${fn:substring(order.agentTel,7,11)}</td>
                <td>${order.agentAddressName }</td>
                <td>${fn:substring(order.agentAddressTel,0,3)}****${fn:substring(order.agentAddressTel,7,11)}</td>
                <td>${order.agentAmount==null?"":order.agentAmount/100 }</td>
                <td>${order.agentYetAmount==null?"":order.agentYetAmount/100 }</td>
                <td>
                    <c:if test="${! (empty order.itemList) }">
                        <c:forEach items="${order.itemList }" var="item">
                            ${item.itemProductName}(${item.itemColorName})*${item.itemNum},
                        </c:forEach>
                    </c:if>
                </td>
                <td><fmt:formatDate value="${order.agentCreateDate }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>${order.agentAdminRemark }</td>
                <td class="td-manage">
                    <a onclick="show_address('${order.agentAddressInfo }','${order.agentPostNum }','${order.agentPostFirm }')"
                       title="查看收货地址" href="javascript:;"  class="ml-5" style="text-decoration:none">查看收货地址</a>
                    <a onclick="getEfastStatus('${order.agentOrderid}')"
                       title="同步物流信息" href="javascript:;"  class="ml-5" style="text-decoration:none">同步物流信息</a>
                </td>
                </c:forEach>
                </c:if>
            </tbody>
        </table>
        <div align="right" class="mt-10 mb-10 mr-10">
            <%@include file="/common/other/paper/pager.jsp"%>
        </div>
    </form>
</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" src="${pageContext.request.contextPath }/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/js/page/jqPaginator.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/goods/js/utils.js"></script>
<script type="text/javascript">
    function updateGiftState(_this,id){
        var obj = $(_this);
        layer.confirm('确认要修改状态吗？',function(index){
                $.ajax({
                    url: '${pageContext.request.contextPath }/admin/agentTooth/update_agent_config_status',
                    type: "POST",
                    dataType: "json",
                    data: {configId : id,configStatus : obj.val()},
                    error:function(data){
                        layer.msg("修改失败</br>",{icon: 5,time:2000});
                    },
                    success:  function(data){
                        if (data.status) {
                            layer.msg("修改成功</br>",{icon: 1,time:2000});
                            var message = '';
                            switch (obj.val()) {
                                case "1":
                                    message = '启用';
                                    break;
                                case "2":
                                    message = '停用';
                                    break;
                            }
                            $('#config_status').html(message);
                        } else {
                            layer.msg("修改失败</br>",{icon: 5,time:2000});
                        }
                    }
                });
            }, function () {
                window.location.reload(location.href);
            }
        );

    }
    /**
     * 打开修改商品界面
     */
    function config_edit(url){
        window.location.href = url;
    }

    //显示物流信息
    function show_address(addressInfo,postNum,postFirm) {
        var txtPostFirm = '';
        if (addressInfo == null || addressInfo == '') {
            $('#addressInfo').html('暂无');
        } else {
            $('#addressInfo').html(addressInfo);
        }
        if (postNum == null || postNum == '') {
            $('#postNum').html('暂无');
        } else {
            $('#postNum').html(postNum);
        }
        if (postFirm == null || postFirm == '') {
            $('#postFirm').html('暂无');
        } else {
            switch (postFirm) {
                case "sto":txtPostFirm = '申通快递';break;
                case "yto":txtPostFirm = '圆通快递';break;
                case "sf":txtPostFirm = '顺丰快递';break;
                case "ems":txtPostFirm = '邮政EMS';break;
                case "zto":txtPostFirm = '中通快递';break;
                case "zjs":txtPostFirm = '宅急送';break;
                case "yunda":txtPostFirm = '韵达快递';break;
                case "cces":txtPostFirm = 'cces快递';break;
                case "pick":txtPostFirm = '上门提货';break;
                case "htky":txtPostFirm = '汇通快递';break;
                case "ttkdex":txtPostFirm = '天天快递';break;
                case "stars":txtPostFirm = '星晨急便';break;
                case "jd":txtPostFirm = '京东快递';break;
                case "01":txtPostFirm = '其他';break;
                case "02":txtPostFirm = '上门送货';break;
                default:txtPostFirm = '圆通快递';break;
            }
            $('#postFirm').html(txtPostFirm);
        }
        $('#layui-address').show();
    }

    //隐藏物流信息
    function close_address() {
        $('#layui-address').hide();
    }

    //显示同步订单弹出框
    function getEfastStatus(orderId){
        $('#url').val('${pageContext.request.contextPath }/admin/agentTooth/sync_efast_order/' + orderId);
        $('#layui-SynOrder').show();
    }

    /**
     * 同步订单状态
     */
    function submitSynOrder(){
        var url = $('#url').val();
        var efastOrderId = $("#efastOrderId").val();
        if(efastOrderId == null || efastOrderId == ""){
            $("#msge").html("请输入百胜订单号！");
            return false;
        }
        $.ajax({
            type:'POST',
            url: url,
            data:{
                efastOrderId : efastOrderId
            },
            dataType: 'json',
            success:function(res) {
                debugger;
                if(res.resultCode == 200){
                    $("#msge").html("同步成功");
                    location.reload();
                }else{
                    $("#msge").html(res.message);
                }
                return false;
            }
        });
    }

    function close_synOrder() {
        $('#layui-SynOrder').hide();
    }
</script>
</body>
</html>