<!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:right;">
                            <form class="layui-form" lay-filter="query-form-element">
                                <div class="seach_items">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           placeholder="姓名"/>
                                </div>
                                <div class="seach_items">
                                    <input type="text" name="tel" autocomplete="off" class="layui-input"
                                           placeholder="电话"/>
                                </div>
                                <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>
                            </form>
                        </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="clear_balance"
                            >清空余额</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="clear_balance" style="display: none">
    <div class="layui-card-body" pad15>
        <form class="layui-form" lay-filter="form-change">
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label"><font color='red' size="4">*</font>清空原因：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="reason"
                               lay-verify="required" placeholder="请输入清空原因">
                    </div>
                </div>
                <div class="layui-form-item" style="text-align:right">
                    <button class="layui-btn" lay-submit id="clear_balance_btn" lay-filter="form-change"
                            style="display: none">保存
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'admin'], function () {
        var $ = layui.$
            , table = layui.table
            , admin = layui.admin
            , form = layui.form;

        table.render({
            elem: '#datagrid'
            , url: '/option/balance/'
            , cols: [[
                {field: 'create_user_text', title: '电话', width: 120}
                , {field: 'date_joined_f', title: '注册时间', width: 150}
                , {field: 'balance', title: '余额', width: 150}
                , {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;
        });
        form.on('submit(form-change)', function (data) {
            admin.req({
                url: '/option/balance/clear_balance/?create_user=' + create_user
                , data: data.field
                , type: 'post'
                , done: function (res) {
                    layer.closeAll();
                    table.reload('datagrid', {});
                }
            });
            return false;
        });
        var create_user = ''
        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'clear_balance') {
                if (parseFloat(data.balance) <= 0) {
                    layer.msg("余额为0，不能清空！", {icon: 2});
                    return false
                }
                create_user = data.create_user
                layer.open({
                    type: 1,
                    title: '清空余额',
                    area: ['40%', '40%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        $('#clear_balance_btn').click();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: $('#clear_balance')
                });
            }
        });

        $('#btn_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: false,
                area: ['550px', '80%'],
                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: 'edit.html'
            });
        });
    });
</script>
</body>
</html>

