/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/05/19 by CL $
*/
$(function () {
    
    //个人相册
    function OEHomePhoto () {
        this.home_uid = ''; //0.05.09
        this.type = ''; //是否显示全部包括头像 all 0.05.19
        this.api_url = WAP_APPFILE+"&c=home&a=getphoto";
        this.clickPhoto();
    }
    
    
    OEHomePhoto.prototype = { 
    
        clickPhoto:function () {
            var _this = this;
            
            //点击查看 0.05.09
            $('[f="view_photo"]').on('click', function () {
                //0.05.19
                var $type = $(this).attr("data-type");
                if (typeof($type) == 'undefined') {
                    $type = '';
                }
                _this.type = $type;
                
                if (_LOGIN_STATUS == '0') {
                    _this.home_uid = $("#homeuid").val();
                    if (typeof(_this.home_uid) == 'undefined') {
                        _this.home_uid = '';
                    }
                    window.location.href = WAP_APPFILE+"&c=passport&a=login&forward="+encodeURIComponent(WAP_APPFILE+"&c=home&a=detail&id="+_this.home_uid+"&nofollow=1");
                    return false;
                }
                else {
                    _this.getPhoto();
                }
            });
        },
        
        //获取相册列表
        getPhoto: function () {
            var _this = this;
            var $home_uid = $("#homeuid").val();
            
            var loading = null;
            var timer = setTimeout(function () {
                loading = OEUI.showLoading({
                    type:2
                });
            }, 200);
            
            $.ajax({
                type: 'POST',
                url: _this.api_url,
                data: {
                    uid: $home_uid, type:_this.type //0.05.19
                },
                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') {
                        OEPhotoSwipe($result.photo);
                    }
                    else if ($response == '2'){
                        //引导上传
                        _inst_oehome.guideDialog('my_photo');
                    }
                    else {
                        if ($result == '' || $result == null) {
                            $result = '查看失败，请检查';
                        }
                        //0.05.09
                        OEUI.toast({
                            text: $result
                        });
                    }
                },
                error: function () {
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    OEUI.toast({
                        text: '网络繁忙，请稍后再试'
                    });
                }
            });
        }
        
    }
    new OEHomePhoto();
});