Blame view

public/js/product/detail/brand-fav.js 3.63 KB
htoooth authored
1 2
var $ = require('yoho-jquery');
htoooth authored
3
exports.getFavNum = function(sid, bid) {
htoooth authored
4 5 6 7 8
    return $.getJSON('/product/index/favnum', {sid: sid, bid: bid})
        .then(function(result) {
            if (result.code === 200) {
                return result.data.count;
            } else {
htoooth authored
9
                return $.Deferred().reject().promise();// eslint-disable-line
htoooth authored
10 11
            }
        });
htoooth authored
12 13
};
htoooth authored
14
exports.addFav = function(sid, bid) {
htoooth authored
15 16
    if (!getUid()) {// eslint-disable-line
        return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise(); // eslint-disable-line
htoooth authored
17 18 19 20
    }

    if (sid) {
        return $.post('/product/shop/togglecollect', {
yyq authored
21
            isFavorite: 1,
htoooth authored
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
            shopId: sid
        }).then(function(result) {
            if (result.code === 200) {
                return $.Deferred().resolve().promise();  //eslint-disable-line
            } if (result.code === 401) {
                return window.jumpUrl(window.signinUrl());
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }

    if (bid) {
        return $.post('/product/index/favoriteBrand', {
            type: 'add',
            brandId: bid
        }).then(function(result) {
            if (result.code === 200) {
                return $.Deferred().resolve().promise();//eslint-disable-line
            } else if (result.code === 403) {
                return window.jumpUrl(window.signinUrl());
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }
};
htoooth authored
50
exports.cancelFav = function(sid, bid) {
htoooth authored
51 52
    if (!getUid()) {// eslint-disable-line
        return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise();// eslint-disable-line
htoooth authored
53 54 55 56
    }

    if (sid) {
        return $.post('/product/shop/togglecollect', {
yyq authored
57
            isFavorite: 0,
htoooth authored
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
            shopId: sid
        }).then(function(result) {
            if (result.code === 200) {
                return $.Deferred().resolve().promise();//eslint-disable-line
            }
            if (result.code === 401) {
                return window.jumpUrl(window.signinUrl());
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }

    if (bid) {
        return $.post('/product/index/favoriteBrand', {
            type: 'cancel',
            brandId: bid
        }).then(function(result) {
            if (result.code === 200) {
                return $.Deferred().resolve().promise();//eslint-disable-line
            } else if (result.code === 403) {
                return window.jumpUrl(window.signinUrl());
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }
};
htoooth authored
87
exports.statusFav = function(sid, bid) {
htoooth authored
88 89 90 91
    if (sid) {
        return $.post('/product/index/isFavoriteShop', {
            shopId: sid
        }).then(function(result) {
yyq authored
92
            if (result.code === 200 && result.data) {
htoooth authored
93 94 95 96 97 98 99 100 101 102 103
                return $.Deferred().resolve().promise();//eslint-disable-line
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }

    if (bid) {
        return $.getJSON('/product/index/isfav', {
            brandId: bid
        }).then(function(result) {
htoooth authored
104
            if (result.code === 200 && result.data) {
htoooth authored
105 106 107 108 109 110
                return $.Deferred().resolve().promise();//eslint-disable-line
            } else {
                return $.Deferred().reject().promise();//eslint-disable-line
            }
        });
    }
htoooth authored
111
yyq authored
112
    return $.Deferred().reject().promise();//eslint-disable-line
htoooth authored
113 114
};