{extend name="public/container"}
{block name="content"}
<div class="layui-fluid" style="background: #fff;margin-top: -10px;">

    <div class="layui-row layui-col-space15" id="app">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">门店：</label>
                                <div class="layui-input-inline">
                                    <select name="store_id" lay-verify="store">
                                        <option value="0">全部</option>
                                        {volist name="store" id="v"}
                                        <option value="{$v.id}">{$v.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">状态：</label>
                                <div class="layui-input-inline">
                                    <select name="status" lay-verify="status">
                                        <option value="-2">全部</option>
                                        <option value="0">待审核</option>
                                        <option value="1">通过</option>
                                        <option value="-1">拒绝</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">商品条型码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="key" class="layui-input" placeholder="条型码">

                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search"
                                            lay-filter="search">
                                        <i class="layui-icon layui-icon-search"></i>搜索
                                    </button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
        <div class="layui-btn-group conrelTable">
            <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_group"><i
                        class="fa fa-check-circle-o"></i>批量审核
            </button>
        </div>
        <!--商品列表-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <table class="layui-hide" id="List" lay-filter="List"></table>
                    <!--图片-->
                    <script type="text/html" id="image">
                        <img style="cursor: pointer" lay-event="open_image" src="{{d.image}}">
                    </script>
                    <!--商品名称-->
                    <script type="text/html" id="store_name">
                        <h4>{{d.store_name}}</h4>
                        <p>价格:<font color="red">{{d.price}}</font></p>
                    </script>

                    <script type="text/html" id="status">
                        <h4>{{d.status}}</h4>
                        {{# if(d.status != '已通过'){ }}
                        <p>拒绝原因:{{d.refuse_msg}}</font></p>
                        {{# } }}
                    </script>
                    <script type="text/html" id="in_stock">
                        {{# if(d.type == 1){ }}
                        <b style="color: #00aa00">+{{d.in_stock}}</b>
                        {{# }else{ }}
                        <b style="color: #aa0000">-{{d.in_stock}}</b>
                        {{# } }}
                    </script>
                    <!--操作-->
                    <script type="text/html" id="act">
                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
                                    class="caret"></span></button>
                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
                            <li>
                                <a href="javascript:void(0);" lay-event='auth'>
                                    <i class="fa fa-trash"></i> 审核
                                </a>
                            </li>
                        </ul>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="{__ADMIN_PATH}js/layuiList.js"></script>
<script>

    //实例化form
    layList.form.render();
    //加载列表
    layList.tableList('List', "{:Url('bill_lst')}", function () {
        var join = new Array();
        join = [
            {type: 'checkbox'},
            {field: 'id', title: 'ID', sort: true, event: 'id', width: '6%'},
            {field: 'store', title: '门店', width: '10%'},
            {field: 'image', title: '商品图片', templet: '#image', width: '10%'},
            {field: 'store_name', title: '商品名称', templet: '#store_name', width: '15%'},
            {field: 'in_stock', title: '入库', width: '8%', templet: '#in_stock'},
            {field: 'add_time', title: '入库时间', width: '8%'},
            {field: 'status', title: '状态', templet: "#status", width: '8%'},
            {field: 'info', title: '增减缘由'},
            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
        ];

        return join;
    })


    //下拉框
    $(document).click(function (e) {
        $('.layui-nav-child').hide();
    })

    function dropdown(that) {
        var oEvent = arguments.callee.caller.arguments[0] || event;
        oEvent.stopPropagation();
        var offset = $(that).offset();
        var top = offset.top - $(window).scrollTop();
        var index = $(that).parents('tr').data('index');
        $('.layui-nav-child').each(function (key) {
            if (key != index) {
                $(this).hide();
            }
        })
        if ($(document).height() < top + $(that).next('ul').height()) {
            $(that).next('ul').css({
                'padding': 10,
                'top': -($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height() / 2),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        } else {
            $(that).next('ul').css({
                'padding': 10,
                'top': $(that).parent('td').height() / 2 + $(that).height(),
                'min-width': 'inherit',
                'position': 'absolute'
            }).toggle();
        }
    }

    //快速编辑
    layList.edit(function (obj) {
        var id = obj.data.id, value = obj.value;
        switch (obj.field) {
            case 'price':
                action.set_product('price', id, value);
                break;
            case 'stock':
                action.set_product('stock', id, value);
                break;
            case 'sort':
                action.set_product('sort', id, value);
                break;
            case 'ficti':
                action.set_product('ficti', id, value);
                break;
        }
    });
    //上下加商品
    layList.switch('is_show', function (odj, value) {
        if (odj.elem.checked == true) {
            layList.baseGet(layList.Url({
                c: 'store.store_product',
                a: 'set_show',
                p: {is_show: 1, id: value}
            }), function (res) {
                layList.msg(res.msg, function () {
                    layList.reload();
                });
            });
        } else {
            layList.baseGet(layList.Url({
                c: 'store.store_product',
                a: 'set_show',
                p: {is_show: 0, id: value}
            }), function (res) {
                layList.msg(res.msg, function () {
                    layList.reload();
                });
            });
        }
    });
    //点击事件绑定
    layList.tool(function (event, data, obj) {
        switch (event) {

            case 'auth':
                $eb.createModalFrame('编辑', layList.Url({a: 'audit', p: {id: data.id}}));
                break;

        }
    })
    //排序
    layList.sort(function (obj) {
        var type = obj.type;
        switch (obj.field) {
            case 'id':
                layList.reload({order: layList.order(type, 'id')}, true, null, obj);
                break;
            case 'sales':
                layList.reload({order: layList.order(type, 'sales')}, true, null, obj);
                break;
        }
    });
    //查询
    layList.search('search', function (where) {
        layList.reload(where, true);
    });
    //自定义方法
    var action = {
        set_product: function (field, id, value) {
            layList.baseGet(layList.Url({
                c: 'store.store_product',
                a: 'set_product',
                q: {field: field, id: id, value: value}
            }), function (res) {
                layList.msg(res.msg);
            });
        },
        show: function () {
            var ids = layList.getCheckData().getIds('id');
            if (ids.length) {
                layList.basePost(layList.Url({
                    c: 'store.store_product',
                    a: 'product_show'
                }), {ids: ids}, function (res) {
                    layList.msg(res.msg);
                    layList.reload();
                });
            } else {
                layList.msg('请选择要上架的商品');
            }
        },
        "set_group": function () {
            var ids = layList.getCheckData().getIds('id');
            if (ids.length) {
                var str = ids.join(',');
                $eb.createModalFrame('批量设置分组', layList.Url({a: 'batch_audit', p: {id: str}}), {w: 500, h: 300});
            } else {
                layList.msg('请选择要批量设置分组的会员');
            }
        }
    };
    //多选事件绑定
    $('.layui-btn-container').find('button').each(function () {
        var type = $(this).data('type');
        $(this).on('click', function () {
            action[type] && action[type]();
        })
    });
    $('.conrelTable').find('button').each(function () {
        var type = $(this).data('type');
        $(this).on('click', function () {
            action[type] && action[type]();
        })
    })

</script>
{/block}
