<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>html {
        background-color: #fff;
        padding-bottom: 50px;
    }
    td, th {
        text-align: center !important;
    }</style>
</head>

<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">订单信息</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <div class="layui-col-xs12 mt-10 pr-30">
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">订单状态：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="mergeStatus" readonly autocomplete="off"
                                               class="layui-input layui-bg-gray" value="">
                                    </div>
                                </div>
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">下单时间：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="createTime" readonly autocomplete="off" placeholder="请输入"
                                               class="layui-input layui-bg-gray" value="<fmt:formatDate value="${applyOrder.columns.create_time}" pattern="yyyy-MM-dd HH:mm"/>">
                                    </div>
                                </div>
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">产品编号：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="projectCode" readonly autocomplete="off"
                                               class="layui-input layui-bg-gray" value="${applyOrder.columns.project_code}">
                                    </div>
                                </div>
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">入库仓库：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="inWarehouseName" readonly autocomplete="off" placeholder="请输入"
                                               class="layui-input layui-bg-gray" value="${applyOrder.columns.inWarehouseName}">
                                    </div>
                                </div>
                                <c:if test="${user.userType ne '1' && user.userType ne '4'}">
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label w-130">下单人：</label>
                                        <div class="layui-input-block ">
                                            <input type="text" disabled name="creator" readonly autocomplete="off"
                                                   placeholder="请输入"
                                                   class="layui-input layui-bg-gray"
                                                   value="${applyOrder.columns.creator}">
                                        </div>
                                    </div>
                                </c:if>
                                <c:if test="${user.userType eq '1' || user.userType eq '4'}">
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label w-130">下单人：</label>
                                        <div class="layui-input-block ">
                                            <input type="text" disabled name="creator" readonly autocomplete="off" placeholder="请输入"
                                                   class="layui-input layui-bg-gray" value="${applyOrder.columns.traderName}">
                                        </div>
                                    </div>
                                </c:if>
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">接货人：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="personInCharge" readonly autocomplete="off"
                                               class="layui-input layui-bg-gray" value="${applyOrder.columns.person_in_charge}">
                                    </div>
                                </div>
                                <div class="layui-col-xs3">
                                    <label class="layui-form-label w-130">联系方式：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="mobile" readonly autocomplete="off"
                                               class="layui-input layui-bg-gray" value="${applyOrder.columns.mobile}">
                                    </div>
                                </div>
                                <div class="layui-col-xs12">
                                    <label class="layui-form-label w-130">收货地址：</label>
                                    <div class="layui-input-block ">
                                        <c:if test="${empty applyOrder.columns.province }">
                                            <input type="text" disabled name="mobile" readonly autocomplete="off"
                                                   class="layui-input layui-bg-gray" value="${applyOrder.columns.w_address}">
                                        </c:if>
                                        <c:if test="${not empty applyOrder.columns.province }">
                                            <input type="text" disabled name="mobile" readonly autocomplete="off"
                                                   class="layui-input layui-bg-gray" value="${applyOrder.columns.province}${applyOrder.columns.city }${applyOrder.columns.area}${applyOrder.columns.address}">
                                        </c:if>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs12 mb-10 pr-30">
                                <div class="layui-form-item">
                                    <label class="layui-form-label w-130">订单备注：</label>
                                    <div class="layui-input-block ">
                                        <textarea readonly class="layui-textarea layui-bg-gray">${applyOrder.columns.remark}</textarea>
                                    </div>
                                </div>
                            </div>

                            <c:if test="${not empty deliverOrder}">
                                <div class="layui-col-xs12">
                                    <div class="layui-col-xs4 layui-form-item">
                                        <label class="layui-form-label w-130">匹配时间：</label>
                                        <div class="layui-input-block ">
                                            <input type="text" disabled name="placeTime" readonly autocomplete="off"
                                                   placeholder=""
                                                   class="layui-input layui-bg-gray"
                                                   value='<fmt:formatDate value="${deliverOrder.columns.place_time}" pattern="yyyy-MM-dd HH:mm"/>'>
                                        </div>
                                    </div>
                                </div>
                                <c:if test="${not empty deliverOrder.columns.remarks}">
                                    <div class="layui-inline layui-col-xs12">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label w-130">匹配备注：</label>
                                            <div class="layui-input-block ">
                                    <textarea readonly
                                              class="layui-textarea layui-bg-gray">${deliverOrder.columns.remarks}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                </c:if>
                            </c:if>

                            <c:if test="${not empty deliverOrder && deliverOrder.columns.status ne '1' && deliverOrder.columns.status ne '3'}">
                                <div>
                                <c:if test="${user.userType eq '1' || user.userType eq '4'}">
                                    <div class="layui-col-xs8">
                                        <div class="layui-col-xs6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label w-130">发货单位：</label>
                                                <div class="layui-input-block ">
                                                    <input type="text" disabled name="deliverName" readonly
                                                           autocomplete="off"
                                                           placeholder=""
                                                           class="layui-input layui-bg-gray"
                                                           value="${deliverOrder.columns.deliver_name}">
                                                </div>
                                            </div>
                                        </div>
                                        </c:if>
                                        <div class="layui-col-xs6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label w-130">发货方式：</label>
                                                <div class="layui-input-block ">
                                                    <input type="text" disabled name="deliverMethodName" readonly
                                                           autocomplete="off"
                                                           placeholder=""
                                                           class="layui-input layui-bg-gray"
                                                           value="${deliverOrder.columns.deliver_method_name}">
                                                </div>
                                            </div>
                                        </div>

                                        <c:if test="${not empty deliverOrder.columns.express_no}">
                                            <div class="layui-col-xs6">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">物流单号：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" disabled name="expressNo" readonly
                                                               autocomplete="off"
                                                               placeholder=""
                                                               class="layui-input layui-bg-gray"
                                                               value="${deliverOrder.columns.express_no}">
                                                    </div>
                                                </div>
                                            </div>
                                        </c:if>
                                        <c:if test="${empty deliverOrder.columns.express_no}">
                                            <div class="layui-col-xs6">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">司机：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" disabled name="deliverDriver" readonly
                                                               autocomplete="off"
                                                               placeholder=""
                                                               class="layui-input layui-bg-gray"
                                                               value="${deliverOrder.columns.deliver_driver}">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs6">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">联系方式：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" disabled name="deliverMobile" readonly
                                                               autocomplete="off"
                                                               placeholder=""
                                                               class="layui-input layui-bg-gray"
                                                               value="${deliverOrder.columns.deliver_mobile}">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs6">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">车牌号：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" disabled name="deliverCarNum" readonly
                                                               autocomplete="off"
                                                               placeholder=""
                                                               class="layui-input layui-bg-gray"
                                                               value="${deliverOrder.columns.deliver_car_num}">
                                                    </div>
                                                </div>
                                            </div>
                                        </c:if>
                                        <div class="layui-col-xs6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label w-130">发货时间：</label>
                                                <div class="layui-input-block ">
                                                    <input type="text" disabled name="deliverCarNum" readonly
                                                           autocomplete="off"
                                                           placeholder=""
                                                           class="layui-input layui-bg-gray"
                                                           value='<fmt:formatDate value="${deliverOrder.columns.deliver_time}" pattern="yyyy-MM-dd HH:mm"/>'>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs12">
                                            <div class="layui-form-item mb-5">
                                                <label class="layui-form-label w-130">发货备注：</label>
                                                <div class="layui-input-block ">
                                            <textarea readonly
                                                      class="layui-textarea layui-bg-gray">${deliverOrder.columns.deliver_remark}</textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs4">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label w-130">接货单：</label>
                                            <div class="layui-input-block">
                                                <div class="layer-photos-demo">
                                                  <%--  <img src="${commonStaticImgPath}${deliverOrder.columns.deliver_invoice}"
                                                         alt="img placeholder" style="width: 80px; height: 80px;">--%>
                                                      <a target="_blank"  id="pic" style="color:#D9B589;cursor:pointer;" href="${commonStaticImgPath}${deliverOrder.columns.deliver_invoice}">查看接货单</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </c:if>

                            <c:if test="${deliverOrder.columns.status eq '5' || deliverOrder.columns.status eq '6' || deliverOrder.columns.status eq '7'}">
                                <div>
                                    <div class="layui-col-xs8">
                                        <div class="layui-col-xs6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label w-130">入库时间：</label>
                                                <div class="layui-input-block ">
                                                    <input type="text" name="receiveTime" readonly autocomplete="off"
                                                           placeholder=""
                                                           class="layui-input layui-bg-gray"
                                                           value='<fmt:formatDate value="${deliverOrder.columns.receive_time}" pattern="yyyy-MM-dd HH:mm"/>'>
                                                </div>
                                            </div>
                                        </div>
                                        <c:if test="${deliverOrder.columns.status eq '6' || deliverOrder.columns.status eq '7'}">
                                            <div class="layui-col-xs6">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">审核时间：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" name="auditTime" readonly autocomplete="off"
                                                               placeholder=""
                                                               class="layui-input layui-bg-gray"
                                                               value='<fmt:formatDate value="${deliverOrder.columns.audit_time}" pattern="yyyy-MM-dd HH:mm"/>'>
                                                    </div>
                                                </div>
                                            </div>
                                        </c:if>
                                        <c:if test="${not empty deliverOrder.columns.receive_remark}">
                                            <div class="layui-col-xs12">
                                                <div class="layui-form-item mb-5">
                                                    <label class="layui-form-label w-130">入库说明：</label>
                                                    <div class="layui-input-block ">
                                                <textarea readonly
                                                          class="layui-textarea layui-bg-gray">${deliverOrder.columns.receive_remark}</textarea>
                                                    </div>
                                                </div>
                                            </div>
                                        </c:if>
                                        <c:if test="${deliverOrder.columns.status eq '6' || deliverOrder.columns.status eq '7'}">
                                            <div class="layui-col-xs12">
                                                <div class="layui-form-item mb-5">
                                                    <label class="layui-form-label w-130">审核备注：</label>
                                                    <div class="layui-input-block ">
                                                    <textarea readonly
                                                              class="layui-textarea layui-bg-gray">${deliverOrder.columns.audit_remark}</textarea>
                                                    </div>
                                                </div>
                                            </div>
                                        </c:if>
                                    </div>
                                    <c:if test="${not empty deliverOrder.columns.receive_invoice}">
                                        <div class="layui-col-xs4">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label w-130">接货单：</label>
                                                <div class="layui-input-block">
                                                    <div class="layer-photos-demo">
                                                       <%-- <img src="${commonStaticImgPath}${deliverOrder.columns.receive_invoice}"
                                                             alt="img placeholder" style="width: 80px; height: 80px;">--%>
                                                           <a target="_blank"  id="pic" style="color:#D9B589;cursor:pointer;" href="${commonStaticImgPath}${deliverOrder.columns.receive_invoice}">查看接货单</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </c:if>
                                </div>
                            </c:if>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <c:if test="${empty deliverOrder}">
                    <ul class="layui-tab-title">
                        <c:choose>
                            <c:when test="${applyOrder.columns.status eq '1' || applyOrder.columns.status eq '2' || applyOrder.columns.status eq '3' || applyOrder.columns.status eq '4'}">
                                <li class="layui-this">物料汇总</li>
                                <li>物料明细</li>
                            </c:when>
                            <c:otherwise>
                                <li class="layui-this">物料明细</li>
                            </c:otherwise>
                        </c:choose>
                        <li>过程记录</li>
                    </ul>
                    <div class="layui-tab-content">
                        <c:if test="${applyOrder.columns.status eq '1' || applyOrder.columns.status eq '2' || applyOrder.columns.status eq '3' || applyOrder.columns.status eq '4'}">
                            <div class="layui-tab-item layui-show">
                                <table class="layui-table">
                                    <thead>
                                    <th>序号</th>
                                    <th>物料/BOM代码</th>
                                    <th>物料/BOM类型</th>
                                    <th>物料组</th>
                                    <th>物料/BOM描述</th>
                                    <th>申请数量</th>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${gatherDetails}" var="gatherDetail" varStatus="vs">
                                        <tr>
                                            <td>${vs.count}</td>
                                            <td>${gatherDetail.columns.code}</td>
                                            <td>${gatherDetail.columns.materialTypeName}</td>
                                            <td>${gatherDetail.columns.materialGroupName}</td>
                                            <td>${gatherDetail.columns.remarks}</td>
                                            <td>${gatherDetail.columns.amount}</td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </c:if>
                        <div class="layui-tab-item ${applyOrder.columns.status eq '1' || applyOrder.columns.status eq '2' || applyOrder.columns.status eq '3' || applyOrder.columns.status eq '4'? '': 'layui-show'}">
                            <table class="layui-table">
                                <thead>
                                <th>序号</th>
                                <th>物料代码</th>
                                <th>物料类型</th>
                                <th>物料组</th>
                                <th>单位</th>
                                <th>物料描述</th>
                                <th>申请数量</th>
                                </thead>
                                <tbody>
                                <c:forEach items="${applyDetails}" var="applyDetail" varStatus="vs">
                                    <tr>
                                        <td>${vs.count}</td>
                                        <td>${applyDetail.columns.code}</td>
                                        <td>${applyDetail.columns.materialTypeName}</td>
                                        <td>${applyDetail.columns.materialGroupName}</td>
                                        <td>${applyDetail.columns.unit_name}</td>
                                        <td>${applyDetail.columns.remarks}</td>
                                        <td>${applyDetail.columns.apply_amount}</td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-tab-item">
                            <c:forEach items="${applyOrderMsgList}" var="msg" varStatus="vs">
                                <div class="mb-10">
                                    <fmt:formatDate value="${msg.operateTime}" pattern="yyyy-MM-dd HH:mm"/>
                                        ${msg.content}
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                </c:if>
                <c:if test="${not empty deliverOrder}">
                    <ul class="layui-tab-title">
                        <li class="layui-this">物料清单</li>
                        <li>过程记录</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <table class="layui-table">
                                <thead>
                                <th>序号</th>
                                <th>物料代码</th>
                                <th>物料类型</th>
                                <th>物料组</th>
                                <th>单位</th>
                                <th>物料描述</th>
                                <th>下单数量</th>
                                <th>实发数量</th>
                                <c:if test="${deliverOrder.columns.status ne '2'}">
                                    <th>入库数量</th>
                                </c:if>
                                </thead>
                                <tbody id="materialTbody">
                                <c:forEach items="${deliverOrderDetails}" var="applyDetail" varStatus="vs">
                                    <tr data-id="${applyDetail.columns.id}"
                                        data-materialId="${applyDetail.columns.material_id}"
                                        data-applyAmount="${applyDetail.columns.apply_amount}">
                                        <td>${vs.count}</td>
                                        <td>${applyDetail.columns.code}</td>
                                        <td>${applyDetail.columns.materialTypeName}</td>
                                        <td>${applyDetail.columns.materialGroupName}</td>
                                        <td>${applyDetail.columns.unit_name}</td>
                                        <td>${applyDetail.columns.remarks}</td>
                                        <td>${applyDetail.columns.apply_amount}</td>
                                        <td>${applyDetail.columns.out_amount}</td>
                                        <c:if test="${deliverOrder.columns.status ne '2'}">
                                            <td>${applyDetail.columns.out_amount}</td>
                                        </c:if>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-tab-item">
                            <c:forEach items="${deliverMsgList}" var="msg" varStatus="vs">
                                <div class="mb-10">
                                    <fmt:formatDate value="${msg.operateTime}" pattern="yyyy-MM-dd HH:mm"/>
                                        ${msg.content}
                                </div>
                            </c:forEach>
                            <c:forEach items="${applyOrderMsgList}" var="msg" varStatus="vs">
                                <div class="mb-10">
                                    <fmt:formatDate value="${msg.operateTime}" pattern="yyyy-MM-dd HH:mm"/>
                                        ${msg.content}
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                </c:if>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <button type="button" class="layui-btn layui-btn-primary " onclick="closeDiv();">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var $;
    var imgs = '';
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'layedit', 'laydate', 'jquery', 'layer', 'element', 'upload'], function () {
        $ = layui.jquery;
        form = layui.form;
        var element = layui.element;
        $form = $('form');

        layer.photos({
            photos: '.layer-photos-demo'
            , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });

        function transStatus() {
            if (${not empty deliverOrder}) {
                return transDeliverStatus('${deliverOrder.columns.status}');
            } else {
                return transApplyStatus('${applyOrder.columns.status}');
            }
        }

        $('input[name=mergeStatus]').val(transStatus());

        function transDeliverStatus(status){
            switch (status) {
                case '1':
                    return '待发货';
                case '2':
                    return '待收货';
                case '3':
                    return '已撤销';
                case '4':
                    return '仓库打回';
                case '5':
                    return '待入账';
                case '6':
                    return '入账驳回';
                case '7':
                    return '已完成';
                default:
                    return '';
            }
        }

        function transApplyStatus(status){
            switch (status) {
                case '1':
                    return '待业务员审批';
                case '2':
                    return '待工程部审批';
                case '3':
                    return '待运管部审批';
                case '4':
                    return '审批驳回';
                case '5':
                    return '待匹配';
                default:
                    return '';
            }
        }
    })

    function closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }


</script>
</body>
</html>
