<!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">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
    <style type="text/css">
        .seach_items {
            display: inline-block;
            margin-right: 5px;
            margin-top: 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;">
                        <div style="float:left; margin-right: 5px; margin-top: 5px;">
                            <button class="layui-btn" id="btn_add"  data-permission="order.add_coupon">
                                <i class="layui-icon layui-icon-add-circle"></i>添加
                            </button>
                        </div>

                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>

                    <script type="text/html" id="datagrid-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="edit"  data-permission="order.add_coupon"
                               >修改</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , formSelects: 'formSelects-v4'
    }).use(['index', 'table', 'form', 'formSelects'], function () {
        var $ = layui.$
            , table = layui.table
            , form = layui.form;
        table.render({
            elem: '#datagrid'
            , url: '/order/coupon/'
            , cols: [[
                {field: 'name', title: '优惠券名称', width: 200}
                , {field: 'amount', title: '优惠券金额', width: 100}
                , {field: 'category_text', title: '使用分类', width: 260}
                , {field: 'school_text', title: '使用学校', width: 260}
                , {field: 'begin_date', title: '开始时间', width: 120}
                , {field: 'end_date', title: '结束时间', width: 120}
                , {field: 'count', title: '已用数量', width: 100}
                , {field: 'enable_text', title: '是否在用', width: 100}
                , {field: 'create_time', title: '添加时间', width: 150}
                , {field: 'create_user_text', title: '添加人', width: 100}
                , {width: 100, align: 'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
        });
        var _params;
        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;
        });
        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                table.editdata = data;
                layer.open({
                    type: 2,
                    title: '修改优惠券',
                    shadeClose: false,
                    area: ['50%', '90%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (res) {
                            layer.close(index);
                            table.reload('datagrid', {});
                        };
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'coupon_edit.html?id=' + data.id
                });
            }
        });

        $('#btn_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加优惠券',
                shadeClose: false,
                area: ['40%', '90%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (res) {
                        layer.close(index);
                        table.reload('datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'coupon_edit.html'
            });
        });
    });
</script>
</body>
</html>

