<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>待发货订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css"/>
    <style>
        .layui-table-tool-temp {
            padding-right: 0
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <form class="layui-form layui-card" id="searchForm">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <a href="${ctx}/material/order/waitDeliverOrder">
                    <li class="layui-this">待发货</li>
                </a>
                <a href="${ctx}/material/order/waitDeliverOrderEnd">
                    <li class="">已发货</li>
                </a>
                <button type="reset" class="layui-btn f-r mt-10 mr-15 pl-10 pr-10">
                    <i class="layui-icon">&#xe666;</i>重置
                </button>
                <button type="button" class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto">
            <!-- 供应链能看到所有代理商数据 -->
            <c:if test="${ascriptionId ne 'a'}">
                <input type="hidden" name="deliverId" value="${ascriptionId}"/>
            </c:if>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <!-- 关联的申请单号 -->
                    <label class="layui-form-label">订单编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="number" class="layui-input">
                    </div>
                </div>
<%--                <div class="layui-col-lg2 layui-col-sm3 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">--%>
<%--                    <label class="layui-form-label">订单来源：</label>--%>
<%--                    <div class="layui-input-block">--%>
<%--                        <select name="type" lay-search>--%>
<%--                            <option value="">请选择</option>--%>
<%--                            <option value="1">电站下单</option>--%>
<%--                            <option value="2">物料储备</option>--%>
<%--                            <option value="3">平台采购</option>--%>
<%--                            <option value="4">合并发货</option>--%>
<%--                            <option value="5">现金下单</option>--%>
<%--                        </select>--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--                <div class="layui-col-lg2 layui-col-sm3">--%>
<%--                    <label class="layui-form-label">订单类型：</label>--%>
<%--                    <div class="layui-input-block">--%>
<%--                        <select name="pattern" lay-search>--%>
<%--                            <option value="">请选择</option>--%>
<%--                            <option value="1">平台采购</option>--%>
<%--                            <option value="2">供应商直发</option>--%>
<%--                            <option value="3">平台发货</option>--%>
<%--                        </select>--%>
<%--                    </div>--%>
<%--                </div>--%>
                <div class="layui-col-lg4 layui-col-sm4">
                    <label class="layui-form-label">代理商名称：</label>
                    <div class="layui-input-block">
                        <div id="traderId"></div>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <!-- 申请单的备注 -->
                    <label class="layui-form-label">订单备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="applyOrderRemarks" class="layui-input">
                    </div>
                </div>
<%--                <div class="layui-col-lg2 layui-col-sm3 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">--%>
<%--                    <!-- 申请单的备注 -->--%>
<%--                    <label class="layui-form-label">分配说明：</label>--%>
<%--                    <div class="layui-input-block">--%>
<%--                        <input type="text" name="allocationRemark" class="layui-input">--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--                <div class="layui-col-lg2 layui-col-sm3 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">--%>
<%--                    <label class="layui-form-label">供应商名称：</label>--%>
<%--                    <div class="layui-input-block">--%>
<%--                        <div id="supplierId"></div>--%>
<%--                    </div>--%>
<%--                </div>--%>


                <c:if test="${ascriptionId ne 'a'}">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">下单人：</label>
                        <div class="layui-input-block">
                            <input type="text" name="applyOrderCreator" class="layui-input">
                        </div>
                    </div>
                </c:if>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">下单时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="placeTimeMin" class="layui-input" id="placeTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="placeTimeMax" class="layui-input" id="placeTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm4 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">
                    <label class="layui-form-label">发货仓库：</label>
                    <div class="layui-input-block">
                        <select name="outWarehouseId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${warehouses}" var="warehouse">
                                <option value="${warehouse.columns.id}">${warehouse.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

            </div>
        </div>
    </form>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<div class="hide pd-10" style="padding: 10px" id="refuseDiv">
    <label class="layui-form-label"><span class="red">*</span>拒发货原因：</label>
    <div class="layui-input-block ">
        <textarea id="reason" class="layui-textarea" lay-verify="required"></textarea>
    </div>
</div>
<div class="hide layui-tab-content" id="auditDiv">
    <label class="layui-form-label"><span class="red">*</span>驳回原因：</label>
    <div class="layui-input-block ">
        <textarea id="rejectReason" class="layui-textarea"></textarea>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <c:if test="${userType eq '8'}">
        <button class="layui-btn layui-btn-sm" lay-event="refuse"><i class="layui-icon layui-icon-ok-circle"></i>拒发货</button>
    </c:if>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laypage', 'laydate', 'form'], function () {
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        //发货
        var fhBtn = ${fns:checkPagePermission(request, 'JXSDDGL_DFHDD_DFHDD_FH_B') eq '0'};
        //发货审核
        var fhshBtn = ${fns:checkPagePermission(request, 'JXSDDGL_DFHDD_DFHDD_FHSH_B') eq '0'};

        //开始日期
        var placeTimeMin = laydate.render({
            elem: '#placeTimeMin'
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                placeTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                placeTimeMax.config.elem[0].focus();
            }
        });
        //结束日期
        var placeTimeMax = laydate.render({
            elem: '#placeTimeMax'
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                placeTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        traderSelect = xmSelect.render({
            el: '#traderId',
            name: 'traderId',
            filterable: true,
            size: 'mini',
            model: {
                label: {
                    type: 'block',
                    block: {
                        //最大显示数量, 0:不限制
                        showCount: 2,
                        //是否显示删除图标
                        showIcon: true,
                    }
                }
            },
            toolbar: {
                show: true
            },
            height: '300px',
            data: [
                <c:forEach items="${traders}" var="trader" varStatus="vs">
                <c:if test="${vs.count > 1}">, </c:if>
                {name: '${trader.columns.name}', value: '${trader.columns.id}'}
                </c:forEach>
            ]
        });
        traderSelect.setValue('${map.traderId}'.split(","));

        <%--supplierSelect = xmSelect.render({--%>
        <%--    el: '#supplierId',--%>
        <%--    name: 'supplierId',--%>
        <%--    filterable: true,--%>
        <%--    size: 'mini',--%>
        <%--    model: {--%>
        <%--        label: {--%>
        <%--            type: 'block',--%>
        <%--            block: {--%>
        <%--                //最大显示数量, 0:不限制--%>
        <%--                showCount: 2,--%>
        <%--                //是否显示删除图标--%>
        <%--                showIcon: true,--%>
        <%--            }--%>
        <%--        }--%>
        <%--    },--%>
        <%--    toolbar: {--%>
        <%--        show: true--%>
        <%--    },--%>
        <%--    height: '300px',--%>
        <%--    data: [--%>
        <%--        <c:forEach items="${supplies}" var="supply" varStatus="vs">--%>
        <%--        <c:if test="${vs.count > 1}">, </c:if>--%>
        <%--        {name: '${supply.columns.name}', value: '${supply.columns.id}'}--%>
        <%--        </c:forEach>--%>
        <%--    ]--%>
        <%--});--%>
        <%--supplierSelect.setValue('${map.supplierId}'.split(","));--%>


        form.on('select(supplyId)', function (d) {
            var $select = $('select[name=outWarehouseId]');
            $select.empty();
            if (!isBlank(d.value)) {
                $.ajax({
                    type: 'post',
                    url: '${ctx}/warehouseSetting/findWarehouseByAscriptionId',
                    async: false,
                    data: {
                        id: d.value
                    },
                    dataType: 'json',
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        for (var i = 0; i < data.length; i++) {
                            html += '<option value="' + data[i].columns.id + '">' + data[i].columns.name + '</option>';
                        }
                        $select.append(html);
                    }
                });
            }
            form.render();
        });

        window.searchOrder = function () {
            render();
        };

        render();

        function render() {
            tableExt.render({
                elem: '#test'
                , height: 'full-220'
                , toolbar: '#toolbarDemo'
                , defaultToolbar: false
                , limits: [20, 50, 100]
                , limit: 20
                , page: true //开启分页
                , url: '${ctx}/material/order/ajaxForSupplyOrder?fixedStatus=5'
                , where: _serializeJson($("#searchForm"))
                , cols: [[
                    {type: 'numbers', fixed: 'left', title: '序号'},
                    {type: 'checkbox', fixed: 'left', title: '选择'},
                    {
                        field: 'id',
                        title: '操作',
                        fixed: 'left',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        templet: function (d) {
                            // var html ="<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"printOrder('" + d.id + "')\">打印</a>";
                            var html = '';
                            if(d.status === '5'&& d.deliver_id === 'a' && ${userType eq '1' || userType eq '4'}){

                                if(fhshBtn && d.send_status === '1'){
                                    return html + "&nbsp;&nbsp;<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"sendToExamine('" + d.id + "')\">审核</a>";
                                }else if(fhBtn &&(d.send_status === '0' || d.send_status === '3')){
                                     html += "&nbsp;&nbsp;<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"deliver('" + d.id + "')\">发货</a>"+
                                    "&nbsp;&nbsp;<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"reject('" + d.id + "')\">驳回</a>";
                                    return html;
                                }else{
                                    return '- -';
                                }
                            }else
                            if (fhBtn && d.status === '5' && (d.deliver_id !== 'a' && ${userType eq '8'})) {
                                return html + "&nbsp;&nbsp;<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"deliver('" + d.id + "')\">发货</a>";
                            }

                            return '- -';
                        }
                    }
                    , {
                        field: 'number',
                        title: '订单编号',
                        minWidth: 230,
                        align: 'center',
                        fixed: 'left',
                        exportable: true,
                        templet: function (d) {
                            var ht='';
                            <%--if(1== d.dayCount){--%>
                            <%--    ht+="<img src='${ctxPlugin}/static/imgs/24.png'>";--%>
                            <%--}else if(2== d.dayCount){--%>
                            <%--    ht+="<img src='${ctxPlugin}/static/imgs/48.png'>";--%>
                            <%--}else if(3== d.dayCount){--%>
                            <%--    ht+="<img src='${ctxPlugin}/static/imgs/24.png'>";--%>
                            <%--}else if(4== d.dayCount){--%>
                            <%--    ht+="<img src='${ctxPlugin}/static/imgs/4.png'>";--%>
                            <%--}else if(5== d.dayCount){--%>
                            <%--    ht+="<img src='${ctxPlugin}/static/imgs/5.png'>";--%>
                            <%--}--%>
                            ht+= "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"orderDetail('" + d.id + "')\">" + d.number + "</a>";

                            return  ht;
                        }
                    }
                    // , {
                    //     field: 'supply_name', title: '供应商名称', minWidth: 150, align: 'center', exportable: true
                    // }
                    // , {
                    //     field: 'id',
                    //     title: '物料清单',
                    //     align: 'center',
                    //     minWidth: 150,
                    //     templet: function (d) {
                    //         return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"materialDetail('" + d.id + "')\">查看</a>&nbsp;&nbsp;";
                    //     }
                    // }
                    , {field: 'inWarehouseName', title: '入库仓库', minWidth: 150, align: 'center', exportable: true}
                    , {
                        field: 'allocation_time',
                        title: '分配时间',
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    // , {
                    //     field: 'allocation_remark',
                    //     title: '分配说明',
                    //     align: 'center',
                    //     exportable: true,
                    //     minWidth: 200
                    // }
                    , {
                        field: 'type', title: '订单来源', minWidth: 120, align: 'center', exportable: true
                        , templet: function (d) {
                            if (d.type === '1') {
                                return '电站下单';
                            } else if (d.type === '2') {
                                return '物料储备';
                            } else if (d.type === '3') {
                                return '平台采购';
                            } else if (d.type === '4') {
                                return '合并发货';
                            }else if (d.type === '5') {
                                return '材料下单';
                            }
                        }
                        , expFormat: function (d) {
                            if (d.type === '1') {
                                return '电站下单';
                            } else if (d.type === '2') {
                                return '物料储备';
                            } else if (d.type === '3') {
                                return '平台采购';
                            } else if (d.type === '4') {
                                return '合并发货';
                            }else if (d.type === '5') {
                                return '材料下单';
                            }
                        }
                    }
                    // , {
                    //     field: 'pattern', title: '订单类型', minWidth: 120, align: 'center', exportable: true
                    //     , templet: function (d) {
                    //         if (d.pattern === '1') {
                    //             return '平台采购';
                    //         } else if (d.pattern === '2') {
                    //             return '供应商直发';
                    //         } else if (d.pattern === '3') {
                    //             return '平台发货';
                    //         } else {
                    //             return '';
                    //         }
                    //     }
                    //     , expFormat: function (d) {
                    //         if (d.pattern === '1') {
                    //             return '平台采购';
                    //         } else if (d.pattern === '2') {
                    //             return '供应商直发';
                    //         } else if (d.pattern === '3') {
                    //             return '平台发货';
                    //         } else {
                    //             return '';
                    //         }
                    //     }
                    // }
                    , {
                        field: 'outWarehouseName',
                        title: '发货仓库',
                        minWidth: 150,
                        align: 'center',
                        exportable: true
                    }

                    , {
                        field: 'applyOrderTrader',
                        title: '代理商名称',
                        minWidth: 150,
                        align: 'center',
                        exportable: true
                    }


                    <c:if test="${ascriptionId ne 'a'}">
                    , {
                        field: 'place_name',
                        title: '下单人',
                        align: 'center',
                        exportable: true,
                        minWidth: 150
                    }
                    </c:if>

                    // , {
                    //     field: 'deliver_method_name',
                    //     title: '发货方式',
                    //     minWidth: 150,
                    //     sort: false,
                    //     align: 'center'
                    // }
                    , {
                        field: 'person_in_charge',
                        title: '接货人',
                        minWidth: 150,
                        align: 'center'
                    }
                    , {
                        field: 'mobile',
                        title: '联系方式',
                        minWidth: 150,
                        align: 'center'
                    }
                    , {
                        field: 'receive_address',
                        title: '收货地址',
                        minWidth: 150,
                        align: 'center'
                        , templet: function (d) {
                            if (d.pattern === '1') {
                                return d.w_address;
                            } else {
                                return d.receive_address;
                            }
                        }
                    }
                    , {
                        field: 'place_time',
                        title: '下单时间',
                        minWidth: 200,
                        align: 'center'/*,
                        templet: function (d) {
                            return "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"applyOrderDetail('" + d.applyOrderId + "')\">" + d.applyOrderNumber + "</a>";
                        }*/
                    }
                    , {
                        field: 'remarks',
                        title: '订单备注',
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }


                ]]
                , exportOpt: {                           //导出选项配置
                    ele: '#exportBtn',                   //导出的Dom元素
                    headerTitle: '收货单',             //excel表格的标题
                    pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                    maxAmount: 5000,                    //当pageData为false生效
                    fileName: '收货单',
                    where: function () {                 //当pageData为false时生效，过滤的条件
                        return _serializeJson($("#searchForm"));
                    }
                }
            });
        }


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


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === 'refuse') {
                if (data.length < 1) {
                    layer.msg("请至少选择一条数据", {icon: 5, anim: 6});
                    return;
                }
                var orderId = "";
                for (var i = 0; i < data.length; i++) {
                    orderId += data[i].id + ",";
                }
                $('#reason').val('');
                layer.open({
                    type: 1,
                    area: ['450px', '280px'],
                    content: $("#refuseDiv"),
                    title: '提示',
                    btn: ['确认', '取消'],
                    btnAlign: 'c',
                    yes: function () {
                        var reason = $('#reason').val();
                        if (isBlank(reason)) {
                            layer.msg("请输入拒发货原因");
                        } else {
                            $.ajax({
                                type: 'post',
                                url: '${ctx}/material/order/deliverRejectBatch',
                                contentType: 'application/json',
                                dataType: 'json',
                                data: JSON.stringify({
                                    id: orderId,
                                    reason: reason
                                }),
                                success: function (result) {
                                    if (result.code === '200') {
                                        layer.msg('操作成功！', {time: 1000}, function(){
                                            layer.closeAll();
                                            $('.layui-laypage-btn').click();
                                        })
                                    } else {
                                        layer.msg('保存失败!'+result.errMsg)
                                    }
                                }
                            });
                        }
                    }
                })
            }
        });

        //监听行单击事件
        table.on('row(test)', function (obj) {
            var data = obj.data;
            var oldData = table.cache["test"];
            var checkCell = obj.tr.find(".layui-form-checkbox");
            var CHECKED;

        });
        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });


        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });

    });

    function inStock(id) {
        layer.open({
            title: '收货',
            type: 2,
            area: ['80%', '80%'],
            fixed: false,
            content: '${ctx}/material/order/toInStock?id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }

    function orderDetail(deliverOrderId) {
        // var id = applyOrderId;
        // var type = 1;
        // if(!isBlank(deliverOrderId) && deliverOrderId !== 'null'){
        //     id = deliverOrderId;
        //     type = 2;
        // }
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '80%'],
            content: '${ctx}/material/order/toDeliverPage?opt=view&id=' + deliverOrderId,
            <%--content: '${ctx}/material/order/mergeOrderDetail?id=' + id + '&type=' + type--%>
        });
    }

    function applyOrderDetail(id) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/apply/materialDetail?applyId=' + id
        });
    }

    function deliver(id) {
        layer.open({
            title: '发货',
            type: 2,
            area: ['80%', '80%'],
            fixed: false,
            content: '${ctx}/material/order/toDeliverForm?opt=fh&id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }

    function reject(id) {
        $('#rejectReason').val('');
        var indexla = layer.open({
            type: 1,
            area: ['450px', '280px'],
            content: $("#auditDiv"),
            title: '提示',
            btn: ['确认', '取消'],
            btnAlign: 'c',
            yes: function () {
                var reason = $('#rejectReason').val();
                $.ajax({
                    type: 'post',
                    url: '${ctx}/material/order/deliverReject',
                    contentType: 'application/json',
                    dataType: 'json',
                    data: JSON.stringify({
                        id: id,
                        reason: reason
                    }),
                    success: function (result) {
                        if (result.code === '200') {
                            layer.msg('操作成功！', {time: 1000}, function(){
                                searchOrder();
                                layer.close(indexla);
                            })
                        } else {
                            layer.msg('保存失败!'+result.errMsg)
                            layer.close(indexla);
                        }
                    }
                });

            }
        })

        <%--var indexla = layer.confirm('您确定要驳回该订单吗？', {--%>
        <%--    icon: 3,--%>
        <%--    btn: ['确定', '取消'] //按钮--%>
        <%--}, function () {--%>
        <%--    $.ajax({--%>
        <%--        type: "GET",--%>
        <%--        url: "${ctx}/material/order/reject?id="+id,--%>
        <%--        success: function (result) {--%>
        <%--            if (result.code == '200') {--%>
        <%--                layer.msg('修改成功！', {icon: 1, time: 1000}, function () {--%>
        <%--                    searchOrder();--%>
        <%--                });--%>
        <%--            } else {--%>
        <%--                console.log(result)--%>
        <%--                layer.msg('操作失败!', {icon: 2});--%>
        <%--            }--%>
        <%--        },--%>
        <%--        error: {}--%>
        <%--    })--%>
        <%--}, function () {--%>
        <%--    layer.close(indexla);--%>
        <%--});--%>
    }

    function sendToExamine(id){
        layer.open({
            title: '发货审核',
            type: 2,
            area: ['80%', '80%'],
            fixed: false,
            content: '${ctx}/material/order/sendToExamine?opt=fh&id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }

    function refuse(id) {
        var indexla = layer.confirm('您确定要拒发货该订单吗？', {
            icon: 3,
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                url: "${ctx}/material/order/refuse",
                data: {
                    id: id
                },
                success: function (result) {
                    if (result.code == '200') {
                        layer.msg('操作成功！', {icon: 1, time: 1000}, function () {
                            searchOrder();
                        });
                    } else {
                        console.log(result)
                        layer.msg('操作失败!', {icon: 2});
                    }
                },
                error: {}
            })
        }, function () {
            layer.close(indexla);
        });
    }

    function printOrder(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']];
            }
        })
    }

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

    function materialDetail(id) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/order/orderMaterialList?id=' + id
        });
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>

