/**
 * [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/14 by bo $
*/
$(function () {
    
    function OEMyParty() {
        this.api_url = WAP_APPFILE+"&c=myparty";
        this.id = '';
        this.partyid = '';
        
        this.wake();
    }
    
    OEMyParty.prototype = {
        
        //触发
        wake:function() {
            var _this = this;
            $(document).on("click", "[f='but_pay']", function(){
                _this.id = $(this).attr("data-id");
                _this.partyid = $(this).attr("data-partyid");
                _this.pay();
            });
        },
        
        //支付
        pay:function() {
            var _this = this;
            
            var loading = null,
            timer = null;
            timer = setTimeout(function () {
                loading = OEUI.showLoading({type: '2'});
            }, 200);

            $.ajax({
                type: "POST",
                url: _this.api_url,
                cache: false,
                data: {
                    a:"confirmpay", id:_this.id
                },
                dataType: "json",
                success: function (json) {
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    
                    var $res = JSON.parse(json);
                    var $response = $res.response;
                    var $result = $res.result;
                    
                    if ($response == "1") {
                        window.location.href = WAP_APPFILE+"&c=pay&paynum="+$result;
                    }
                    else {
                        if ($result.length == 0 || $result == '') {
                            $result = '评论失败，请检查！';
                        }
                        OEUI.toast({
                            type: 'bottom',
                            text: $result
                        }); 
                    }
                },
                error: function() {
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;

                    OEUI.toast({
                        type: 'bottom',
                        text: '网络繁忙，请稍后再试'
                    });
                }
            });
            
        }
    }
    new OEMyParty();
});