<%@ 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/inStockOrderList">
                    <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="inAscriptionId" value="${inAscriptionId}"/>
            <input type="hidden" name="statusList" value="2,5,6,7"/>
            <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="2">待收货</option>
                            <option value="5">待入账</option>
                            <option value="6">入账驳回</option>
                            <option value="7">已完成</option>
                        </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="deliverName" 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="inWarehouseId" 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">
                        <input type="text" name="applyOrderRemarks" 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-lg2 layui-col-sm3">
                    <label class="layui-form-label">下单人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="creator" 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="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-lg4 layui-col-sm6">
                    <label class="layui-form-label">下单时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="applyOrderCreateTimeMin" class="layui-input" id="repairTime"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="applyOrderCreateTimeMax" class="layui-input" id="endTime"
                                   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">
                    <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 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="auditPassTimeMin" class="layui-input" id="auditPassTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="auditPassTimeMax" class="layui-input" id="auditPassTimeMax"
                                   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">
    <sfTags:pagePermission authFlag='CKGL_FHDGL_FHDGL_DC_B' html='<button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="export"><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 rkBtn = ${fns:checkPagePermission(request, 'CKGL_RKDGL_RKDGL_RK_B') eq '0'};

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

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

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

        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'
                , where: _serializeJson($("#searchForm"))
                , cols: [[
                    {type: 'numbers', fixed: 'left', title: '序号'},
                    // {type: 'checkbox', fixed: 'left', title: '选择'}
                    {
                        field: 'id', title: '操作', minWidth: 100, sort: false, align: 'center', fixed: 'left', templet: function (d) {
                            if (rkBtn && (d.status === '2' || d.status === '6')) {
                                return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"inStock('" + d.id + "')\">收货</a>&nbsp;&nbsp;";
                            }
                            return '- -';
                        }
                    }
                    , {
                        field: 'number',
                        title: '订单编号',
                        minWidth: 200,
                        sort: false,
                        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: 'status',
                        title: '收货状态',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true,
                        templet: function (d) {
                            return transStatus(d.status);
                        },
                        expFormat: function (d) {
                            return transStatus(d.status);
                        }
                    }
                    , {
                        field: 'deliver_name',
                        title: '发货单位',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true
                    }
                    , {
                        field: 'inWarehouseName',
                        title: '入库仓库',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true
                    }
                    , {
                        field: 'creator',
                        title: '下单人',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 150
                    }
                    , {
                        field: 'id',
                        title: '物料清单',
                        sort: false,
                        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: 'deliver_method_name',
                        title: '发货方式',
                        minWidth: 150,
                        sort: false,
                        align: 'center'
                    }
                    , {
                        field: 'remarks',
                        title: '订单备注',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'deliver_remark',
                        title: '发货备注',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'create_time',
                        title: '下单时间',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'deliver_time',
                        title: '发货时间',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'receive_time',
                        title: '收货时间',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'audit_time',
                        title: '入账时间',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200,
                        templet: function (d) {
                            if (d.status === '7') {
                                return d.audit_time;
                            }
                            return '';
                        }
                    }
                ]]
                , 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);
            switch (obj.event) {

            }
        });

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

    });

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

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

