/**
 * [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 2019/10/22 by OE $
*/
var boundx, boundy, flip_obj;
$(function(){
	//确定裁剪 ajax
	$(document).on("click", "[f='but_confirm_cut']", function(){
        $obj_id = $(this).attr("id");
        
        if (!$("#"+$obj_id).hasClass("forbid_submit")) {
            $_imgcode = $("#imgcode").val();
            $_x1 = $("#x1").val();
            $_y1 = $("#y1").val();
            $_x2 = $("#x2").val();
            $_y2 = $("#y2").val();
            $_w = $("#w").val();
            $_h = $("#h").val();
            $_boundwidth = boundx; //压缩比例宽
            $_boundheight = boundy; //压缩比例高
            if ($_w.length == 0) {
                OEUI.message.msg({text: '请拖动设置白色裁剪框'});
                return false;
            }
            if ($_h.length == 0) {
                OEUI.message.msg({text: '请拖动设置白色裁剪框'});
                return false;
            }
            
            $("#"+$obj_id).addClass("forbid_submit");
            $("#"+$obj_id).find("span").show();
            $("#cut_loading").show();
            
            $from = $("#from").val();
            $forward = $("#forward").val();
            
            $.ajax({
                type: "POST",
                url: _ROOT_PATH+"index.php?m=user&c=avatar",
                cache: false,
                data: {
                        a:"cropper", imgcode:$_imgcode, x1:$_x1, y1:$_y1, x2:$_x2, y2:$_y2, w:$_w, h:$_h, boundwidth:$_boundwidth, boundheight:$_boundheight
                },
                success: function($data) {
                    $json = JSON.parse($data);
                    $response = $json.response;
                    $result = $json.result;
                    $attid = $json.attid;
                    if (typeof($attid) == "undefined") {
                        $attid = "";
                    }
                    if ($response == "1") {
                        OEUI.message.msg({text: '裁剪成功'});
                        _oeloveFileSynYun($attid); //同步云存储
                        
                        if ($from == "reg") {
                            //来源注册流程
                            if ($forward.length == 0) {
                                $forward = _ROOT_PATH+"index.php?c=passport&a=success";
                            }
                            setTimeout(function(){
                                window.parent.uploadAvatar.remove();
                                window.parent.location.href = $forward;
                            }, 500);
                        }
                         
                        //9.10.22  跳到会员中心
                        else if ($from == "cp") {
                            if ($forward.length == 0) {
                                $forward = _ROOT_PATH+"index.php?m=user";
                            }
                            setTimeout(function(){
                                window.parent.uploadAvatar.remove();
                                window.parent.location.href = $forward;
                            }, 500);
                        }
                        
                        else {
                            setTimeout(function(){
                                window.parent.uploadAvatar.remove();
                                window.parent.location.reload();
                            }, 500);
                        }
                    }
                    else {
                        if ($result.length > 0) {
                            OEUI.message.msg({text: $result});
                        }
                        else {
                            OEUI.message.msg({text: '裁剪失败'});
                        }
                        $("#"+$obj_id).removeClass("forbid_submit");
                        $("#"+$obj_id).find("span").hide();
                        $("#cut_loading").hide();
                        
                    }
                },
                error: function() {
                    OEUI.message.msg({text: '系统繁忙，请稍后再试'});
                    $("#"+$obj_id).removeClass("forbid_submit");
                    $("#"+$obj_id).find("span").hide();
                    $("#cut_loading").hide();
                }
            });
        
        }

	});
	
});