<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <link rel="stylesheet"
          href="plugins\bootstrap-fileinput\fileinput.min.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">


<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">
        <div id="importExcelDiv"></div>

        <section class="content-header">
            <h1>
                会员管理
                <small>会员信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">管理列表</a></li>
            </ol>
        </section>

        <div id="addlabelModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- dialog body -->
                    <div class="modal-body">
                        <font color="red" style="margin: 10px;">*谨慎操作:生成虚拟会员后，此邀请码对应的预导入名单人员状态自动为报名状态*</font>
                        <input class="form-control select2" style="width: 100%" id="addlabel"
                               placeholder='邀请码'>
                        </input>
                    </div>
                    <div style="text-align: center;padding-bottom: 20px;">
                        <button style="width: 100px;" type="button" class="btn btn-primary" onclick="addlabelsubmit()">
                            确定
                        </button>
                        <button style="width: 100px;" type="button" id="tagCacel" class="btn btn-default">取消</button>
                    </div>
                    <!-- dialog buttons -->
                </div>
            </div>
        </div>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <form id="seachTableForm" action="#springUrl('/a/member/exportExcel')" method="get"
                                  onkeydown="if(event.keyCode==13){return false;}">
                                <div class="col-xs-2">
                                    <input type="text" class="form-control required"
                                           name="phone" placeholder="手机号">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control required"
                                           name="name" placeholder="会员名称">
                                </div>
                                <!--                                <div class="col-xs-2">-->
                                <!--                                    <select name="status" class="form-control">-->
                                <!--                                        <option value="0">请选择会员状态</option>-->
                                <!--                                        <option value="1">会员注册</option>-->
                                <!--                                        <option value="2">虚拟会员</option>-->
                                <!--                                    </select>-->
                                <!--                                </div>-->
                                <div class="col-xs-5">
                                    <a href="javascript:void(0)" class="btn btn-primary search">搜索</a>
                                    #if($shiro.hasPermission("qy:member:edit"))
                                    <!-- <a href="#springUrl('/a/member/form')" class="btn btn-primary">新增</a>-->
                                    #end
                                    <button class="btn btn-primary">导出</button>
                                    <!--                                    <a href="javascript:void(0)" onclick="addMemer()" class="btn btn-primary">添加虚拟会员</a>-->
                                </div>
                            </form>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="table" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <td hidden="true">Id</td>
                                    <th>头像</th>
                                    <th>性别</th>
                                    <!--                                    <th>姓</th>-->
                                    <!--                                    <th>名</th>-->
                                    <th>微信OPENID</th>
                                    <th>联系方式</th>
                                    <th>会员名称</th>
                                    <th>来源</th>
                                    <!--                                    <th>邀请码</th>-->
                                    <!--                                    <th>客户分类</th>-->
                                    <!--                                    <th>名片</th>-->
                                    <th>创建日期</th>
                                </tr>
                                </thead>
                                <tbody id="tablebody">
                                </tbody>

                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->
<!-- jQuery 2.1.4 -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins\bootstrap-fileinput\fileinput.js"></script>
<script src="plugins/bootstrap-fileinput/zh.js"></script>
<script src="plugins/bootstrap-fileinput/zh2.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script type="text/javascript"
        src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script>
    var csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    var csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>
<script src="common/js/tabletok.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="common/js/cfapp.js"></script>
<script>
    function formatDates(now) {
        var date = new Date(now);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    }

    function seachTable() {
        var sSource = "#springUrl('/a/member/listData')";
        var aoData = {
            iDisplayStart: 0,
            iDosplayLength: 10,
            csrf_header: csrfheader,
            csrf_token: csrftoken
        }


        $('#table').DataTable({
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "bFiltered": false,
            "bStateSave": false, // save datatable state(pagination, sort, etc) in cookie.
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": sSource,
            "fnServerData": retrieveData,
            "pagingType": "full_numbers",
            "aoColumns": [
                {
                    "mData": "id"
                },
                {
                    "mData": "imageurl"
                },
                {
                    "mData": "sex"
                },
                {
                    "mData": "openId"
                },
                {
                    "mData": "phone"
                },
                {
                    "mData": "name"
                },
                {
                    "mData": "source"
                },
                {
                    "mData": "createTime"
                }
            ],
            "aoColumnDefs": [
                { // set default column settings
                    'visible': false,
                    'targets': [0]
                },

                {
                    "aTargets": [1],
                    "mData": "imageurl",
                    "mRender": function (a, b, c, d) {
                        return '<img src="' + a + '" style="width:80px;height:80px;">';

                    }
                }, {
                    "aTargets": [2],
                    "mData": "sex",
                    "mRender": function (a, b, c, d) {
                        if (a == 0) {
                            return '女'
                        } else if (a == 1) {
                            return '男';
                        } else {
                            return '';
                        }
                    }
                },

                /*  {
                 "aTargets": [6],
                 "mData": "createTime",
                 "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                 return formatDates(a, "yyyy-MM-dd HH:mm:ss");
                 }
                 },*/
                // {
                //     "aTargets": [3],
                //     "mData": "surname",
                //     "mRender": function (a, b, c, d) {
                //        return a;
                //     }
                // },
                {
                    "aTargets": [3],
                    "mData": "openId",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }, {
                    "aTargets": [4],
                    "mData": "phone",
                    "mRender": function (a, b, c, d) {
                        return c.phone.slice(0, 1) + '*' + c.phone.slice(2, 3);
                    }
                }, {
                    "aTargets": [5],
                    "mData": "name",
                    "mRender": function (a, b, c, d) {
                        return c.name.slice(0, 3) + '****' + c.name.slice(7);
                    }
                }, {
                    "aTargets": [6],
                    "mData": "source",
                    "mRender": function (a, b, c, d) {

                        if (a == 1) {
                            return "普通关注";
                        } else if (a == 2) {
                            return "药师二维码";
                        } else if (a == 3) {
                            return "客服二维码";
                        } else if (a == 4) {
                            return "医生二维码";
                        } else if (a == 5) {
                            return "组织二维码";
                        } else {
                            return "";
                        }

                    }
                }
                , {
                    "aTargets": [7],
                    "mData": "createTime",
                    "mRender": function (a, b, c, d) {
                        return formatDates(a, "yyyy-MM-dd HH:mm:ss");
                    }
                }

            ]
        });
    }


    function addlabelsubmit() {
        var code = $("#addlabel").val();
        $.ajax({
            type: "POST",
            url: "#springUrl('/a/member/addMember')",
            data: {code: code, _csrf_header: csrfheader.value, _csrf: csrftoken.value},
            dataType: "json",
            success: function (data) {
                if (data.errorNo == 0) {
                    Cfapp.alert({
                        message: "生成成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/member/list')";
                        }
                    });
                } else if (data.errorNo == 1) {
                    Cfapp.alert({
                        message: "系统异常",
                        btntext: "确定",
                        success: function () {

                        }
                    });
                } else {
                    Cfapp.alert({
                        message: "无效的邀请码",
                        btntext: "确定",
                        success: function () {

                        }
                    });
                }
            },
            error: function () {
            }
        })
    }
    function addMemer() {
        $("#addlabelModal").modal("show");
    }


    jQuery(document).ready(function () {
        seachTable();
        $('.datepicker').datepicker({
            show: true,
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            clearBtn: 'linked'

        });
        $('.search').click(function () {
            $("#table").dataTable().fnClearTable();
        });


        $("#tagCacel").click(function () {
            $("#addlabelModal").modal("hide");
        })


    });

    Cfapp.init();
    function removeData(data) {
        Cfapp.confirm({
            message: "确定要删除吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/member/delete')",
                    data: {id: data, _csrf_header: csrfheader.value, _csrf: csrftoken.value},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            csrfheader.value = resp._csrf_header;
                            csrftoken.value = resp._csrf;
                            Cfapp.alert({
                                message: "删除成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/member/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }


</script>

</body>
</html>
