<!DOCTYPE html>
<html lang="en">
<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">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style type="text/css">
    .LAY-btns .layui-nav {padding-left:0;padding-right:10px;top:-4px;margin: 0 10px;border: 0;background-color: #009688;}
    .LAY-btns .layui-nav .layui-nav-item{line-height: 30px;}
    .LAY-btns .layui-nav .layui-nav-child{top:34px;}
    .LAY-btns .layui-nav .layui-nav-bar{display: none;}
    .LAY-btns .layui-nav .layui-nav-child dd.layui-this a{color:#333;background-color:#fff;}
    .LAY-btns .layui-nav .layui-nav-child dd.layui-this a:hover {background-color: #f2f2f2;color: #000;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row">

                <div class="LAY-btns" style="margin-bottom: 10px;">
                    <button class="layui-btn layui-btn-sm" id="btn_export" data-permission="purchase.export_consumable_godownentry_query"><i class="layui-icon layui-icon-download-circle"></i>导出</button>

                    <button class="layui-btn layui-btn-sm" id="btn_print" data-permission="purchase.print_consumable_godownentry_query"><i class="layui-icon layui-icon-form"></i>打印</button>
                    <button class="layui-btn layui-btn-sm" id="btn_query"><i class="layui-icon layui-icon-search"></i>查询</button>
                </div>
                <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>
                <script type="text/html" id="datagrid-operate-bar">
                    {{# if(d.is_PY == false){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="return" data-permission="purchase.add_consumable_godown_entry_return">退货</a>
                    {{# } }}
                </script>
            </div>
        </div>
    </div>
</div>
<div id="dlg_query" style="display: none">
    <div class="layui-card-body" pad15>
        <form class="layui-form" lay-filter="query-form-element">
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">审核时间：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="check_time" id="check_time" placeholder=" - " autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">入库类别：</label>
                    <div class="layui-input-block">
                        <select name="entry_type">
                            <option value="">全部</option>
                            <option value="0">直接入库</option>
                            <option value="1">采购入库</option>
                            <option value="2">盘盈入库</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">产品名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_text" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">代码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_model" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">仓别：</label>
                    <div class="layui-input-block">
                        <input type="text" name="warehouse" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">入库单号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="no" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">供应商：</label>
                    <div class="layui-input-block">
                        <input type="text" name="supplier" class="layui-input" autocomplete="off">
                    </div>
                </div>
                 <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">创建人：</label>
                    <div class="layui-input-block">
                        <input type="text" name="create_user" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">产品备注：</label>
                    <div class="layui-input-block">
                        <input type="text" name="notes" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div style="display: none" >
                <button id="query-submit" lay-submit lay-filter="query-form-element">查询</button>
            </div>
        </form>
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    var _params = '';
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        utils: 'utils'
    }).use(['index', 'table', 'laydate', 'form', 'utils'], function () {
        var $ = layui.$;
        var table = layui.table
            , form = layui.form
            , utils = layui.utils
            , laydate = layui.laydate;
        var is_has = utils.isHasPermissions('material.view_consumable_cost');
        var cols = [];
        cols.push({field: 'no', title: '入库单号', width: 160});
        cols.push({field: 'type', title: '入库类别', width: 120});
        cols.push({field: 'supplier', title: '供应商', width: 145});
        cols.push({field: 'product_name', title: '产品', width: 140});
        cols.push({field: 'product_model', title: '代码', width: 100});
        cols.push({field: 'product_unit', title: '单位', width: 100});
        cols.push({field: 'product_type', title: '产品类别', width: 100});
        cols.push({field: 'warehouse', title: '仓别', width: 130});
        if (is_has){
            cols.push({field: 'price', align:'right', title: '入库单价', width: 110});
        }
        cols.push({field: 'count', align:'right', title: '数量', width: 110});
        cols.push({field: 'return_count', align:'right', title: '退货数量', width: 110});
        if (is_has){
            cols.push({field: 'amount', align:'right', title: '合计金额', width: 130});
        }
        cols.push({field: 'deliver_count', align:'right', title: '出库数量', width: 110});
        cols.push({field: 'surplus_count', align:'right', title: '剩余数量', width: 110});
        cols.push({field: 'create_user', title: '创建人', width: 120});
        cols.push({field: 'check_time', title: '审核时间', width: 160});
        cols.push({field: 'warehouse_place', title: '存放库位', width: 150});
        cols.push({field: 'notes', title: '备注', minWidth: 200});
        cols.push({width: 75, align: 'center', fixed: 'right', toolbar: '#datagrid-operate-bar'});
        table.render({
            elem: '#datagrid'
            , url: '/purchase/godownentry_query/data/?type=1'
            , cols: [cols]
            , page: true
            , height: 'full-104'
            , totalRow: true
            ,parseData:function(res) {
                var cols = this.cols[0];
                for (var i in cols) {
                    if (cols[i].field == 'count') {
                        cols[i].totalRowText = res.more.total_count;
                    }
                    if (cols[i].field == 'return_count') {
                        cols[i].totalRowText = res.more.total_return_count;
                    }
                    if (cols[i].field == 'amount') {
                        cols[i].totalRowText = res.more.total_amount;
                    }
                    if (cols[i].field == 'deliver_count') {
                        cols[i].totalRowText = res.more.total_deliver_count;
                    }
                    if (cols[i].field == 'surplus_count') {
                        cols[i].totalRowText = res.more.total_surplus_count;
                    }
                }
                return {
                  "code": res.code, //解析接口状态
                  "count": res.count, //解析数据长度
                  "data": res.data //解析数据列表
                };
            }
            , done: function () {
                layui.index.removeNoPermButtons()
            }
        });
        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'return') {
                layer.open({
                    type: 2,
                    title: '退货',
                    shadeClose: false,
                    area: ['80%', '90%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('datagrid', {});
                        layer.msg('添加退货成功', {icon: 6});
                    };
                    layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'consumable_godownentry_return_edit.html?godownentry_detail_id='+data.godownentry_detail_id
                });
            }
        });
        laydate.render({
            elem: '#entry_time'
            , range: true
        });
        laydate.render({
            elem: '#check_time'
            , range: true
        });

        $('#btn_export').on('click', function () {
            layui.admin.req({
                url: '/purchase/godownentry_query/export/?type=1',
                data: _params,
                done: function (res) {
                    layui.view.download(res.data.filename);
                }
            });
        });

        $('#btn_query').on('click', function () {
            layer.open({
                type: 1,
                shadeClose: true,
                area: ['550px', '540px'],
                title: '查询',
                btn: ['查询'],
                yes: function (index, dom) {
                    $("#query-submit").click();
                },
                content: $('#dlg_query')
            });
        });
        form.on('submit(query-form-element)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            _params = data.field;
            table.reload('datagrid', {
                where: data.field,
                page:{curr:1}
            });
            layer.closeAll();
            return false
        });

        $('#btn_print').on('click', function () {
            layer.open({
                type: 2,
                title: '打印',
                shadeClose: true,
                area: ['90%', '90%'],
                btn: ['打印', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function(data){
                      layer.close(index);
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'consumable_godownentry_query_print.html'
            });
        });


    })
</script>
</body>
</html>
