detail-dynamic.js 1.06 KB
/**
 * 动态获取页面数据
 * @author liuchuanyang
 * @date 2016/10/09
 */
var $ = require('yoho-jquery');

function getDynamicById(id) {
    'use strict';

    var param = {
        id: id
    };

//  //guang.yohobuy.com/guang/info/detailData
    return $.getJSON('/guang/info/detailData', param);
}

function renderData(data) {
    'use strict';

    var $favor = $('#collect-btn'),
        $praise = $('#prise-btn');

    if (data && data.code === 200 && data.data) {

        if (data.data.isFavor === 'Y') {
            $favor.addClass('collected');
        } else {
            $favor.removeClass('collected');
        }

        if (data.data.isPraise === 'Y') {
            $praise.addClass('liked');
        } else {
            $praise.removeClass('liked');
        }

        $praise.find('.like-num').text(data.data.praiseNum || 0);
        $('.detail-body .article-click em').text(data.data.browseNum || 0);
    }
}

function refreshData() {
    'use strict';

    var id = $('.detail-body').attr('data-id');

    getDynamicById(id).done(renderData);
}

refreshData();