user.js
2.48 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
72
73
74
75
76
77
78
import $ from 'jquery';
import jsonp from './jsonp';
import utils from './utils';
let _noLoginUrl = function() {
let referrer = location.href.split('?')[0];
return '//m.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href) + '&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;
return jsonp({
url: '//m.yohobuy.com/passport/login/user?callback=?'
}).then(function(res){
if (res.code === 200) {
_this.uid = Number(res.data) || 0;
}
if (!_this.uid && utils.isApp()) {
_this.uid = Number(utils.queryString().uid) || 0;
}
return $.Deferred().resolve(_this.uid);
}, function() {
utils.isApp() && (_this.uid = Number(utils.queryString().uid) || 0);
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
});
});
},
getMktCode() {
let mkt_code;
if (this.uid) {
if (Number(this.uid) % 1024 >= 512) {
mkt_code = 100000000000195; // 默认的值
} else {
mkt_code = 100000000000193; // 个性化,动态接口数据
}
} else {
mkt_code = 100000000000197; // 访客接口数据
}
return mkt_code;
}
};