/**
 * [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/01/19 by OE 
*/
$(function(){
    function PartyDetail() {
        this.bmBtn();
    }
    PartyDetail.prototype = {
        //报名按钮
        bmBtn: function () {
            //活动报名
            var _this = this;
            $(document).on('click', '[f="pop_partybm"]', function(){
                var id = $(this).attr("data-id");
                _this.id = id;
                
                var width = $(this).attr("data-width");
                if (typeof(width) == "undefined") {
                    width = 800;
                }
                var height = $(this).attr("data-height");
                if (typeof(height) == "undefined") {
                    height = 580;
                }
                
                var type = $(this).attr('data-type');
                if (type == 'idrz') {
                    _this.tipsIdrz();
                    return false;
                }
                else if (type == 'vip') {
                    _this.tipsVip();
                    return false;
                }
                _this.bm_dialog = OEUI.modal.dialog({
                    type: 'iframe',
                    title: '报名活动',
                    width: width,
                    height: height,
                    content: _ROOT_PATH+"index.php?c=party&a=bm&partyid="+id
                });
            }); 
        },
                
        tipsIdrz:function() {
            var _this = this;
            var back_url = _ROOT_PATH+"index.php?c=party&a=detail&id="+_this.id;
            OEUI.modal.warning({
                title: '温馨提示',
                text: '你还没实名认证，无法报名活动',
                confirmText: '立即认证',
                cancelText: '知道了',
                confirm: function () {
                    window.location.href = _ROOT_PATH+"index.php?m=user&c=rz&fromurl="+encodeURIComponent(back_url);
                },
                cancel: function () {
                    
                }
            });
        },
        tipsVip:function() {
            var _this = this;
            var back_url = _ROOT_PATH+"index.php?c=party&a=detail&id="+_this.id;
            OEUI.modal.warning({
                title: '温馨提示',
                text: '你不是VIP会员，无法报名活动',
                confirmText: '立即升级',
                cancelText: '知道了',
                confirm: function () {
                    window.location.href = _ROOT_PATH+"index.php?m=user&c=vip&fromurl="+encodeURIComponent(back_url);
                },
                cancel: function () {
                    
                }
            });
            
        }
    };
    new PartyDetail();
	//选择地区
	$(document).on("click", "[f='but_open_area']", function(){
		if ($("#party_area_box").css("display") == "none") {
			$("#party_area_box").slideDown(100);
		}
		else {
			$("#party_area_box").slideUp(100);
		}
	});
	$(document).on("click", "[f='but_party_selarea']", function(){
		var _val1 = parseInt($("#s_area1").find("option:selected").val());
        var _text1 = $("#s_area1").find("option:selected").text();

        var _val2 = parseInt($("#s_area2").find("option:selected").val());
        var _text2 = $("#s_area2").find("option:selected").text();
		if (typeof(_val2) == "undefined") {
			_val2 = 0;
		}
		if (typeof(_text2) == "undefined") {
			_text2 = "";
		}

        var _val3 = parseInt($("#s_area3").find("option:selected").val());
        var _text3 = $("#s_area3").find("option:selected").text();
		if (typeof(_val3) == "undefined") {
			_val3 = 0;
		}
		if (typeof(_text3) == "undefined") {
			_text3 = "";
		}

        var _val4 = parseInt($("#s_area4").find("option:selected").val());
        var _text4 = $("#s_area4").find("option:selected").text();
		if (typeof(_val4) == "undefined") {
			_val4 = 0;
		}
		if (typeof(_text4) == "undefined") {
			_text4 = "";
		}

        var text = "";
		if (_text1.length > 0 && _text1 != "请选择") {
			text = _text1;
		}
		if (_text2.length > 0 && _text2 != "请选择") {
			text += "-"+_text2;
		}
		if (_text3.length > 0 && _text3 != "请选择") {
			text += "-"+_text3;
		}
		if (_text4.length > 0 && _text4 != "请选择") {
			text += "-"+_text4;
		}
		if (text.length > 0) {
			$("[f='but_open_area']").html(text+"<i class='layui-edge'></i>");
		}
		$("#party_area_box").slideUp(100);
        $("#my_party_form").submit();

	});
	//点击空白出隐藏选择器
	$(document).on("click", function(e){
		var target1  = $(e.target);
        if (target1.closest(".layui-form-item").length == 0){
			$(".layui-form-item #party_area_box").slideUp(100);
		}
	});

    //打开报名会员列表窗 2018.05.28
    $(document).on("click", "[f='but_open_bmuser']", function(){
        var partyid = $("#partyid").val();
        var _url = _ROOT_PATH+"index.php?c=party&a=bmuser&partyid="+partyid+"&r="+get_rndnum(8);
        $.ajax({
            type: "GET",
            url:  _url,
            cache: false,
            data: {r:get_rndnum(8)},
            dataType: "json",
            success: function (data) {
                var json = eval(data);
                var result = json.result;
                var response = json.response;
                if (response == 1) {
                    layer.open({
                        title:'已报名活动会员列表',
                        type: 1,
                        area: ['710px', '450px'],
                        shadeClose: true,
                        content: result,
                        success: function(layero, index){
                            _getBmPageList(1);
                        }
                    });
                }
                else{
                    if (result.length == 0) {
                        result = "查看失败";
                    }
                    layer.msg(result);
                }
            },
            error: function() {

            }
        });
    });
    //加载下一页报名
    $(document).on("click", "[f='but_get_bmpage']", function(){
        var _page = parseInt($(this).attr("data-page"));
        if (_page > 1) {
            $("[f='but_get_bmpage']").find("label").show();
        }
        _getBmPageList(_page);
    });
    
    //会员认证提示  2019.01.19
    $(document).on("click", '[f="but_idrz_tips"]', function(){
        var id = $(this).attr("data-id");
        layer.confirm("你没有实名认证，请先进行认证", 
        {
            title: "温馨提示",
            btn: ['去认证', '知道了']
        },        
        function(){
            //升级...
            var back_url = _ROOT_PATH+"index.php?c=party&a=detail&id="+id;
            window.location.href = _ROOT_PATH+"index.php?m=user&c=rz&fromurl="+encodeURIComponent(back_url);
        },         
        function(){
            //知道了...
        });
    });
    
    //会员VIP提示  2019.01.19
    $(document).on("click", '[f="but_vip_tips"]', function(){
        var id = $(this).attr("data-id");
        layer.confirm("你没有权限执行此操作，请先升级会员", 
        {
            title: "温馨提示",
            btn: ['去升级', '知道了']
        },        
        function(){
            //升级...
            var back_url = _ROOT_PATH+"index.php?c=party&a=detail&id="+id;
            window.location.href = _ROOT_PATH+"index.php?m=user&c=vip&fromurl="+encodeURIComponent(back_url);
        },         
        function(){
            //知道了...
        });
    });
});


//ajax报名会员列表
function _getBmPageList(page) {
    if (typeof(page) == "undefined") {
        page = 1;
    }
    var partyid = $("#partyid").val();
    var obj_box = $("#bm_json_data");
    $.ajax({
        type: "GET",
        url:  _ROOT_PATH+"index.php?c=party&a=bmlist&datatype=json&partyid="+partyid,
        cache: false,
        data: {page:page, r:get_rndnum(8)},
        dataType: "json",
        success: function(data) {
            var json = eval(data);
            var prepage = json.prepage; //上一页
            var nextpage = json.nextpage; //下一页
            var result = json.result;
            if (result.length > 0) {
                if (page == "1") {
                    obj_box.html(result);
                }
                else {
                    obj_box.append(result);
                }
                if (nextpage > 0) { //还有下一页
                    $("[f='but_get_bmpage']").attr("data-page", nextpage);
                    $("[f='but_get_bmpage']").show();
                    $("[f='but_get_bmpage']").find("label").hide();
                }
                else {
                    $("[f='but_get_bmpage']").hide();
                }
            }
        },
        error: function() {

        }
    });
}
