<!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=agent-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">
        .seach_items {
            float: right;
            margin-left: 10px;
        }
    </style>
    <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: 40px;
        }

        .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;
        }

        .tableContent {
            width: 100%;
            display: flex;
            justify-content: space-between;
            flex-direction: row;
        }

        .layui-table-cell {
            padding: 0 5px;
        }
    </style>

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <!--商品-->
                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <form class="layui-form" lay-filter="query-form-element">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element"><i class="layui-icon layui-icon-search"></i>查询
                                </button>
                            </div>
                            <div class="seach_items" style="width: 150px;">
                                <select name="type">
                                    <option value="">请选择价格类型</option>
                                    <option value="1">现金商品</option>
                                    <option value="2">积分商品</option>
                                </select>
                            </div>
                            <div class="seach_items" style="width: 150px">
                                <select name="category" id="select_category">
                                    <option value="">请选择商品类别</option>
                                </select>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="名称"/>
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="commodity_datagrid" lay-filter="commodity-operate"></table>

                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', ], function () {
        var $ = layui.$;
        var table = layui.table
            , form = layui.form
            , admin = layui.admin;

        admin.req({
            url: '/commodity/dict/',
            done: function (res) {
                var data = res.data.category;
                var category = $('#select_category');
                for (var i in data) {
                    var pid1 = data[i].value;
                    var name1 = data[i].name;
                    category.append("<option value='" + pid1 + "'>" + name1 + "</option>");
                }
                form.render();
            }
        });

        table.render({
            elem: '#commodity_datagrid'
            , url: '/commodity/'
            , cols: [[
                {type:'radio'}
                , {field: 'name', title: '商品名称', width: 200}
                , {field: 'category_text', title: '商品类别', width: 100}
                , {field: 'type_text', title: '价格类型', width: 100}
                , {field: 'price', title: '销售价格', width: 120}
                , {field: 'vip_price', title: '会员价格', width: 120}
                , {field: 'point_price', title: '积分价格', width: 120}
                , {field: 'status_text', title: '状态', width: 120}
            ]]
            , page: true
            , height: 'full-108'
            , done: function () {
                layui.index.removeNoPermButtons();
            }
        });

        form.on('submit(query-form-element)', function (data) {
            table.reload('commodity_datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false
        });
        
        parent.layui.submitChild = function () {
            var checkStatus = table.checkStatus('commodity_datagrid');
            var commodity_id = '';
            if (checkStatus.data.length === 1) {
                 commodity_id = checkStatus.data[0].id;
            }
            admin.req({
                url: '/config/set_commodity/'
                ,data: {'commodity_id': commodity_id}
                ,type: 'post'
                ,done: function(res){
                    parent.layui.onSubmitChild(res.data);
                }
              });
            return false;

        }
        
    });

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