/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 *  Last update 2019/10/17 by OE 
*/
$(function(){
    function Userlist() {
        this.condition = {
            s_uid: $("#s_uid").val(),
            s_age1: $("#s_age1").val(),
            s_age2: $("#s_age2").val(),
            s_gender: $("#s_gender").val(),
            s_dist1: $("#s_dist1").val(),
            s_dist2: $("#s_dist2").val(),
            s_dist3: $("#s_dist3").val(),
            s_marry: $("#s_marry").val(),
            s_avatar: $("#s_avatar").attr("checked") == "checked"?1:0,
            s_match_cond: $("#s_match_cond").attr("checked") == "checked"?1:0,
            s_height1: $("#s_height1").val(),
            s_height2: $("#s_height2").val(),
            s_education: $("#s_edu").val(),
            s_house: $("#s_house").val(),
            s_salary: $("#s_salary").val(),
            s_job: $("#s_job").val(),
            s_orderby: 0,
            page: 1
        };
        this.initDist();
        this.changeOrderBy();
        this.searchBtn();
    }

    Userlist.prototype = {
        initDist: function () {
            new Dist({
                el: $('#dist'),
                dataType: '2'
            });
        },
        //建立url链接
        buildUrl: function () {
            var url = "/index.php?c=user&a=list";
            for (let key in this.condition) {
                if (key == "s_avatar") {
                    this.condition[key] = $("#s_avatar").attr("checked") == "checked"?1:0;
                } else if (key == "s_match_cond") {
                    this.condition[key] = $("#s_match_cond").attr("checked") == "checked"?1:0;
                } else if (key == "page") {
                    continue;
                } else if (key == "s_orderby") {

                }
                else {
                    this.condition[key] = $("#"+key).val();
                }
                if (this.condition[key]) {
                    url += "&" + key + "=" + this.condition[key];
                }
            }
            return url;
        },
        //切换排序
        changeOrderBy: function () {
            var _this = this;
            $(document).on("click", "[f='but_ser_orderby']", function(){
                var val = $(this).attr("data-val");
                //如果是附近的人，必须已登录
                if (val == '3'){
                    if (_LOGIN_STATUS == 0) {
                        location.href = "/index.php?c=passport&a=login";
                        return;
                    }
                    //如果未设置地图位置
                    if (ismap == '0') {
                        _this.completeMap();
                        return;
                    }
                }
                _this.condition.s_orderby = val;
                var url = _this.buildUrl();
                location.href = url;
            });
        },
        //完善地图
        completeMap: function () {
            OEUI.modal.dialog({
                type: "iframe",
                title: "请标注您的位置",
                content: _ROOT_PATH+"index.php?m=user&c=map",
                width: 900,
                height: 600
            })
        },
        //搜索按钮
        searchBtn: function () {
            var _this = this;
            $("[f='search_btn']").on("click", function () {
                var url = _this.buildUrl();
                location.href = url;
            })
        }
    };
    new Userlist();
});

//获取随机会员...8.08.16
function _userlist_get_randuser() {
    var obj = $("#user_rand_data");
    obj.find("#user_rand_loading").show();
    $.ajax({
        type: "POST",
        url: _ROOT_PATH + "index.php?c=user",
        cache: false,
        data: {
            a:"randuser", r:get_rndnum(8)
        },
        dataType: "json",
        success: function(data) {
            var json = eval(data);
            var response = json.response;
            var result = json.result;
            if (response == "1") {
                obj.html(result);
            } 
        },
        error: function() {
            obj.find("#user_rand_loading").hide();
        }
    });
}