user.js
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import $ from 'jquery';
import jsonp from './jsonp';
import utils from './utils';
let _noLoginUrl = function() {
if (!utils.isApp()) {
return '//m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
} else {
let referrer = location.href.split('?')[0];
return '//m.yohobuy.com/signin.html?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + referrer.replace(/\//g, '\\/') + '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}';
}
};
export default {
uid: '',
noLoginUrl: _noLoginUrl,
init() {
let _this = this;
if (!utils.isApp()) {
// 获取当前登录用户信息
return jsonp({
url: '//m.yohobuy.com/passport/login/user?callback=?'
}).then(function(res){
if (res.code === 200) {
_this.uid = res.data;
}
return $.Deferred().resolve(_this.uid);
}, function() {
return $.Deferred().resolve(_this.uid);
});
} else {
_this.uid = utils.queryString().uid;
return $.Deferred().resolve(_this.uid);
}
},
auth() {
if (!this.uid) {
let noLoginUrl = _noLoginUrl();
$('a.auth').attr('href', noLoginUrl);
}
},
favout(skn) {
if (!skn || !this.uid) {
return;
}
jsonp({
url: `//service.yoho.cn/activity/favorite/addFavorite?productSkn=${skn}&uid=${this.uid}&callback=?`,
}).then(function(res) {
if (res.code === 200) {
utils.showTip({
content: '恭喜您,收藏成功',
close: true
});
} else {
utils.showTip({
content: res.message,
close: true
});
}
}, function(){
utils.showTip({
title: '收藏失败<br>请刷新重新领取',
content: '如多次收藏失败,请联系客服人员<br>带来不便敬请谅解',
close: false
});
});
}
};