<%@ 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/purchaseWaitInStock">
                    <li class="layui-this">待入库</li>
                </a>
                <a href="${ctx}/material/order/purchaseWaitInStockEnd">
                    <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">
            <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">
                        <input type="text" name="traderId" 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="ckName" lay-search>
                            <option value="">请选择</option>
                            <c:forEach items="${warehouses}" var="warehouse">
                                <option value="${warehouse.columns.name}">${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">
                        <input type="text" name="applyOrderRemarks" 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>
        </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>
<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出</button>
</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
                });
            }
        });


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

        render();
        //监听搜索
        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 render() {
            tableExt.render({
                elem: '#test'
                , height: 'full-220'
                , toolbar: '#toolbarDemo'
                , defaultToolbar: false
                , limits: [20, 50, 100]
                , limit: 20
                , method: "post"
                , page: true //开启分页
                , url: '${ctx}/material/order/queryQqList'
                , where: _serializeJson($("#searchForm"))
                , cols: [[
                    {type: 'numbers', fixed: 'left', title: '序号'},
                    {type: 'checkbox', fixed: 'left', title: '选择'},
                    {
                        field: 'id',
                        title: '操作',
                        fixed: 'left',
                        minWidth: 100,
                        sort: false,
                        align: 'center',
                        templet: function (d) {
                            var html = '';
                                if(d.status === '10' && d.pattern === '平台采购'){
                                    return html = "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"sendInStock('" + d.id + "')\">确认入库</a>";
                                }
                            return '- -';
                    }
                    }, {
                        field: 'number',
                        title: '订单编号',
                        minWidth: 230,
                        align: 'center',
                        fixed: 'left',
                        exportable: true,
                        templet: function (d) {
                            return "<a href=\"#\" class=\"layui-table-link\" style='font-size:14px;' onclick=\"orderDetail('" + d.id + "')\">" + d.number + "</a>";
                        }
                    }
                    , {
                        field: 'gysName', title: '供应商名称', minWidth: 150, align: 'center', exportable: true
                    }
                    , {
                        field: 'type',
                        title: '订单来源',
                        align: 'center',
                        minWidth: 150,
                        exportable: true
                    }
                    , {
                        field: 'pattern',
                        title: '订单类型',
                        align: 'center',
                        minWidth: 150,
                        exportable: true
                    }
                    , {
                        field: 'ckName',
                        title: '入库仓库',
                        align: 'center',
                        minWidth: 150,
                        exportable: true,
                    }, {
                        field: 'address',
                        title: '仓库地址',
                        align: 'center',
                        minWidth: 150,
                        exportable: true,
                    }, {
                        field: 'personInCharge',
                        title: '接收人',
                        align: 'center',
                        minWidth: 150,
                        exportable: true,
                    }, {
                        field: 'mobile',
                        title: '联系电话',
                        align: 'center',
                        minWidth: 150,
                        exportable: true,
                    }, {
                        field: 'createTime',
                        title: '创建时间',
                        align: 'center',
                        minWidth: 150,
                        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"));
                    }
                },done: function(res, curr, count){
                    $('span[data-oneself="oneselfFlag"]').parent().parent().parent().css('background-color', '#E2D5D2');
                }
            });
        }
        //监听行单击事件
        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;

        });
    });



    function orderDetail(id) {
        layer.open({
            title: '详情',
            type: 2,
            area: ['80%', '90%'],
            fixed: false,
            content: '${ctx}/material/order/toDeliverPagea?opt=view&id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }
    function sendInStock(id) {
        layer.open({
            title: '采购入库',
            type: 2,
            area: ['80%', '80%'],
            fixed: false,
            content: '${ctx}/material/order/toInStockForm?id=' + id,
            success: function (layero, index) {
                childWin = window[layero.find('iframe')[0]['name']];
            }
        })
    }


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

