/** * Created by yfzhangguangming on 2016/6/27. */ $(function () { var info = { articleId: $('.detail .follow').attr('article-id'), writerId: $('.designer .follow').attr('writer-id'), init: function () { var labelIds = $("#related").attr("labelids"); if (labelIds) { var labelIdArray = labelIds.split(","); if (labelIdArray.length > 0) { info.getRelated(labelIdArray[1]) } } myutils.checkLogin(info.isCollect, undefined); myutils.checkLogin(info.checkAttention, undefined); $('.detail .follow').click(function () { myutils.checkLogin(info.doCollect, info.isCollect); }); $('.designer .follow').click(function () { myutils.checkLogin(info.doAttention, info.checkAttention); }); info.browse(info.articleId); }, isCollect: function () { myutils.isCollect(info.articleId, info.changeArticleStyle); }, doCollect: function () { if ($('.detail .follow').hasClass('followed')) { myutils.doUnCollect(info.articleId, info.changeArticleStyle); } else { myutils.doCollect(info.articleId, info.changeArticleStyle); } }, checkAttention: function () { myutils.checkAttention(info.writerId, info.changeDesignerStyle); }, doAttention: function () { if ($('.designer .follow').hasClass('followed')) { myutils.doUnAttention(info.writerId, info.changeDesignerStyle); } else { myutils.doAttention(info.writerId, info.changeDesignerStyle); } }, changeArticleStyle: function (ok) { if (ok) { $('.detail .follow').addClass('followed'); } else { $('.detail .follow').removeClass('followed'); } }, changeDesignerStyle: function (ok) { if (ok) { $('.designer .follow').addClass('followed'); } else { $('.designer .follow').removeClass('followed'); } }, getRelated: function (id) { $.ajax({ url: '/article/related?id=' + id, dataType: 'json', success: function (r) { if (r) { if (r.list && r.list.length > 0) { var list = r.list; var htmls = []; var skuIds = []; for (var i = 0, j = list.length; i < j; i++) { var labelName = ''; if (r.labelNames) { var labelNames = r.labelNames; for (var l = 0, m = labelNames.length; l < m; l++) { if (labelNames[l].id == list[i].id) { labelName = labelNames[l].name; } } } var clstag = 'clstag="pageclick|keycount|Pcshejibang_details|'+(i + 42)+'"'; var html = '
  • ' + '
    ' + '
    ' + labelName + '
    ' + '
    ' + '' + '' + '' + '
    ' + '' + '
    ' + '
  • '; htmls.push(html); if (r[list[i].id]) { skuIds.push(r[list[i].id]) } } $("#related").html(htmls.join("")); if (skuIds.length > 0) { for (var s = 0; s < skuIds.length; s++) { info.getRelatedPrice(skuIds[s]); } } } } } }) }, getRelatedPrice: function (skuIds) { $.ajax({ url: '//p.3.cn/prices/mgets?skuIds=' + skuIds + '&area=0&type=1', dataType: 'jsonp', success: function (r) { if (r && r.length > 0) { var totalPrice = 0.0; for (var i = 0; i < r.length; i++) { var p = parseFloat(r[i].p); if (p > 0) { totalPrice += p; } } totalPrice = totalPrice.toFixed(2); if (totalPrice > 0) { $("#related .p-price").each(function () { if ($(this).attr("skuids") == skuIds) { $(this).children().html(totalPrice); } }); } } } }); }, browse: function (id) { $.ajax({ url: '/article/browse?id=' + id, dataType: 'json', success: function (r) { } }) } } info.init(); });