layui.extend({
    common    :   'js/common'
}).use(['jquery','table','layer','form','common'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    //  弹窗插件
    var layer = layui.layer;
    var common = layui.common;
    //  引入表单
    var form = layui.form;


    //表格对象
    var layuiTable = common.layuiTable.render(table,{
        elem: '#table-id'    //页面table的id
        , url: '/statistics/member/showMemberList' //后台接口
        ,method: 'post'
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，
        , cols: [[
           { field: 'name', title: '名字',align:'center'}
            , { field: 'tel', title: '电话',align:'center'}
            , { field: 'telType', title: '手机型号',align:'center'}
            , { field: 'sex', title: '性别',templet:'#sex',align:'center'}
            , { field: 'state', title: '认证状态',templet:'#state',align:'center'}
            , { field: 'createDate', title: '注册时间',align:'center'}
        ]]
        //  开启分页功能
        , page: true
    });

    //  重新加载表格
    var queryTableFn = function(){
        var name = $('#selectedName').val();
        var tel = $('#selectedTel').val();
        var state = $('#selectedState').val();
        //重新加载表格
        layuiTable.reload({
            where:{
                name    :   name,
                tel     :   tel,
                state   :   state,
            }
            //重新从第1页开始
            ,page: {
                curr: 1
            }
        });
    };

    //监听搜索
    form.on('submit(query)', function(){
        queryTableFn();
    });

    //监听重置查询
    form.on('submit(reset)', function(){
        $('#selectedName').val('');
        $('#selectedTel').val('');
        $('#selectedState').val('');
        // 刷新select标签
        form.render('select');
        queryTableFn();
    });

});

