<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" 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" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="DDGL_DSHDD_DSHDD_T"
                                       html='<li class="layui-this"><a href="${ctx}/checkPendingOrder/toCheckPendingOrderPage">待入账订单</a></li>'/>
                <button type="reset" class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" type="reset" onclick="reset()">
                    <i class="layui-icon">&#xe666;</i>重置
                </button>
                <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">
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">业务单号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="code" class="layui-input" id="code" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">收货单位：</label>
                        <div class="layui-input-block">
                            <input type="text" name="receivingUnit" class="layui-input" id="receivingUnit" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="">请选择</option>
                                <option value="1" selected>待审批</option>
                                <option value="2">已审批</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">发货单位：</label>
                        <div class="layui-input-block">
                            <input type="text" name="forwardingUnit" class="layui-input" id="forwardingUnit" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">发货方式：</label>
                        <div class="layui-input-block">
                            <select name="deliverMethodId">
                                <option value="">请选择</option>
                                <option value="0">发货方式一</option>
                                <option value="1">发货方式二</option>
                                <option value="2">发货方式三</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">发货备注：</label>
                        <div class="layui-input-block">
                            <input type="text" name="deliverRemarks" class="layui-input" id="deliverRemarks" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">订单备注：</label>
                        <div class="layui-input-block">
                            <input type="text" name="remarks" class="layui-input" id="remarks" autocomplete="off">
                        </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="placeOrderTimeMin" class="layui-input" id="placeOrderTimeMin"
                                       placeholder="开始日期" value="">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="placeOrderTimeMax" class="layui-input" id="placeOrderTimeMax"
                                       placeholder="结束日期" value="">
                            </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="开始日期" value="">
                            </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="结束日期" value="">
                            </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="submitTimeMin" class="layui-input" id="submitTimeMin"
                                       placeholder="开始日期" value="">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="submitTimeMax" class="layui-input" id="submitTimeMax"
                                       placeholder="结束日期" value="">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <button class="layui-btn layui-btn-sm"  id="exportBtn"><i
            class="layui-icon layui-icon-export"></i>导出
    </button>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>

<script type="text/javascript">
    var saveMark = false;
    //初始数据

    var form;
    var $;
    var table;
    var tableExt;
    var laydate;

    var auditBtn = '${fns:checkPagePermission(request, "DDGL_DSHDD_DSHDD_AUDIT_B")}';
    var details = '${fns:checkPagePermission(request, "DDGL_DSHDD_DSHDD_VIEW_B")}';
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laypage', 'laydate', 'form'], function () {
        $ = layui.$;
        form = layui.form;
        tableExt = layui.tableExt;
        table = layui.table;
        laydate = layui.laydate;



        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-205'
            , id: 'test'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , url: '${ctx}/checkPendingOrder/ajaxForCheckPendingOrderData'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true

            , method: "post"
            , where: _serializeJson($("#searchForm"))
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers', fixed: 'left'}
                , {field: 'id', title: '操作', fixed: 'left', minWidth: 120, align: 'center'
                    , templet: function (d) {
                        var html = "";
                        if (d.status === '1') {
                            if (auditBtn == '0') {
                                html += '<a href="#" class="layui-table-link" onclick="auditOrder(\''+d.id+'\')">审核</a>&nbsp;';
                            }
                        } else {
                            html += '——';
                        }
                        return html;
                    }
                }
                , {
                    field: 'status', title: '审核状态', minWidth: 120, align: 'center',exportable: true
                    , templet: function (d) {
                        if (d.status === '1') {
                            return '待审核';
                        } else {
                            return '已审核';
                        }
                    }
                    ,
                    expFormat: function (d) {
                        if (d.status === '1') {
                            return '待审核';
                        } else {
                            return '已审核';
                        }
                    }
                }
                , {field: 'warehouse_name', title: '仓库', minWidth: 150, align: 'center',exportable: true}
                , {field: 'code', title: '业务单号', minWidth: 180, align: 'center',exportable: true}
                , {field: 'forwarding_unit', title: '发货单位', minWidth: 150, align: 'center',exportable: true}
                , {field: 'receiving_unit', title: '收货单位', minWidth: 150, align: 'center',exportable: true}
                , {
                    field: 'id', minWidth: 120, title: '物料清单', align: 'center',
                    templet: function (d) {
                        if (details == '0') {
                            return "<a href=\"#\" class=\"layui-table-link\" onclick=\"siteDetail('" + d.order_id + "', '"+d.order_type+"')\">查看</a>";
                        }
                        return "";
                    }
                }
                , {field: 'deliver_method_name', title: '发货方式', minWidth: 150, align: 'center',exportable: true}
                , {field: 'remarks', title: '订单备注', minWidth: 180, align: 'center',exportable: true}
                , {field: 'deliver_remarks', title: '发货备注', minWidth: 180, align: 'center',exportable: true}
                , {field: 'place_order_time', title: '下单时间', minWidth: 180, align: 'center',exportable: true}
                , {field: 'deliver_time', title: '发货时间', minWidth: 180, align: 'center',exportable: true}
                , {field: 'submit_time', minWidth: 180, title: '入库时间', align: 'center' ,exportable: true}
            ]
            ]
            , exportOpt: {                           //导出选项配置
                ele: '#exportBtn',                   //导出的Dom元素
                headerTitle: '供应链仓下单',             //excel表格的标题
                pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '供应链仓下单',
                where: function () {                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

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

        //发货开始日期
        var deliverTimeMin = laydate.render({
            elem: '#deliverTimeMin'
            ,type: 'date'
            ,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: 'date'
            ,done: function(value, date){
                //更新开始日期的最大日期
                deliverTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

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


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


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

        //重置
        form.on('submit(resetButton)', function (data) {
            $("#searchForm")[0].reset();
            layui.form.render();

        });

        window.showImg = function (src){
            layer.photos({ photos: {"data": [{"src": src}]} });
        }
    });

    function auditOrder(id) {
        layer.open({
            type: 2,
            title: '审核',
            content: '${ctx}/checkPendingOrder/toAuditForm?id='+id,
            area: ['50%', '65%']
        });
    }



    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    /*bom详情*/
    function siteDetail(id, orderType) {
        var url = '';
        if (orderType === '1') {
            url = '${ctx}/inventory/toInventoryOrderDetailForm?mode=view&id=' + id;
        } else if (orderType === '2') {
            url = '${ctx}/allocation/allocationMaterialList?id=' + id;
        } else if (orderType === '3') {
            url = '${ctx}/material/order/materialList?id=' + id;
        }
        layer.open({
            type: 2,
            title: '查看',
            content: url,
            area: ['80%', '80%']
        });
    }

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