<%@ 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/waitReceiveOrder">
                    <li class="">待签收</li>
                </a>
                <a href="${ctx}/material/order/completedOrder">
                    <li class="layui-this">已签收</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">
            <!-- 供应链能看到所有数据 -->

            <input type="hidden" name="traderId" value="${applyTraderId}"/>

            <c:if test="${ascriptionId ne 'a' && userType eq '8'}">
                <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">
                    <label class="layui-form-label">订单状态：</label>
                    <div class="layui-input-block">
                        <select name="status">
                            <option value="">请选择</option>
                            <option value="1">待审批</option>
                            <option value="2">采购分配</option>
                            <option value="3">分配打回</option>
                            <option value="4">采购审批</option>
                            <option value="5">待发货</option>
                            <option value="6">待签收</option>
                            <option value="7">已完成</option>
                            <option value="8">已并单</option>
                            <option value="9">发货打回</option>
                        </select>
                    </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">
                            <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">--%>
<%--                            <option value="">请选择</option>--%>
<%--                            <option value="1">平台采购</option>--%>
<%--                            <option value="2">供应商直发</option>--%>
<%--                            <option value="3">平台发货</option>--%>
<%--                        </select>--%>
<%--                    </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="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 class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">发货方式：</label>
                    <div class="layui-input-block">
                        <select name="deliverMethodId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${deliverMethods}" var="method">
                                <option value="${method.columns.id}">${method.columns.name}</option>
                            </c:forEach>
                        </select>
                    </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="expressNo" class="layui-input">
                    </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">
                        <div id="supplierId"></div>
                    </div>
                </div>

                <c:if test="${userType eq '1' || userType eq  '4'}">
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">代理商名称：</label>
                        <div class="layui-input-block">
                            <div id="traderId"></div>
                        </div>
                    </div>
                </c:if>


                <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">
                    <label class="layui-form-label">发货说明：</label>
                    <div class="layui-input-block">
                        <input type="text" name="deliverRemark" class="layui-input">
                    </div>
                </div>


                <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-sm6 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">
                    <label class="layui-form-label">分配完成时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="allocationTimeMin" class="layui-input" id="allocationTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="allocationTimeMax" class="layui-input" id="allocationTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <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="deliverTimeMin" class="layui-input" id="deliverTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="deliverTimeMax" class="layui-input" id="deliverTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm6 ${ascriptionId eq 'a' ? '' : 'layui-hide'}">
                    <label class="layui-form-label">签收时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="receiveTimeMin" class="layui-input" id="receiveTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="receiveTimeMax" class="layui-input" id="receiveTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </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="ideaDiv">
    <label class="layui-form-label"><span class="red">*</span>撤销原因：</label>
    <div class="layui-input-block ">
        <textarea id="idea" class="idea-text f-l layui-textarea"></textarea>
    </div>
</div>

<script type="text/html" id="toolbarDemo">


    <%--    <c:if test="${ascriptionId eq 'a'}">--%>
    <%--        <sfTags:pagePermission authFlag="JXSDDGL_DDCX_DDCX_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>--%>
    <%--        <button class="layui-btn layui-btn-sm" lay-event="export"><i class="layui-icon layui-icon-export"></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 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
                });
            }
        });
        // 分配完成时间
        var allocationTimeMin = laydate.render({
            elem: '#allocationTimeMin'
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                allocationTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                allocationTimeMax.config.elem[0].focus();
            }
        });
        // 分配完成时间
        var allocationTimeMax = laydate.render({
            elem: '#allocationTimeMax'
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                allocationTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        // 发货时间
        var deliverTimeMin = laydate.render({
            elem: '#deliverTimeMin'
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                deliverTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                deliverTimeMax.config.elem[0].focus();
            }
        });
        // 发货时间
        var deliverTimeMax = laydate.render({
            elem: '#deliverTimeMax'
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                deliverTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

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

        <c:if test="${userType eq '1' || userType eq  '4'}">
        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(","));
        </c:if>


        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(","));

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


        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-280'
                , toolbar: '#toolbarDemo'
                , defaultToolbar: false
                , limits: [20, 50, 100]
                , limit: 20
                , page: true //开启分页
                , url: '${ctx}/material/order/ajaxForCompletedOrderData'
                , where: _serializeJson($("#searchForm"))
                , cols: [[
                    {type: 'numbers', fixed: 'left', title: '序号'}
                    , {type: 'checkbox', fixed: 'left', title: '选择'}
                    <c:if test="${userType ne '8'}">
                    , {field: 'id', title: '操作', fixed: 'left', minWidth: 100, align: 'center',
                        templet: function (d) {
                            var html = "——";
                            if (('${userType}' === '1' || '${userType}' === '4') && d.pattern === '1') {
                                var html = "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"orderReturn('" + d.id + "')\">退货</a>";
                            }
                            if( d.status==='11'){
                                var html = "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"inStock('" + d.id + "')\">重签</a>";
                            }
                            return html;
                        }
                    }
                    </c:if>
                    , {field: 'number', title: '订单编号', minWidth: 200, align: 'center', fixed: 'left', exportable: true,
                        templet: function (d) {
                            var html = "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"orderDetail('" + d.id + "')\">" + d.number + "</a>";
                            var lessAmountstr = '';
                            if (!isBlank(d.total_in_amount) && parseFloat(d.total_in_amount) != parseFloat(d.total_deliver_amount)) {
                                lessAmountstr = '<span data-oneself = "lessAmountFlag"></span>';
                            }
                            return lessAmountstr + html;
                        }
                    }


                    , {field: 'supply_name', title: '供应商名称', minWidth: 150, align: 'center', exportable: true}

                    // , {field: 'applyOrderId', title: '物料清单', align: 'center', minWidth: 150,
                    //     templet: function (d) {
                    //         // if(isBlank(d.deliverOrderId)){
                    //         //     return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"applyMaterialDetail('" + d.id + "')\">查看</a>";
                    //         // }
                    //         return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"deliverMaterialDetail('" + d.id + "')\">查看</a>";
                    //     }
                    // }
                    , {field: 'deliver_method_name', title: '发货方式', minWidth: 150, align: 'center', exportable: true}

                    , {field: 'outWarehouseName', title: '发货仓库', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'express_no', title: '物流单号', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'status', title: '签收状态', minWidth: 150, align: 'center', exportable: true,
                        templet: function (d) {
                            return modifyStatus(d.status);
                        }
                        }
                    , {field: 'deliver_driver', title: '司机', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'deliver_mobile', title: '联系方式', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'deliver_car_num', 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: 'applyOrderTrader', title: '代理商名称', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'inWarehouseName', title: '入库仓库', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'person_in_charge', title: '接货人', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'mobile', title: '联系方式', minWidth: 150, align: 'center', exportable: true}
                    , {field: 'address', title: '仓库地址', minWidth: 150, align: 'center', exportable: true,
                        templet: function (d) {
                            if (isBlank(d.address)) {
                                return d.w_address;
                            }
                            return d.address;
                        }
                    }
                    , {field: 'status', title: '订单状态', minWidth: 150, align: 'center', exportable: true,
                        templet: function (d) {
                            return transDeliverStatus(d.status);
                        },
                        expFormat: function (d) {
                            return transDeliverStatus(d.status);
                        }
                    }
                    , {field: 'type', title: '订单来源', minWidth: 200, 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: 'place_time', title: '下单时间', align: 'center', exportable: true, minWidth: 200}
                    , {field: 'remarks', title: '订单备注', align: 'center', exportable: true, minWidth: 200}
                    , {field: 'deliver_time', title: '发货时间', align: 'center', exportable: true, minWidth: 200}
                    , {field: 'deliver_remark', title: '发货说明', align: 'center', exportable: true, minWidth: 200}
                    , {field: 'receive_time', 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"));
                    }
                },done: function(res, curr, count){
                    $('span[data-oneself="lessAmountFlag"]').parent().parent().parent().css('background-color', '#E2D5D2');
                }
            });
        }


        function transStatus(mergeStatus) {
            if (mergeStatus.indexOf('apply') !== -1) {
                return transApplyStatus(mergeStatus.split('-')[1]);
            } else if (mergeStatus.indexOf('deliver') !== -1) {
                return transDeliverStatus(mergeStatus.split('-')[1]);
            }
            return '';
        }

        function transDeliverStatus(status){
            switch (status) {
                case '0':
                    return '已删除';
                case '1':
                    return '待审批';
                case '2':
                    return '采购分配';
                case '3':
                    return '分配打回';
                case '4':
                    return '采购审批';
                case '5':
                    return '待发货';
                case '6':
                    return '待签收';
                case '7':
                    return '已完成';
                case '8':
                    return '已并单';
                case '9':
                    return '发货打回';
                default:
                    return '';
            }
        }

        function modifyStatus(status){
            switch (status) {
                case '7':
                    return '已确认';
                case '11':
                    return '已签收';
                default:
                    return '';
            }
        }

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

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'edit':{
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据", {icon: 5, anim: 6});
                        return;
                    }
                    if (checkStatus.data.length > 1) {
                        layer.msg("只能选择数据一条数据", {icon: 5, anim: 6});
                        return;
                    }
                    if (checkStatus.data[0].mergeStatus !== 'apply-4') {
                        layer.msg('仅审批驳回的订单可以重新下单');
                        return;
                    }
                    layer.open({
                        type: 2,
                        title: "编辑",
                        resize: false,
                        area: ['80%', '70%'],
                        content: '${ctx}/material/apply/addApply?id=' + checkStatus.data[0].applyOrderId
                    });
                    break;
                }
                case 'delete':{
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据", {icon: 5, anim: 6});
                        return;
                    }
                    var ids = [];
                    for (var i = 0; i < checkStatus.data.length; i++) {
                        if (checkStatus.data[i].mergeStatus !== 'apply-4') {
                            layer.msg('仅审批驳回的订单可以删除');
                            return;
                        }
                        ids.push(checkStatus.data[i].applyOrderId);
                    }
                    layer.confirm('确认要删除吗？', {
                        icon: 3,
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            type: 'post',
                            url: '${ctx}/material/apply/deleteApplyOrder',
                            data: {
                                ids: ids.join()
                            },
                            success: function (data) {
                                if (data.code === '200') {
                                    layer.msg('操作成功', {time: 1000});
                                    render();
                                } else if (data.code === '501') {
                                    layer.msg(data.errMsg, {time: 1000});
                                } else {
                                    layer.msg('操作失败', {time: 1000});
                                }
                            }
                        })
                    });
                    break;
                }
                case 'deleteOrder':{
                    if (checkStatus.data.length < 1) {
                        layer.msg("请先选择数据", {icon: 5, anim: 6});
                        return;
                    }
                    if (checkStatus.data.length > 1) {
                        layer.msg("只能选择数据一条数据", {icon: 5, anim: 6});
                        return;
                    }
                    layer.confirm('确认要删除吗？', {
                        icon: 3,
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        console.log(checkStatus.data[0].deliverOrderId)
                        $.ajax({
                            type: 'post',
                            url: '${ctx}/material/order/deleteOrder',
                            data: {
                                orderId: checkStatus.data[0].deliverOrderId
                            },
                            success: function (data) {
                                if (data.code === '200') {
                                    layer.msg('操作成功', {time: 1000});
                                    render();
                                } else if (data.code === '501') {
                                    layer.msg(data.errMsg, {time: 1000});
                                } else {
                                    layer.msg('操作失败', {time: 1000});
                                }
                            }
                        })
                    });
                    break;
                }
                case 'export':{
                    location.href = '${ctx}/material/order/export/exportAllOrder?' + $('#searchForm').serialize();
                    break;
                }
            }
        });

        //监听行单击事件
        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) {

        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '80%'],
            content: '${ctx}/material/order/toDeliverPage?opt=view&id=' + deliverOrderId,
        });
    }

    function deliverOrderDetail(id){
        layer.open({
            title: '详情',
            type: 2,
            area: ['80%', '80%'],
            fixed: false,
            content: '${ctx}/material/order/inStockOrderDetail?id=' + 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 applyMaterialDetail(applyOrderId) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/apply/materialList?id=' + applyOrderId
        });
    }

    //发货单物料清单
    function deliverMaterialDetail(deliverOrderId) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/order/materialList?id=' + deliverOrderId
        });
    }

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

    function orderReturn(id) {
        layer.open({
            title: '退货',
            type: 2,
            area: ['85%', '85%'],
            fixed: false,
            content: '${ctx}/material/return/addReturnOrderFromCompleteOrder?id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }
</script>
</body>
</html>

