/**
 * [OElove] (C)2010-2099 oelove.com Webapp
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/03/12 by bo $
*/
$(function () {

    function OECond() {
        this.api_url = WAP_APPFILE+'&c=profile';
        this._this_dialog = null;
        this.slide_time = 300;
        
        this.obj_id = '';
        this.wake();
        
    }
    OECond.prototype = {
        //触发
        wake:function() {
            var _this = this;
            
            //弹出
            $(document).on("click", "[f='open_cond_dialog']", function() {
                _this._this_dialog = OEUI.Dialog({
                    el: "#cond_dialog",
                    animated: 'slideRightIn',
                    time:_this.slide_time
                });
            });
            //关闭 
            $(document).on("click", "[f='close_cond_dialog']", function() {
                _check_profile_mygr();
                if (_this._this_dialog) {
                    _this._this_dialog.hide();
                }
            });

            //提交
            $(document).on("click", "[f='but_submit_cond']", function(){
                _this.obj_id = $(this).attr("id");
                
                var $send_data = {
                    'age1':$("#cond_age1").val(), 'age2':$("#cond_age2").val(), 
                    'height1':$("#cond_height1").val(), 'height2':$("#cond_height2").val(),
                    'weight1':$("#cond_weight1").val(), 'weight2':$("#cond_weight2").val(),
                    'marry':$("#cond_marry").val(), 'education':$("#cond_education1").val(), 
                    'eduup':$("#cond_education2").val(),
                    'salary':$("#cond_salary1").val(), 'salaryup':$("#cond_salary2").val(),
                    'house':$("#cond_house").val(), 'car':$("#cond_car").val(),
                    'child':$("#cond_child").val(), 'avatar':$("#cond_avatar").val(),
                    'rz':$("#cond_rz").val(), 'area1':$("#cond_area1").val(), 
                    'area2':$("#cond_area2").val(), 'a':'savecond'
                };
                
                _this.sendCond($send_data);
            });
            
        }, 
        
        //保存
        sendCond:function($send_data) {
            var _this = this;
            
            if (!$("#"+_this.obj_id).hasClass("forbid_submit")) {
                var loading = null;
                var timer = setTimeout(function () {
                    loading = OEUI.showLoading({
                        type:2
                    });
                }, 200);
                $("#"+_this.obj_id).addClass("forbid_submit");
                
                $.ajax({
                    type: "POST",
                    url: _this.api_url,
                    cache: false,
                    data:$send_data,
                    dataType: "json",
                    success: function($data) {
                        var $json = eval($data);
                        var $response = $json.response;
                        var $result = $json.result;
                        
                        clearTimeout(timer);
                        loading && loading.hideLoading();
                        timer = null;
                        
                        if ($response == "1") {
                            _check_profile_mygr();
                            OEUI.toast({
                                type: 'bottom',
                                text: '保存成功'
                            }); 
                            setTimeout(function(){
                                if (_this._this_dialog) {
                                    _this._this_dialog.hide();
                                }
                            }, 800);
                        }
                        else {
                            if ($result.length == 0 || $result == '') {
                                $result = '保存失败，请检查';
                            }
                            OEUI.toast({
                                type: 'bottom',
                                text: $result
                            }); 
                        }
                        $("#"+_this.obj_id).removeClass("forbid_submit");
                    },
                    error: function() {
                        $("#"+_this.obj_id).removeClass("forbid_submit");
                        clearTimeout(timer);
                        loading && loading.hideLoading();
                        timer = null;
                        OEUI.toast({
                            type: 'bottom',
                            text: '网络繁忙，请稍后再试！'
                        });
                    }
                });
            }
            
        }
    }
    new OECond();

});