<%@ 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">
    <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-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">表单信息</li>
            <c:if test="${user.userType eq '1' || user.userType eq '4'}">
                <li>过程信息</li>
            </c:if>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show" id="LAY_app">
                <div class="layui-card">
                    <div class="layui-elem-quote" style="display: flex;justify-content: space-between;">
                        <p>订单信息</p>
                        <p style="color: #0099cc;">下单时间：${order.columns.place_time}</p>
                    </div>
                    <div class="layui-tab-content">
                        <div class="layui-row">
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">订单编号：</label>
                                <div class="layui-input-block ">
                                    <input type="text" disabled name="inWarehouseName" readonly autocomplete="off"
                                           placeholder="请输入"
                                           class="layui-input layui-bg-gray" value="${order.columns.number}">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">订单状态：</label>
                                <div class="layui-input-block ">
                                    <c:choose>
                                        <c:when test="${order.columns.status eq '1'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="待审批"></c:when>
                                        <c:when test="${order.columns.status eq '2'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="采购分配"></c:when>
                                        <c:when test="${order.columns.status eq '3'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="分配打回"></c:when>
                                        <c:when test="${order.columns.status eq '4'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="采购审批"></c:when>
                                        <c:when test="${order.columns.status eq '5'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="待发货"></c:when>
                                        <c:when test="${order.columns.status eq '6'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="待签收"></c:when>
                                        <c:when test="${order.columns.status eq '7'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="已完成"></c:when>
                                        <c:when test="${order.columns.status eq '8'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="已并单"></c:when>
                                        <c:when test="${order.columns.status eq '9'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="发货打回"></c:when>
                                        <c:when test="${order.columns.status eq '10'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="待确认入库"></c:when>
                                        <c:when test="${order.columns.status eq 'a'}"><input type="text" disabled name="status" readonly class="layui-input layui-bg-gray" value="发货审核不通过"></c:when>
                                    </c:choose>
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">订单来源：</label>
                                <div class="layui-input-block">
                                    <c:if test="${order.columns.type eq '1'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="项目订单"></c:if>
                                    <c:if test="${order.columns.type eq '2'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="储备物料单"></c:if>
                                    <c:if test="${order.columns.type eq '3'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="平台采购"></c:if>
                                    <c:if test="${order.columns.type eq '4'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="合并发货"></c:if>
                                    <c:if test="${order.columns.type eq '5'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="材料下单"></c:if>
                                    <c:if test="${order.columns.type eq '6'}"><input type="text" disabled name="type" readonly class="layui-input layui-bg-gray" value="企企数据"></c:if>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">入库仓库：</label>
                                <div class="layui-input-block ">
                                    <input type="text" disabled name="inWarehouseName" readonly class="layui-input layui-bg-gray" value="${order.columns.inWarehouseName}">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">接货人：</label>
                                <div class="layui-input-block ">
                                    <input type="text" disabled name="personInCharge" readonly class="layui-input layui-bg-gray" value="${order.columns.person_in_charge}">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <label class="layui-form-label ">联系方式：</label>
                                <div class="layui-input-block ">
                                    <input type="text" disabled name="mobile" readonly class="layui-input layui-bg-gray" value="${order.columns.mobile}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs8">
                                <label class="layui-form-label ">仓库地址：</label>
                                <div class="layui-input-block ">
                                    <input type="text" disabled name="mobile" readonly class="layui-input layui-bg-gray" value="${order.columns.w_address}">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <c:if test="${order.columns.pattern eq '1'}">
                                    <label class="layui-form-label ">供应商名称：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="mobile" readonly class="layui-input layui-bg-gray" value="${order.columns.deliver_name}">
                                    </div>
                                </c:if>
                                <c:if test="${order.columns.pattern ne '1'}">
                                    <label class="layui-form-label ">代理商名称：</label>
                                    <div class="layui-input-block ">
                                        <input type="text" disabled name="mobile" readonly class="layui-input layui-bg-gray" value="${order.columns.applyOrderTrader}">
                                    </div>
                                </c:if>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-xs12">
                                <label class="layui-form-label">订单备注：</label>
                                <div class="layui-input-block ">
                                <textarea readonly class="layui-textarea layui-bg-gray">${order.columns.remarks}</textarea>
                                </div>
                            </div>
                        </div>

                        <c:if test="${order.columns.status eq '4' && not empty order.columns.warehouse_fail_reason}">
                            <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">${order.columns.warehouse_fail_reason}</textarea>
                                </div>
                            </div>
                        </c:if>
                    </div>

                    <c:if test="${order.columns.status eq '5'}">
                        <div class="layui-col-xs12 mt-10 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-elem-quote">
                                    <p>发货信息</p>
                                </div>
                                <div class="layui-tab-content">
                                    <c:if test="${opt ne 'view'}">
                                        <div class="layui-tab-item layui-show">
                                            <div class="layui-inline layui-col-xs8">
                                                <div class="layui-form-item layui-col-xs6">
                                                    <label class="layui-form-label w-130"><i class="red">*</i>发货方式：</label>
                                                    <div class="layui-input-block ">
                                                        <select name="deliverMethodId" lay-verify="required" id="deliverMethodId"
                                                                lay-filter="deliverMethodId">
                                                            <option value="">请选择</option>
                                                            <c:forEach items="${methods}" var="method">
                                                                <option value="${method.columns.id}" ${order.columns.deliver_method_id eq method.columns.id? 'selected': ''}
                                                                        data-type="${method.columns.type}">${method.columns.name}</option>
                                                            </c:forEach>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item layui-col-xs6 ${not empty order.columns.express_no? '': 'layui-hide'} expressNoDiv">
                                                    <label class="layui-form-label w-130"><i class="red">*</i>物流单号：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" name="expressNo" lay-verify="express"
                                                               autocomplete="off"
                                                               placeholder="请输入"
                                                               class="layui-input" value="${order.columns.express_no}">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item ${not empty order.columns.deliver_driver && order.columns.deliver_method_name ne '快递物流'? '': 'layui-hide'} otherDiv">
                                                    <div class="layui-col-xs6 layui-col-md4">
                                                        <div class="layui-inline">
                                                            <label class="layui-form-label w-130"><i class="red">*</i>司机：</label>
                                                            <div class="layui-input-block ">
                                                                <input type="text" name="deliverDriver" autocomplete="off" lay-verify="deliverDriver"
                                                                       placeholder="请输入"
                                                                       class="layui-input"
                                                                       value="${order.columns.deliver_driver}">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="layui-col-xs6 layui-col-md4">
                                                        <div class="layui-inline">
                                                            <label class="layui-form-label w-130"><i class="red">*</i>联系电话：</label>
                                                            <div class="layui-input-block ">
                                                                <input type="text" name="deliverMobile" autocomplete="off" lay-verify="deliverMobile"
                                                                       placeholder="请输入"
                                                                       class="layui-input"
                                                                       value="${order.columns.deliver_mobile}"> lay-verify="required"
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="layui-col-xs6 layui-col-md4">
                                                        <div class="layui-inline">
                                                            <label class="layui-form-label w-130"><i class="red">*</i>车牌号：</label>
                                                            <div class="layui-input-block ">
                                                                <input type="text" name="deliverCarNum" autocomplete="off"  lay-verify="deliverCarNum"
                                                                       placeholder="请输入"
                                                                       class="layui-input"
                                                                       value="${order.columns.deliver_car_num}">
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="layui-form-item">
                                                    <div class="layui-col-xs12 layui-form-item  mb-5">
                                                        <label class="layui-form-label">送货单：</label>
                                                        <div class="layui-input-block">
                                                            <div id="qualificationsImgsDev">
                                                                <c:if test="${not empty order.columns.delivery_voucher}">
                                                                    <c:forEach var="quaim" items="${quaimgs}">
                                                                        <div class="bj-img imgSpan">
                                                                            <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploaderQuali')"></span>
                                                                            <img src="${commonStaticImgPath}${quaim}" height="700" width="1200">
                                                                            <input type="hidden" class="quaImgPicker" value="${quaim}">
                                                                        </div>
                                                                    </c:forEach>
                                                                </c:if>
                                                            </div>

                                                            <div class="upload-container" id="uploaderQuali" >
                                                                <img src="" alt="img placeholder" >
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>


                                                <div class="layui-form-item mb-5">
                                                    <label class="layui-form-label w-130">发货说明：</label>
                                                    <div class="layui-input-block ">
                                                      <textarea name="deliverRemark" id="deliverRemark" class="layui-textarea">${order.columns.deliver_remark}</textarea>
                                                    </div>
                                                </div>
                                            </div>
<%--                                            <div class="layui-inline layui-col-xs4">--%>
<%--                                                <div class="layui-form-item">--%>
<%--                                                    <label class="layui-form-label w-130"><i class="red">*</i>上传接货单：</label>--%>
<%--                                                    <div class="layui-input-block ">--%>
<%--                                                        <c:if test="${not empty order.columns.deliver_invoice}">--%>
<%--                                                            <a target="_blank"  class="hide" id="pic" style="color:#D9B589;cursor:pointer;" href="${commonStaticImgPath}${order.columns.deliver_invoice}">查看接货单</a>--%>
<%--                                                        </c:if>--%>
<%--                                                        <input type="hidden" lay-verify="deliverInvoice"--%>
<%--                                                               value="${order.columns.deliver_invoice}" name="deliverInvoice"--%>
<%--                                                               id="deliverInvoice"/>--%>
<%--                                                        <div class="upload-container layer-photos-demo" id="uploader">--%>
<%--                                                                &lt;%&ndash;<img src="${commonStaticImgPath}${order.columns.deliver_invoice}"--%>

<%--                                                                     alt="img placeholder" style="width: 80px; height: 80px;" id="pic">&ndash;%&gt;--%>
<%--                                                        </div>--%>
<%--                                                    </div>--%>
<%--                                                </div>--%>
<%--                                            </div>--%>
                                        </div>
                                    </c:if>
                                    <c:if test="${opt eq 'view'}">
                                        <div class="layui-tab-item layui-show">
                                            <div class="layui-inline layui-col-xs8">
                                                <c:if test="${order.columns.deliver_id ne 'a'}">
                                                    <div class="layui-inline layui-col-xs6">
                                                        <label class="layui-form-label w-130">供应商：</label>
                                                        <div class="layui-input-block ">
                                                            <input type="text" class="layui-input layui-bg-gray" readonly
                                                                   value="${order.columns.deliver_name}">
                                                        </div>
                                                    </div>
                                                </c:if>
                                                <div class="layui-inline layui-col-xs6">
                                                    <label class="layui-form-label w-130">发货方式：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" class="layui-input layui-bg-gray" readonly
                                                               value="${order.columns.deliver_method_name}">
                                                    </div>
                                                </div>
                                                <div class="layui-inline layui-col-xs6 ${not empty order.columns.express_no? '': 'layui-hide'} expressNoDiv">
                                                    <label class="layui-form-label w-130">物流单号：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" name="expressNo" lay-verify="express" autocomplete="off"
                                                               placeholder="请输入"
                                                               class="layui-input layui-bg-gray"
                                                               value="${order.columns.express_no}">
                                                    </div>
                                                </div>
                                                <div class="layui-inline layui-col-xs6">
                                                    <label class="layui-form-label w-130">出库仓库：</label>
                                                    <div class="layui-input-block ">
                                                        <input type="text" class="layui-input layui-bg-gray" readonly
                                                               value="${order.columns.outWarehouseName}">
                                                    </div>
                                                </div>
                                                <div class="${not empty order.columns.express_no? 'layui-hide': ''}">
                                                    <div class="layui-inline layui-col-xs6">
                                                        <label class="layui-form-label w-130"><i class="red">*</i>司机：</label>
                                                        <div class="layui-input-block ">
                                                            <input type="text" class="layui-input layui-bg-gray" readonly
                                                                   value="${order.columns.deliver_driver}">
                                                        </div>
                                                    </div>
                                                    <div class="layui-inline layui-col-xs6">
                                                        <label class="layui-form-label w-130"><i class="red">*</i>联系电话：</label>
                                                        <div class="layui-input-block ">
                                                            <input type="text" class="layui-input layui-bg-gray" readonly
                                                                   value="${order.columns.deliver_mobile}">
                                                        </div>
                                                    </div>
                                                    <div class="layui-inline layui-col-xs6">
                                                        <label class="layui-form-label w-130"><i class="red">*</i>车牌号：</label>
                                                        <div class="layui-input-block ">
                                                            <input type="text" class="layui-input layui-bg-gray" readonly
                                                                   value="${order.columns.deliver_car_num}">
                                                        </div>
                                                    </div>
                                                </div>
<%--                                                <div class="layui-inline layui-col-xs6">--%>
<%--                                                    <label class="layui-form-label w-130">发货时间：</label>--%>
<%--                                                    <div class="layui-input-block ">--%>
<%--                                                        <input type="text" readonly class="layui-input layui-bg-gray"--%>
<%--                                                               value="<fmt:formatDate value="${order.columns.deliver_time}" pattern="yyyy-MM-dd HH:mm"/>">--%>
<%--                                                    </div>--%>
<%--                                                </div>--%>

                                                <%--<div class="layui-form-item">
                                                    <div class="layui-col-xs12 layui-form-item  mb-5">
                                                        <label class="layui-form-label">送货单：</label>
                                                        <div class="layui-input-block">
                                                            <div id="qualificationsImgsDev">
                                                                <c:if test="${not empty order.columns.delivery_voucher}">
                                                                    <c:forEach var="quaim" items="${quaimgs}">
                                                                        <div class="bj-img imgSpan">
                                                                            <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploaderQuali')"></span>
                                                                            <img src="${commonStaticImgPath}${quaim}" height="700" width="1200">
                                                                            <input type="hidden" class="quaImgPicker" value="${quaim}">
                                                                        </div>
                                                                    </c:forEach>
                                                                </c:if>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>--%>
                                                <div class="layui-form-item mb-5">
                                                    <label class="layui-form-label w-130">发货说明：</label>
                                                    <div class="layui-input-block ">
                                            <textarea readonly name="deliverRemark" id="deliverRemark"
                                                      class="layui-textarea layui-bg-gray">${order.columns.deliver_remark}</textarea>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-xs4">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label w-130">接货单：</label>
                                                    <div class="layui-input-block ">
                                                        <div class="upload-container layer-photos-demo">
                                                                <%-- <img src="${commonStaticImgPath}${order.columns.deliver_invoice}"
                                                                      alt="img placeholder" style="width: 80px; height: 80px;"
                                                                      id="pic">--%>
                                                            <c:if test="${not empty order.columns.deliver_invoice}">
                                                                <a target="_blank"  id="pic" style="color:#D9B589;cursor:pointer;" href="${commonStaticImgPath}${order.columns.deliver_invoice}">查看接货单</a>
                                                            </c:if>
                                                            <input type="hidden" lay-verify="deliverInvoice"
                                                                   value="${order.columns.deliver_invoice}" name="deliverInvoice"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </c:if>
                                </div>
                            </div>
                        </div>
                    </c:if>

                    <div class="layui-elem-quote" style="display: flex;justify-content: space-between;">
                        <p>物料清单</p>
                        <c:if test="${user.userType eq '1' || user.userType eq '4'}">
                            <p>采购总额：<span class="red">${total}</span>元</p>
                        </c:if>
                    </div>
                    <div class="layui-tab-content">
                        <div class="layui-row">
                            <table class="layui-table">
                                <thead>
                                <th>序号</th>
                                <th>物料代码</th>
                                <th>物料名称</th>
                                <th>物料类型</th>
                                <th>物料品牌</th>
                                <th>物料规格</th>
                                <th>单位</th>
                                <th>发货数量</th>
                                <th>采购单价</th>
                                <th>采购总价</th>



                                </thead>
                                <tbody id="materialTbody">
                                <c:forEach items="${details}" 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.material_name}</td>
                                        <td>${applyDetail.columns.materialTypeName}</td>
                                        <td>${applyDetail.columns.material_brand}</td>
                                        <td>${applyDetail.columns.material_spec}</td>
                                        <td>${applyDetail.columns.unit_name}</td>
                                        <td>${applyDetail.columns.apply_amount}</td>
                                        <td>${applyDetail.columns.purchase_price}</td>
                                        <td>${applyDetail.columns.countPrice}</td>


                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>

                    </div>


<%--                    <div class="layui-col-xs12 mb-10 pr-30">--%>
<%--                        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">--%>
<%--                            <ul class="layui-tab-title">--%>
<%--                                <li class="layui-this">物料清单</li>--%>
<%--                                <c:if test="${opt eq 'view'}">--%>
<%--                                    <li>过程记录</li>--%>
<%--                                </c:if>--%>
<%--                            </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>--%>
<%--                                        <c:if test="${opt eq 'fh' && order.columns.status eq '1'}">--%>
<%--                                            <th>实发/拆单数量</th>--%>
<%--                                        </c:if>--%>
<%--                                        <c:if test="${opt ne 'fh' || order.columns.status ne '1'}">--%>
<%--                                            <th>实发数量</th>--%>
<%--                                        </c:if>--%>
<%--                                        </thead>--%>
<%--                                        <tbody id="materialTbody">--%>
<%--                                        <c:forEach items="${details}" 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}</td>--%>
<%--                                                <td>${applyDetail.columns.remarks}</td>--%>
<%--                                                <td>${applyDetail.columns.apply_amount}</td>--%>
<%--                                                <c:if test="${opt eq 'view'}">--%>
<%--                                                    <td>${applyDetail.columns.out_amount}</td>--%>
<%--                                                </c:if>--%>
<%--                                                <c:if test="${opt ne 'view'}">--%>
<%--                                                    <c:if test="${order.columns.status eq '4'}">--%>
<%--                                                        <td><input type="text" class="layui-input" name="amount"--%>
<%--                                                                   value='${applyDetail.columns.out_amount}'/>--%>
<%--                                                        </td>--%>
<%--                                                    </c:if>--%>
<%--                                                    <c:if test="${order.columns.status ne '4'}">--%>
<%--                                                        <td><input type="text" class="layui-input" name="amount"--%>
<%--                                                                   value='${applyDetail.columns.apply_amount}'/>--%>
<%--                                                        </td>--%>
<%--                                                    </c:if>--%>
<%--                                                </c:if>--%>
<%--                                            </tr>--%>
<%--                                        </c:forEach>--%>
<%--                                        </tbody>--%>
<%--                                    </table>--%>
<%--                                </div>--%>
<%--                                <c:if test="${opt eq 'view'}">--%>
<%--                                    <div class="layui-tab-item">--%>
<%--                                        <c:forEach items="${msgList}" 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>--%>
<%--                                </c:if>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                    </div>--%>
                </div>
                <c:if test="${order.columns.status eq '7'}">
                    <div class="layui-card">
                        <div class="layui-col-xs12 layui-form-item">
                            <label class="layui-form-label">
                                <i class="mark">*</i>签收凭证：
                            </label>
                            <div class="layui-input-block">
                                <div id="imgsDiv">
                                    <c:forEach items="${imglist}" var="img">
                                            <%--<span class="layui-icon-close layui-icon" onclick="delImg(this)"></span>--%>

                                                <p style="margin-left:3%"><a class="h-32 lh-32 layui-span-unit lookBtn"
                                                                             target="_blank" href="${commonStaticImgPath.concat(img)}" style="color: #2890ac;">查看</a>
                                                </p>
                                    </c:forEach>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>
            </div>
            <div class="layui-tab-item">
                <c:if test="${opt eq 'view'}">

                    <c:forEach items="${msgList}" var="msg" varStatus="vs">
                        <p class="layui-form-item mb-10">
                        <div class="layui-col-sm3 layui-col-md2"><fmt:formatDate value="${msg.operateTime}" pattern="yyyy-MM-dd HH:mm" /></div>
                        <div class="layui-col-sm3 layui-col-md5">${msg.operator}</div>
                        <div class="layui-col-sm6 layui-col-md5">${msg.content}</div>
                        </p>
                    </c:forEach>

                </c:if>
            </div>
        </div>
    </div>
    <div class="operate-footer">
            <c:if test="${opt ne 'view'}">
                <c:if test="${order.columns.status eq '1'}">
    <%--                <sfTags:pagePermission authFlag="CKGL_FHDGL_FHDGL_CD_B"--%>
    <%--                                       html='<input type="button" value="拆单" class="layui-btn " onclick="splitOrder();">'/>--%>
                    <input type="button" value="拆单" class="layui-btn " onclick="splitOrder();">
                </c:if>
                <c:if test="${order.columns.status eq '5'}">
    <%--                <sfTags:pagePermission authFlag="CKGL_FHDGL_FHDGL_FH_B"--%>
    <%--                                       html='<input type="button" lay-submit lay-filter="deliver" value="发货" class="layui-btn ">'/>--%>
                    <input type="button" lay-submit lay-filter="deliver" value="确认发货" class="layui-btn ">
                    <input type="button" lay-submit lay-filter="deliver" value="发货打回" class="layui-btn ">
<%--                    <input type="button"  onclick="temporary()" value="暂存" class="layui-btn ">--%>
<%--                    <input type="button"  onclick="printOrder()" value="打印" class="layui-btn ">--%>
                </c:if>
            </c:if>
            <button type="button" class="layui-btn layui-btn-primary " onclick="closeDiv();">取消</button>
        </div>

</div>
<div class="hide pd-10 layui-form" style="padding: 10px" id="ideaDiv">
    <div class="layui-form-item">
        <label class="layui-form-label w-130"><span class="red">*</span>出库仓库：</label>
        <div class="layui-input-block ">
            <select name="outWarehouse" lay-search>

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label w-130">下单备注：</label>
        <div class="layui-input-block ">
            <textarea class="layui-textarea orderRemark"></textarea>
        </div>
    </div>
</div>
<div class="hide pd-10" style="padding: 10px" id="auditDiv">
    <label class="layui-form-label w-130"><span class="red">*</span>驳回原因：</label>
    <div class="layui-input-block ">
        <textarea id="idea" class="idea-text f-l layui-textarea"></textarea>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script type="text/javascript">
    //图片查看效果
    var viewer = new Viewer(document.getElementById('LAY_app'));
    //初始数据
    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');

        form.verify({
            express: function (value) {
                var expressMethod = $('select[name=deliverMethodId]').find('option:selected').data('type');
                if (isBlank(value) && expressMethod === 0) {
                    return '请填写物流单号';
                }
            },
            deliverInvoice: function (value) {
                if (isBlank(value)) {
                    return '请上传接货单';
                }
            },
            deliverDriver: function (value) {
                var expressMethod = $('select[name=deliverMethodId]').find('option:selected').data('type');
                if (isBlank(value) && expressMethod != 0) {
                    return '请填写司机';
                }
            },
            deliverMobile: function (value) {
                var expressMethod = $('select[name=deliverMethodId]').find('option:selected').data('type');
                if (isBlank(value) && expressMethod != 0) {
                    return '请填写联系电话';
                }
            },
            deliverCarNum: function (value) {
                var expressMethod = $('select[name=deliverMethodId]').find('option:selected').data('type');
                if (isBlank(value) && expressMethod != 0) {
                    return '请填写车牌号';
                }
            },
        });

        if (${not empty order.columns.deliver_invoice}) {
            $('#pic').show();
        }

        <c:if test="${opt eq 'view'}">
        $('input,select,textarea').prop('disabled', true);
        form.render();
        layer.photos({
            photos: '.layer-photos-demo'
            , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });
        </c:if>

        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#uploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            , size: 5 * 1024
            , number: 1
            ,accept:'file'
            ,exts: 'jpg|png|gif|doc|docx|ppt|pdf|xls|xlsx|txt|mp4|mp3|avi|mov|rmvb|rm|flv|3gp|apk'
            , done: function (res) {
                if (res.code > 0) {
                    return layer.msg("上传失败！", {icon: 2});
                }
                var imgPath = res.path;
                $('#pic').attr('href', '${commonStaticImgPath}' + imgPath).html(res.filename); //图片链接（base64）
                $("#pic").removeClass("hide");
                //$("#uploader").hide();
                $("#deliverInvoice").val(imgPath);
            }
            , error: function () {
                //请求异常回调 演示失败状态
            }
        });

        upload.render({
            elem: '#uploaderQuali' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {

                });
            }
            , done: function (res) {
                //上传完毕回调
                quaimgsCount++;
                if (quaimgsCount >= 5) {
                    $("#uploaderQuali").hide();
                } else {
                    $("#uploaderQuali").show();
                }
                addImg(res.path,"quaimgs","qualificationsImgsDev","quaImgPicker");
            }
            , error: function () {
                //请求异常回调
            }
        });

        form.on('select(deliverMethodId)', function (d) {
            var $elem = $(d.elem);
            var $expressNo = $('.expressNoDiv');
            var $otherDiv = $('.otherDiv');
            if ($elem.find('option:selected').data('type') === 0) {
                $expressNo.removeClass('layui-hide');
                $otherDiv.addClass('layui-hide');
            } else {
                $expressNo.addClass('layui-hide');
                $otherDiv.removeClass('layui-hide')
            }
        });

        var deliverFlag = true;
        form.on('submit(deliver)', function (d) {
            if (!deliverFlag) {
                return;
            }
            var arr = getListData();
            var total = 0;
            for (var i = 0; i < arr.length; i++) {
                if (!/^\d+(\.\d{1,2})?$/.test(arr[i].amount)) {
                    layer.msg('第' + (i + 1) + '条数量格式不正确');
                    return;
                }
                if (arr[i].amount * 1 > arr[i].applyAmount * 1) {
                    layer.msg('第' + (i + 1) + '条数量不能超过下单数量');
                    return;
                }
                total += arr[i].amount * 1;
            }
            if (total === 0) {
                layer.msg('发货数量不能为0');
                return;
            }

            var quaimgs = "";
            $(".quaImgPicker").each(function () {
                if (isBlank(quaimgs)) {
                    quaimgs = $(this).val();
                } else {
                    quaimgs = quaimgs + "," + $(this).val();
                }
            });


            deliverFlag = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/material/order/doDeliver',
                contentType: 'application/json',
                data: JSON.stringify({
                    deliverMethodId: d.field.deliverMethodId,
                    expressNo: d.field.expressNo,
                    deliverRemark: d.field.deliverRemark,
                    deliverInvoice: d.field.deliverInvoice,
                    deliverDriver: d.field.deliverDriver,
                    deliverMobile: d.field.deliverMobile,
                    deliverCarNum: d.field.deliverCarNum,
                    type:'1',
                    deliveryVoucher:quaimgs,
                    materialInfo: {
                        orderId: '${order.columns.id}',
                        details: arr
                    }
                }),
                dataType: 'json',
                success: function (data) {
                    afterSuccess(data);
                },
                complete: function () {
                    deliverFlag = true;
                }
            });
        });


    })

    var temporaryflag=true;
    function temporary(){
        if (!temporaryflag) {
            return;
        }
        temporaryflag = false;
        var deliverMethodId = $("#deliverMethodId").val();
        var expressNo = $("input[name='expressNo']").val();
        var deliverRemark = $("#deliverRemark").val();
        var deliverDriver = $("input[name='deliverDriver']").val();
        var deliverMobile = $("input[name='deliverMobile']").val();
        var deliverCarNum = $("input[name='deliverCarNum']").val();
        $.ajax({
            type: 'post',
            url: '${ctx}/material/order/doTemporary',
            data: {
                deliverMethodId: deliverMethodId,
                expressNo: expressNo,
                deliverRemark: deliverRemark,
                deliverDriver: deliverDriver,
                deliverMobile: deliverMobile,
                deliverCarNum: deliverCarNum,
                orderId: '${order.columns.id}'
            },
            dataType: 'json',
            success: function (data) {
                if (data.code === '200') {
                    layer.msg('操作成功', {icon: 1});
                    window.location.href = '${ctx}/material/order/toDeliverPage?opt=fh&id=${order.columns.id}';
                } else if (data.code === '501') {
                    layer.msg(data.errMsg, {icon: 2});
                } else {
                    layer.msg('操作失败', {icon: 2});
                }

            },
            complete: function () {
                deliverFlag = true;
            }
        });
    }


    function printOrder(){
        var id='${order.columns.id}';
        layer.open({
            title: '打印',
            type: 2,
            area: ['85%', '85%'],
            fixed: false,
            content: '${ctx}/material/order/printOrder?applyId=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }

    var splitFlag = true;

    function splitOrder() {
        if (!splitFlag) {
            return;
        }
        var arr = getListData();
        var total = 0;
        for (var i = 0; i < arr.length; i++) {
            if (!/^\d+(\.\d{1,2})?$/.test(arr[i].amount)) {
                layer.msg('第' + (i + 1) + '条数量格式不正确');
                return;
            }
            if (arr[i].amount * 1 > arr[i].applyAmount * 1) {
                layer.msg('第' + (i + 1) + '条数量不能超过下单数量');
                return;
            }
            total += arr[i].amount * 1;
        }
        if (total === 0) {
            layer.msg('拆单数量不能为0');
            return;
        }

        splitFlag = false;
        $.ajax({
            type: 'post',
            url: '${ctx}/material/order/splitDeliverOrder',
            contentType: 'application/json',
            data: JSON.stringify({
                orderId: '${order.columns.id}',
                details: arr
            }),
            dataType: 'json',
            success: function (data) {
                afterSuccess(data);
            },
            complete: function () {
                splitFlag = true;
            }
        });

    }

    function getListData() {
        var $trs = $('#materialTbody>tr');
        var arr = [];
        for (var i = 0; i < $trs.length; i++) {
            var $tr = $trs.eq(i);
            var data = {};
            data.detailId = $tr.data('id');
            data.materialId = $tr.data('materialid');
            data.applyAmount = $tr.data('applyamount');
            data.amount = $tr.find('input[name=amount]').val();
            arr.push(data);
        }
        return arr;
    }

    function afterSuccess(data) {
        if (data.code === '200') {
            parent.layer.msg('操作成功', {icon: 1});
            closeDiv();
            parent.searchOrder();
        } else if (data.code === '501') {
            layer.msg(data.errMsg, {icon: 2});
        } else {
            layer.msg('操作失败', {icon: 2});
        }
    }

    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;
    }

    function addImg(data,imgType,div,imgPicker) {

        var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this, \''+imgType+'\')"></span>';
        html += '<img src="${commonStaticImgPath}' + data + '" height="700" width="1200"/>';
        html += '<input type="hidden" class="'+imgPicker+'" value="' + data + '" /> </div>';
        $("#"+div).append(html);
    }

    function delImg(that,imgType) {
        if(imgType=='imgs'){
            imgsCount--;
            if (imgsCount < 1) {
                $("#uploader").show();
            }
        }else{
            quaimgsCount--;
            if (quaimgsCount < 5) {
                $("#uploaderQuali").show();
            }
        }
        $(that).parent().remove();
    }

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