/**
 * [OElove] (C)2010-2099 oelove.com Inc.biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 *  Last update 2020/11/13 by OE 
*/
$(function(){
    function PartyBm() {
        this.bmBtn();
        this.checkMobileRz();
        this.initPicker();
    }
    PartyBm.prototype = {
        //报名按钮
        bmBtn: function () {
            var is_http = false;
            $("[f='but_submit_addbm']").on("click", function () {
                var partyid = $("#partyid").val();
                var mobile = $("#mobile").val();
                var mobile_rz = $("#mobile").attr("data-rz");
                if (typeof(mobile_rz) == "undefined") {
                    mobile_rz = "";
                }
                if (mobile.length == 0) {
                    OEUI.message.msg({text: "请填写手机号码"});
                    return false;

                }
                var mobilecode = $("#mobilecode").val();
                if (typeof(mobilecode) == "undefined") {
                    mobilecode = "";
                }
                else {
                    //9.02.21
                    if (mobile_rz != "1") {
                        if (mobilecode.length == 0) {
                            OEUI.message.msg({text: "请填写手机验证码"});
                            return false;
                        }
                    }
                }


                var truename = $("#truename").val();
                if (typeof(truename) == "undefined") {
                    truename = "";
                }
                else {
                    if (truename.length == 0) {
                        OEUI.message.msg({text: "请填写姓名"});
                        return false;

                    }
                }

                var idnumber = $("#idnumber").val();
                if (typeof(idnumber) == "undefined") {
                    idnumber = "";
                }
                else {
                    if (idnumber.length == 0) {
                        OEUI.message.msg({text: "请填写身份证号"});
                        return false;
                    }
                }
                var gender = $("#gender").val();
                if (typeof(gender) == "undefined") {
                    gender = "";
                }
                else {
                    if (gender.length == 0) {
                        OEUI.message.msg({text: "请选择性别"});
                        return false;

                    }
                }
                var weixin = $("#weixin").val();
                if (typeof(weixin) == "undefined") {
                    weixin = "";
                }
                else {
                    if (weixin.length == 0) {
                        OEUI.message.msg({text: "请填写微信号"});
                        return false;
                    }
                }

                var dist1 = $("#dist1").val();
                if (typeof(dist1) == "undefined") {
                    dist1 = "";
                }
                else {
                    if (dist1.length == 0) {
                        OEUI.message.msg({text: "请选择所在地区"});
                        return false;
                    }
                }
                var dist2 = $("#dist2").val();
                if (typeof(dist2) == "undefined") {
                    dist2 = "";
                }
                else {
                    if (dist2.length == 0) {
                        OEUI.message.msg({text: "请选择所在地区"});
                        return false;
                    }
                }
                var dist3 = $("#dist3").val();
                if (typeof(dist3) == "undefined") {
                    dist3 = "";
                }

                var ageyear = $("#ageyear").val();
                if (typeof(ageyear) == "undefined") {
                    ageyear = "";
                }
                else {
                    if (ageyear.length == 0) {
                        OEUI.message.msg({text: "请选择出生年月"});
                        return false;
                    }
                }
                var agemonth = $("#agemonth").val();
                if (typeof(agemonth) == "undefined") {
                    agemonth = "";
                }
                else {
                    if (agemonth.length == 0) {
                        OEUI.message.msg({text: "请选择出生年月"});
                        return false;
                    }
                }
                var ageday = $("#ageday").val();
                if (typeof(ageday) == "undefined") {
                    ageday = "";
                }
                else {
                    if (ageday.length == 0) {
                        OEUI.message.msg({text: "请选择出生年月"});
                        return false;
                    }
                }

                var marry = $("#marry").val();
                if (typeof(marry) == "undefined") {
                    marry = "";
                }
                else {
                    if (marry.length == 0) {
                        OEUI.message.msg({text: "请选择婚况"});
                        return false;
                    }
                }

                var sort = $("#sort").val();
                if (typeof(sort) == "undefined") {
                    sort = "";
                }
                else {
                    if (sort.length == 0) {
                        OEUI.message.msg({text: "请选择交友类型"});
                        return false;
                    }
                }

                var height = $("#height").val();
                if (typeof(height) == "undefined") {
                    height = "";
                }
                else {
                    if (height.length == 0) {
                        OEUI.message.msg({text: "请选择身高"});
                        return false;
                    }
                }

                var weight = $("#weight").val();
                if (typeof(weight) == "undefined") {
                    weight = "";
                }
                else {
                    if (weight.length == 0) {
                        OEUI.message.msg({text: "请选择体重"});
                        return false;
                    }
                }

                var education = $("#education").val();
                if (typeof(education) == "undefined") {
                    education = "";
                }
                else {
                    if (education.length == 0) {
                        OEUI.message.msg({text: "请选择学历"});
                        return false;
                    }
                }

                var job = $("#job").val();
                if (typeof(job) == "undefined") {
                    job = "";
                }
                else {
                    if (job.length == 0) {
                        OEUI.message.msg({text: "请选择职业"});
                        return false;
                    }
                }

                var salary = $("#salary").val();
                if (typeof(salary) == "undefined") {
                    salary = "";
                }
                else {
                    if (salary.length == 0) {
                        OEUI.message.msg({text: "请选择收入"});
                        return false;
                    }
                }

                var house = $("#house").val();
                if (typeof(house) == "undefined") {
                    house = "";
                }
                else {
                    if (house.length == 0) {
                        OEUI.message.msg({text: "请选择住房情况"});
                        return false;
                    }
                }

                var car = $("#car").val();
                if (typeof(car) == "undefined") {
                    car = "";
                }
                else {
                    if (car.length == 0) {
                        OEUI.message.msg({text: "请选择购车情况"});
                        return false;
                    }
                }

                var sources = $("#sources").val();
                if (typeof(sources) == "undefined") {
                    sources = "";
                }
                else {
                    if (sources.length == 0) {
                        OEUI.message.msg({text: "请填写信息来源"});
                        return false;
                    }
                }

                var target = $("#target").val();
                if (typeof(target) == "undefined") {
                    target = "";
                }
                else {
                    if (target.length == 0) {
                        OEUI.message.msg({text: "请填写活动目的"});
                        return false;
                    }
                }


                if (is_http) return;
                is_http = true;

                var loading,
                    timer = setTimeout(function () {
                        loading = OEUI.loading({
                            el: this
                        });
                        loading.show();
                    }, 200);

                $.ajax({
                    type: "POST",
                    url: _ROOT_PATH+"index.php?c=party",
                    cache: false,
                    data: {
                        id:partyid, mobile:mobile, mobilecode:mobilecode, truename:truename, idnumber:idnumber,
                        gender:gender, weixin:weixin, dist1:dist1, dist2:dist2, dist3:dist3,
                        ageyear:ageyear, agemonth:agemonth, ageday:ageday, marry:marry, sort:sort,
                        height:height, weight:weight, education:education, job:job, salary:salary,
                        house:house, car:car, sources:sources, target:target, a:"savebm"
                    },
                    dataType: "json",
                    success: function(data) {
                        is_http = false;
                        loading && loading.remove();
                        clearTimeout(timer);
                        timer = null;
                        var json = eval(data);
                        var response = json.response;
                        var result = json.result;
                        if (response == '1') {
                            if (result.length > 0) {
                                window.parent.location.href = _ROOT_PATH+"index.php?c=pay&paynum="+result; //在线支付
                            }
                            else {
                                OEUI.message.msg({text: "报名成功"});
                                setTimeout(function(){
                                    window.parent.location.reload();
                                }, 500);
                            }
                        }
                        else {
                            if (result.length > 0) {
                                OEUI.message.msg({text: result});
                            }
                            else {
                                OEUI.message.msg({text: "报名失败"});
                            }
                        }
                    },
                    error: function() {
                        is_http = false;
                        loading && loading.remove();
                        clearTimeout(timer);
                        timer = null;
                        OEUI.message.msg({text: "系统繁忙，请稍后再试"});
                    }
                });
            });
        },
        //检测登录用户手机号是否已认证
        checkMobileRz: function () {
            $(document).on("blur", "#mobile", function(){
                var val = $(this).val();
                $.ajax({
                    type: "POST",
                    url: _ROOT_PATH+"index.php?c=party",
                    cache: false,
                    data: {
                        mobile:val, a:"checkmob"
                    },
                    dataType: "json",
                    success: function(data) {
                        var json = eval(data);
                        var response = json.response;
                        var result = json.result;
                        if (response == '1') {
                            $("#mobile").attr("data-rz", "1");
                            //已认证
                            if ($("#mobyz_box").length > 0) {
                                $("#mobyz_box").hide();
                            }
                        }
                        else {
                            $("#mobile").attr("data-rz", "0");
                            //未认证
                            if ($("#mobyz_box").length > 0) {
                                $("#mobyz_box").show();
                            }
                        }
                    },
                    error: function() {
                    }
                });

            });
        },
        initPicker:function () {
            new Dist({
                el: $('#dist'),
                dataType: '2'
            });
            new Birthday({
                el: $('#birthday'),
                range: ['18', '60']
            });
        }
    };
    new PartyBm();
});
