<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<c:set var="commonStaticImgPath" value="https://nhet.oss-cn-shanghai.aliyuncs.com/"/>
<!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;
    }
    .load-icon{background: url('${ctxPlugin}/static/img/shili_img.png') center center no-repeat; width: 12px; height: 12px; display: inline-block; border-radius: 50%;
        vertical-align: text-bottom;transform: translate(0px, -1px);margin-right: 2px;}
    .bj-pdf {
        display: inline-block;
        margin-right: 10px;
        padding: 5px;
        border: 1px solid #ccc;
        border-radius: 5px;
        background-color: #f0f0f0;
        color: #333;
        font-size: 14px;
    }
    .pdfSpan {
        display: flex;
        align-items: center;
    }
    .download-link {
        display: inline-block;
        padding-top: 5px;
        padding-right: 16px;
        color: #007bff;
        text-decoration: none;
        border-radius: 4px;
    }

    .download-link:hover {
        color: #0056b3;
    }
    </style>
</head>

<body>
<div class="layui-form" >
    <div class="layui-tab-content" id="LAY_app">
        <div class="layui-card">
            <div class="layui-elem-quote" style="display: flex;justify-content: space-between;">
                <p>订单信息</p>
                <p>下单时间：${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>

                    <c:if test="${inAscriptionId eq 'a'}">
                        <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 '11'}"><input type="text" disabled name="status"
                                                                                         readonly
                                                                                         class="layui-input layui-bg-gray"
                                                                                         value="待签收确认"></c:when>
                                </c:choose>
                            </div>
                        </div>
                    </c:if>

                    <c:if test="${inAscriptionId ne 'a'}">
                        <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>
                            </div>
                        </div>
                    </c:if>

                    <div class="layui-col-xs4">
                        <label class="layui-form-label ">订单类型：</label>
                        <div class="layui-input-block">
                            <c:if test="${order.columns.pattern eq '1'}"><input type="text" disabled name="type" readonly
                                                                                class="layui-input layui-bg-gray"
                                                                                value="平台采购"></c:if>
                            <c:if test="${order.columns.pattern eq '2'}"><input type="text" disabled name="type" readonly
                                                                                class="layui-input layui-bg-gray"
                                                                                value="供应商直发"></c:if>
                            <c:if test="${order.columns.pattern eq '3'}"><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">
                        <c:if test="${inAscriptionId eq 'a'}">
                            <label class="layui-form-label ">接货人：</label>
                        </c:if>
                        <c:if test="${inAscriptionId ne 'a'}">
                            <label class="layui-form-label ">联系人：</label>
                        </c:if>
                        <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>
                    <c:if test="${inAscriptionId eq 'a'}">
                        <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.applyOrderTrader}">
                            </div>
                        </div>
                    </c:if>
                </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="qqProjectName" readonly class="layui-input layui-bg-gray" value="${order.columns.qqProjectName}">
                        </div>
                    </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>
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label">施工人员保单：</label>
                        <div class="layui-input-block img-box ml-120">
                            <div style="display: flex">
                                <div id="insuranceFilesDiv">
                                    <c:if test="${not empty order.columns.insurance_files}">
                                        <c:forEach items="${order.columns.insurance_files}" var="file" varStatus="vs">
                                            <div style="margin-top: 5px">
                                                <a style="color:#2890ac;" href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                                <a style="color:#2890ac;cursor: pointer" target="_blank" onclick="previewUrl('${commonStaticImgPath}${file}')"    class="download-link">查看</a>
                                                <input type="hidden" class="insuranceFiles" value="${file}">
                                            </div>
                                            <c:set var="insuranceFilesCount" value="${vs.count}"/>
                                        </c:forEach>
                                    </c:if>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <%--
                <div class="layui-row">
                    <div class="layui-inline layui-col-xs12">
                        <label class="layui-form-label">安全教育登记表：</label>
                        <div class="layui-input-block img-box ml-120">
                            <div style="display: flex">
                                <div id="safetyFilesDiv">
                                    <c:if test="${not empty order.columns.safety_files}">
                                        <c:forEach items="${order.columns.safety_files}" var="file" varStatus="vs">
                                            <div style="margin-top: 5px">
                                                <a style="color:#2890ac;" href="${commonStaticImgPath}${file}" download="${file}" class="download-link">${fns:substringAfterLast(file, '/')}</a>
                                                <a style="color:#2890ac;cursor: pointer" target="_blank" onclick="previewUrl('${commonStaticImgPath}${file}')"    class="download-link">查看</a>
                                                <input type="hidden" class="safetyFiles" value="${file}">
                                            </div>
                                            <c:set var="safetyFilesCount" value="${vs.count}"/>
                                        </c:forEach>
                                    </c:if>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                --%>
<%--                <c:if test="${inAscriptionId eq 'a'}">--%>
<%--                    <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.allocation_remark}</textarea>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </c:if>--%>
            </div>
            <!-- 发货信息 -->
            <div class="layui-elem-quote" style="display: flex;justify-content: space-between;">
                <p>发货信息</p>
                <p>发货时间：<fmt:formatDate value="${order.columns.deliver_time}" pattern="yyyy-MM-dd HH:mm:ss"/></p>
            </div>
            <div class="layui-tab-content">
                <div class="layui-row">
                    <c:if test="${inAscriptionId eq 'a' && order.columns.pattern ne '2'}">
                        <div class="layui-col-xs4">
                            <label class="layui-form-label ">发货仓库：</label>
                            <div class="layui-input-block ">
                                <input type="text" disabled name="outWarehouseName" readonly class="layui-input layui-bg-gray"
                                       value="${order.columns.outWarehouseName}">
                            </div>
                        </div>
                    </c:if>

                    <div class="layui-col-xs4">
                        <label class="layui-form-label ">发货方式：</label>
                        <div class="layui-input-block ">
                            <input type="text" disabled name="deliverType" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.deliver_method_name}">
                        </div>
                    </div>
                    <div class="layui-col-xs4">
                        <label class="layui-form-label ">物流单号：</label>
                        <div class="layui-input-block ">
                            <input type="text" disabled name="expressNo" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.express_no}">
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs4 layui-hide">
                        <label class="layui-form-label ">司机：</label>
                        <div class="layui-input-block ">
                            <input type="text" disabled name="deliverDriver" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.deliver_driver}">
                        </div>
                    </div>
                    <div class="layui-col-xs4 layui-hide">
                        <label class="layui-form-label ">联系方式：</label>
                        <div class="layui-input-block ">
                            <input type="text" disabled name="deliverMobile" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.deliver_mobile}">
                        </div>
                    </div>
                    <div class="layui-col-xs4 layui-hide">
                        <label class="layui-form-label ">车牌号：</label>
                        <div class="layui-input-block ">
                            <input type="text" disabled name="deliverCarNum" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.deliver_car_num}">
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12 layui-form-item  mb-5">
                        <label class="layui-form-label">送货单：</label>
                        <div class="layui-input-block">
                            <div id="qualificationsImgsDev" class="display-flex">
                                <c:if test="${not empty order.columns.delivery_voucher}">
                                    <c:forEach items="${fn:split(order.columns.delivery_voucher,',')}" var="img">
                                        <div class="bj-pdf pdfSpan">
                                            <c:set var="type" value="${fn:substring(img,img.lastIndexOf('.')+1 ,img.length() )}"/>
                                            <c:if test="${type eq 'doc' || type eq 'docx'}">
                                                <a href="${commonStaticImgPath}${img}" target="_blank">${fn:substring(img,img.lastIndexOf("/")+1 ,img.length() )}</a>
                                            </c:if>
                                            <c:if test="${type ne 'doc' && type ne 'docx'}">
                                                <span style="cursor: pointer;" onclick="viewPdf('${img}')"  class="pdfName">${fn:substring(img,img.lastIndexOf("/")+1 ,img.length() )}</span>
                                            </c:if>
                                        </div>
                                    </c:forEach>
                                </c:if>
                            </div>

                        </div>
                    </div>
                </div>

                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <label class="layui-form-label ">发货说明：</label>
                        <div class="layui-input-block ">
                            <%--                            <textarea class="layui-textarea" id="deliverRemark" name="deliverRemark"></textarea>--%>
                            <input type="text" disabled name="deliverRemark" readonly class="layui-input layui-bg-gray"
                                   value="${order.columns.deliver_remark}">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-elem-quote" style="display: flex;justify-content: space-between;">
                <p>物料清单</p>
                <%--                <p>采购总额：<span>${total}</span>元</p>--%>
            </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>--%>
                        </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-outAmount="${applyDetail.columns.out_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.out_amount}</td>
                                <td><input type="text" class="layui-input" name="confirmAmount" value="${applyDetail.columns.out_amount}"  readonly /></td>
                                    <%-- <td><a href="#" class="layui-table-link materialNumber" style='font-size:14px;'  onclick="importCode('${applyDetail.columns.id}','${applyDetail.columns.out_amount}')">0</a></td>--%>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

<%--    <div class="layui-card">--%>
<%--        <div class="layui-col-xs12 layui-form-item">--%>
<%--            <label class="layui-form-label">--%>
<%--                <i class="red">*</i>--%>
<%--                签收凭证：--%>
<%--                &lt;%&ndash;<br/><a href="${commonStaticImgPath}/prohibit_delete/示例图/货物签收单示例.png" style="font-size: 12px;color: red;margin-right: 5px;"><i class="load-icon"></i>下载示例图</a>&ndash;%&gt;--%>
<%--            </label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <div id="imgsDiv">--%>
<%--                    <c:forEach items="${imglist}" var="img">--%>
<%--                        <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this)"></span>--%>
<%--                            <img src="${commonStaticImgPath.concat(img)}" data-img="${commonStaticImgPath.concat(img)}" height="700" width="1200"/>--%>
<%--                            <input type="hidden" class="imgPicker"  value="${img}"/>--%>
<%--                        </div>--%>
<%--                    </c:forEach>--%>
<%--                </div>--%>
<%--                <div class="upload-container" id="uploader">--%>
<%--                    <img src="" alt="img placeholder" id="imgsAdd">--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<span style="color: red">(请上传清晰的pdf格式签收文件，要求文件需签字、盖公章、写明签字日期；最多可上传5张)</span>--%>
<%--        <input type="hidden" name="imgs" id="imgs" value="" lay-verify="required">--%>
<%--    </div>--%>

    <div class="layui-card">
        <div class="layui-col-xs12 layui-form-item">
            <label class="layui-form-label">
                <i class="red">*</i>
                签收凭证：
            </label>
            <div class="layui-input-block">
                <c:if test="${status eq 2}">
                    <c:if test="${not empty order.columns.receive_invoice}">
                        <c:forEach items="${fn:split(order.columns.receive_invoice,',')}" var="img">
                            <div class="imgSpan bj-pdf">
                                <span style="cursor: pointer;" onclick="viewPdf('${img}')"  class="pdfName">${fn:substring(img,img.lastIndexOf("/")+1 ,img.length() )}</span>
                            </div>
                        </c:forEach>
                    </c:if>
                </c:if>
                <c:if test="${status eq 1}">
                <div class="upload-containers" id="pdfUploader">
                    <button class="layui-btn">上传 PDF 文件</button>
                </div>
                    <div id="pdfDiv" class="display-flex" style="margin-top: 5px">
                        <c:forEach items="${pdfList}" var="pdf">
                            <div class="pdf-container">
                                <div class="pdf-content">
                                    <div class="bj-pdf pdfSpan">
                                        <a href="${commonStaticPdfPath.concat(pdf)}" target="_blank">${pdf}</a>
                                        <input type="hidden" class="pdfPicker" value="${pdf}">
                                        <span style="margin-left: 10px" class="close-icon layui-icon layui-icon-close" onclick="delPdf(this)"></span>
                                    </div>
                                </div>
                            </div>
                        </c:forEach>
                    </div>
                </c:if>
            </div>
        </div><c:if test="${status eq 1}">
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<span style="color: red">(请上传清晰的 PDF 格式签收文件，要求文件需签字、盖公章、写明签字日期；最多可上传 5 个)</span>
        <input type="hidden" name="pdfs" id="pdfs" value="" lay-verify="required">
    </c:if>
    </div>

    <div class="operate-footer">
        <c:if test="${status eq 1}"> <input type="button"  lay-submit lay-filter="inStock" value="确认" class="layui-btn "></c:if>
        <c:if test="${status eq 2}"><input type="button"  lay-submit lay-filter="agentFalse" value="撤回" class="layui-btn ">
        <input type="button" lay-submit lay-filter="agentOk" value="确认" class="layui-btn "></c:if>
        <button type="button" class="layui-btn layui-btn-primary " onclick="closeDiv();">取消</button>
    </div>
</div>

<div class="hide pd-10" style="padding: 10px" id="ideaDiv">
    <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 src="${ctxPlugin}/lib/base64.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}$/;
    var numReg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-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');

        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#pdfUploader' //绑定元素
            , url: '${ctx}/common/uploadFile3', //上传接口
            accept: 'file',
            exts: 'pdf'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {

                });
            }
            , done: function (res) {
                //上传完毕回调
              //  addImg(res.path);

                addPdf(res)
            }
            , error: function () {
                //请求异常回调
            }
        });

        var submitFlag = true;
        form.on('submit(inStock)', function (d) {
            if (!submitFlag) {
                return;
            }
            var loadingIndex = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });

            var $trs = $('#materialTbody>tr');
            var details = [];
            var detailFlag = false;
            for (var i = 0; i < $trs.length; i++) {
                var $tr = $trs.eq(i);
                var detail = {};
                detail.detailId = $tr.data('id');
                var confirmAmount = $tr.find('input[name=confirmAmount]').val();
                if (isBlank(confirmAmount)) {
                    layer.msg('第'+(i+1)+'行签收数量不能为空');
                    detailFlag = true;
                    return false;
                }
                if (!numReg.test(confirmAmount)) {
                    layer.msg('第'+(i+1)+'行签收数量格式不正确');
                    detailFlag = true;
                    return false;
                }
                detail.confirmAmount = confirmAmount;
                details.push(detail);
            }
            if (detailFlag) {
                return;
            }
            submitFlag = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/material/order/agentOk',
                contentType: 'application/json',
                data: JSON.stringify({
                    orderId: '${id}',
                    receiveInvoice: imgs,
                    details: details
                }),
                dataType: 'json',
                success: function (data) {
                    afterSuccess(data);
                },
                error: function (data){
                    layer.closeAll("loading");
                },
                complete: function () {
                    submitFlag = true;
                }
            });
        });

        var agentFalse = true;
        form.on('submit(agentFalse)', function (d) {
            if (!agentFalse) {
                return;
            }
            agentFalse = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/material/order/agentFalse',
                contentType: 'application/json',
                data: JSON.stringify({
                    orderId: '${id}'
                }),
                dataType: 'json',
                success: function (data) {
                    afterSuccess(data);
                },
                error: function (data){
                    layer.closeAll("loading");
                },
                complete: function () {
                    submitFlag = true;
                }
            });
        });
        var submitFla = true;
        form.on('submit(agentOk)', function (d) {
            if (!submitFla) {
                return;
            }
            var loadingIndex = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });

            var $trs = $('#materialTbody>tr');
            var details = [];
            var detailFla = false;
            for (var i = 0; i < $trs.length; i++) {
                var $tr = $trs.eq(i);
                var detail = {};
                detail.detailId = $tr.data('id');
                var confirmAmount = $tr.find('input[name=confirmAmount]').val();
                if (isBlank(confirmAmount)) {
                    layer.msg('第'+(i+1)+'行签收数量不能为空');
                    detailFlag = true;
                    return false;
                }
                if (!numReg.test(confirmAmount)) {
                    layer.msg('第'+(i+1)+'行签收数量格式不正确');
                    detailFlag = true;
                    return false;
                }
                detail.confirmAmount = confirmAmount;
                details.push(detail);
            }

            submitFla = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/material/order/inStock',
                contentType: 'application/json',
                data: JSON.stringify({
                    orderId: '${id}',
                    receiveInvoice: imgs,
                    details: details
                }),
                dataType: 'json',
                success: function (data) {
                    afterSuccess(data);
                },
                error: function (data){
                    layer.closeAll("loading");
                },
                complete: function () {
                    submitFlag = 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.position = $tr.find('input[name=position]').val();
                data.inAmount = $tr.find('input[name=inAmount]').val();
                arr.push(data);
            }
            return arr;
        }*/

        changeMethodType('${methodType}');
    })

    function changeMethodType(type) {
        if (type === "0") {
            $('input[name=expressNo]').closest('.layui-col-xs4').removeClass('layui-hide');
            $('input[name=deliverDriver]').closest('.layui-col-xs4').removeClass('layui-hide').addClass('layui-hide');
            $('input[name=deliverMobile]').closest('.layui-col-xs4').removeClass('layui-hide').addClass('layui-hide');
            $('input[name=deliverCarNum]').closest('.layui-col-xs4').removeClass('layui-hide').addClass('layui-hide');
        } else {
            $('input[name=expressNo]').closest('.layui-col-xs4').removeClass('layui-hide').addClass('layui-hide');
            $('input[name=deliverDriver]').closest('.layui-col-xs4').removeClass('layui-hide');
            $('input[name=deliverMobile]').closest('.layui-col-xs4').removeClass('layui-hide');
            $('input[name=deliverCarNum]').closest('.layui-col-xs4').removeClass('layui-hide');
        }
    }

    /*function giveBack() {
        layer.open({
            type: 1,
            area: ['450px', '280px'],
            content: $("#ideaDiv"),
            title: '打回',
            btn: ['确认', '取消'],
            btnAlign: 'c',
            yes: function () {
                var idea = $('#idea').val();
                if (isBlank(idea)) {
                    layer.msg('请输入打回原因', {icon: 2});
                    return;
                }
                sureGiveBack(idea);
            }
        })
    }

    var backFlag = true;
    function sureGiveBack(reason) {
        if (!backFlag) {
            return;
        }
        backFlag = false;
        $.ajax({
            type: 'post',
            <%--url: '${ctx}/material/order/giveBack',--%>
            data: {
                <%--id: '${id}',--%>
                reason: reason
            },
            dataType: 'json',
            success: function (data) {
                afterSuccess(data);
            },
            complete: function () {
                backFlag = true;
            }
        });
    }*/

    function importCode(id,amount){
        layer.open({
            title: '物料条码',
            type: 2,
            area: ['550px', '300px'],
            content: '${ctx}/barcodeManage/toImportBarcode?id='+id+"&amount="+amount
        });
    }

    function afterSuccess(data) {
        if (data.code === '200') {
            parent.layer.closeAll();
            parent.layer.msg('操作成功');
            parent.searchOrder();
        } else {
            layer.msg(data.errMsg);
        }
    }

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

    <%--var imgsCount = 0;--%>
    <%--function addImg(data){--%>
    <%--    imgs = '';--%>
    <%--    imgsCount++;--%>
    <%--    if (imgsCount >= 5) {--%>
    <%--        $("#uploader").hide();--%>
    <%--    }else{--%>
    <%--        $("#uploader").show();--%>
    <%--    }--%>
    <%--    var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this)"></span>';--%>
    <%--    html += '<img src="${commonStaticImgPath}'+data+'" height="700" width="1200"/>';--%>
    <%--    html += '<input type="hidden" class="imgPicker" value="'+data+'"/> </div>';--%>
    <%--    $("#imgsDiv").append(html);--%>
    <%--    var imgSelector = $(".imgPicker");--%>
    <%--    imgSelector.each(function (index) {--%>
    <%--        var img = $(this).val();--%>
    <%--        if (!isBlank(img)) {--%>
    <%--            imgs += img + ",";--%>
    <%--        }--%>
    <%--    });--%>
    <%--    $("#imgs").val(imgs);--%>
    <%--}--%>

    <%--function delImg(that){--%>
    <%--    imgs = '';--%>
    <%--    imgsCount--;--%>
    <%--    if (imgsCount < 5) {--%>
    <%--        $("#uploader").show();--%>
    <%--    }--%>
    <%--    $(that).parent().remove();--%>
    <%--    var imgSelector = $(".imgPicker");--%>
    <%--    imgSelector.each(function (index) {--%>
    <%--        var img = $(this).val();--%>
    <%--        if (!isBlank(img)) {--%>
    <%--            imgs += img + ",";--%>
    <%--        }--%>
    <%--    });--%>
    <%--    $("#imgs").val(imgs);--%>
    <%--}--%>

    var pdfs = '';
    var pdfsCount = 0;

    function addPdf(data) {
        imgs = '';
        console.log(pdfsCount,"pdfsCount")
        console.log("data",data)
        if (pdfsCount >= 4) {
            $("#pdfUploader").hide();
        } else {
            $("#pdfUploader").show();
        }
        pdfsCount++;
        var html = '<div class="bj-pdf pdfSpan" onclick="viewPdf(\'' + data.path + '\')" ><span class="pdfName">' + data.filename + '</span><span class="layui-icon-close layui-icon" onclick="delPdf(this)"></span>';
        html += '<input type="hidden" class="pdfPicker" data-path="' + data.path + '" value="' + data.path + '"/></div>';
        $("#pdfDiv").append(html);
        var imgSelector = $(".pdfPicker");
        imgSelector.each(function (index) {
            var img = $(this).val();
            if (!isBlank(img)) {
                imgs += img + ",";
            }
        });
        updatePdfsValue();
    }



    function viewPdf(_url){
        _url = '${commonStaticImgPath}' + _url
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded =  base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }

    function previewUrl(_url) {
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded = base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }

    function checkUrl(url) {
        //url= 协议://(ftp的登录信息)[IP|域名](:端口号)(/或?请求参数)
        var strRegex = '^((https|http|ftp)://)'//(https或http或ftp)
            + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' //ftp的user@  可有可无
            + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
            + '|' // 允许IP和DOMAIN（域名）
            + '(localhost)|'	//匹配localhost
            + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
            + '\\w+\\.' // 一级域名 -英文或数字  加上.
            + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
            + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
            + '((/?)|' // url无参数结尾 - 斜杆或这没有
            + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
        var re = new RegExp(strRegex, 'i');//i不区分大小写
        //将url做uri转码后再匹配，解除请求参数中的中文和空字符影响
        if (re.test(encodeURI(url))) {
            return (true);
        } else {
            return (false);
        }
    }


    <%--function viewPdf(data) {--%>
    <%--    const url = '${commonStaticImgPath}' + data;--%>
    <%--    layui.use('layer', function () {--%>
    <%--        var layer = layui.layer;--%>

    <%--        var html = '<iframe src="pdfjs/web/viewer.html?file=' + encodeURIComponent(url) + '" style="border: 0; width: 100%; height: 100%;">';--%>

    <%--        layer.open({--%>
    <%--            type: 1,--%>
    <%--            area: ['1000px', '750px'],--%>
    <%--            title: false,--%>
    <%--            closeBtn: 1,--%>
    <%--            content: html--%>
    <%--        });--%>
    <%--    });--%>
    <%--}--%>






    function delPdf(that) {
        event.stopPropagation();
        pdfsCount--;
        if (pdfsCount < 5) {
            $("#pdfUploader").show();
        }
        $(that).parent().remove();
        updatePdfsValue();
    }

    function updatePdfsValue() {
        pdfs = '';
        var pdfSelector = $(".pdfPicker");
        pdfSelector.each(function(index) {
            var pdf = $(this).val();
            if (pdf.trim() !== '') {
                pdfs += pdf + ",";

            }
        });
        $("#pdfs").val(pdfs);
    }

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


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