/**
 * 创建html
 *
 * @param e
 * @param id
 * @param tp_id
 */
function createRatioHtml(e, id, tp_id)
{
    var html = $("template#"+tp_id).html();//.replace(/__ID__/g, id);
    e.append(html);
}

/**
 * 设置显示的值
 *
 * @param e
 * @param data
 * @param type
 */
function setRatioText(e, data, type)
{
    e.find('.count').text(data['count']).animate({opacity:"1"}, 500);
    var day = e.find('.' + type);
    day.find('.ratio').text(data[type]['ratio']).addClass(data[type]['color']).animate({opacity:"1"}, 500);
    var count = data[type]['count'];
    var count_color = '';
    if (count > 0) {
        count = '+' + count;
        count_color = 'red';
    } else {
        count = '--';
    }
    day.find('.box-rate-count').text(count).addClass(count_color).animate({opacity:"1"}, 500);
    day.animate({opacity:"1"}, 500);
}

/**
 * 获取用户统计增长率
 *
 * @param role
 * @param prefix
 */
function getUserRatio(role, prefix)
{
    // 异步加载数据
    var url  ="/" +prefix+"/statistic/growth-rate?type="+role;
    $.ajax({
        url: url,
        type: "get",
        dataType : "json",
        success: function (data) {
            var e = $('#'+role);
            setRatioText(e, data, 'day');
            setRatioText(e, data, 'week');
            setRatioText(e, data, 'month');
            user_count += data['count'];
            $("#user-count").text(user_count);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            e.find('.count').animate({opacity:"1"}, 500);
            e.find('.day').animate({opacity:"1"}, 500);
            e.find('.week').animate({opacity:"1"}, 500);
            e.find('.month').animate({opacity:"1"}, 500);
            //关闭加载层
            layer.closeAll('loading');
        }
    });
}

/**
 * 获取用户统计增长率
 *
 * @param type
 */
function getGrowthRate(type, prefix)
{
    // 异步加载数据
    var url  = "/" +prefix+"/statistic/growth-rate?type="+type;
    $.ajax({
        url: url,
        type: "get",
        dataType : "json",
        success: function (data) {
            var e = $('#'+type);
            setRatioText(e, data, 'day');
            setRatioText(e, data, 'week');
            setRatioText(e, data, 'month');
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            e.find('.count').animate({opacity:"1"}, 500);
            //e.find('.day').animate({opacity:"1"}, 500);
            //e.find('.week').animate({opacity:"1"}, 500);
            //e.find('.month').animate({opacity:"1"}, 500);
            //关闭加载层
            layer.closeAll('loading');
        }
    });
}


/**
 * 获取资源统计增长率
 *
 * @param type
 */
function getResourceRate(type, prefix)
{
    // 异步加载数据
    var url  = "/" +prefix+"/statistic/growth-rate?type="+type;
    $.ajax({
        url: url,
        type: "get",
        dataType : "json",
        success: function (data) {
            var e = $('#'+type);

            setRatioText(e, data, 'day');
            setRatioText(e, data, 'week');
            setRatioText(e, data, 'month');

            // e.find('.count').text(data['count']).animate({opacity:"1"}, 500);
            // e.find('.day').text(data['day']['ratio']).addClass(data['day']['color']).animate({opacity:"1"}, 500);
            // e.find('.week').text(data['week']['ratio']).addClass(data['week']['color']).animate({opacity:"1"}, 500);
            // e.find('.month').text(data['month']['ratio']).addClass(data['month']['color']).animate({opacity:"1"}, 500);
            // e.show();
            // e.css('visibility','visible');//元素显示
            resource_count += data['count'];
            $("#resource-count").text(resource_count);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            e.find('.count').animate({opacity:"1"}, 500);
            e.find('.day').animate({opacity:"1"}, 500);
            e.find('.week').animate({opacity:"1"}, 500);
            e.find('.month').animate({opacity:"1"}, 500);
            //关闭加载层
            layer.closeAll('loading');
        }
    });
}


function showLockPasswordSetPage( id )
{
    layer.open(
        {
            type: 2,
            title: '设置密码',
            shadeClose: true,
            // zIndex:9999,
            shade: 0.8,
            area: ['700px', '450px'],
            content: 'tenants/'+id+'/password-set-page', //iframe的url
            iframe: {
                src:'tenants/'+id+'/password-set-page',
                scrolling:'no'
            }
        }
    );
}