3party-bind.js
4.47 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Created by liuchuanyang on 2016/11/23.
*/
var $ = require('yoho-jquery');
var Dialog = require('../plugins/dialog').Dialog;
var labelMap = {
renren: '人人',
douban: '豆瓣',
qq: '腾讯',
sina: '新浪微博',
alipay: '支付宝',
wechat: '微信'
};
var csrfToken = $('input[name=_csrf]').val();
document.domain = 'yohobuy.com';
// MDialog
function MDialog(opts) {
var that = this;
var option = $.extend(true, {}, {
className: 'm-dialog',
closeIcon: false
}, opts);
if (option.title) {
option.content = '<div class="dialog-title">' + option.title +
'<span class="iconfont dialog-close" data-role="dialog-close"></span>' +
'</div>' +
'<div class="dialog-content">' + option.content + '</div>';
}
Dialog.call(this, option);
this.$el.on('click', '[data-role=dialog-close]', function() {
that.close();
});
}
MDialog.prototype = new Dialog({
inherit: true
});
MDialog.prototype.constructor = MDialog;
function malert(content, title, cb) {
var id = '' + new Date().getTime();
var md = new MDialog({
content: content,
title: title || '提示',
btns: [{
id: id,
// btnClass: ['alert-sure'],
name: '确定',
cb: function() {
md.close();
(typeof cb === 'function') && cb();
}
}]
});
md.show();
}
function mconfirm(content, title, ok, cancel) {
var id = '' + new Date().getTime();
var md = new MDialog({
content: content,
title: title || '提示',
btns: [{
id: 'ok-' + id,
// btnClass: ['alert-sure'],
name: '确定',
cb: function() {
md.close();
(typeof ok === 'function') && ok();
}
}, {
id: 'cancel-' + id,
btnClass: ['btn-cancel'],
name: '取消',
cb: function() {
md.close();
(typeof cancel === 'function') && cancel();
}
}]
});
md.show();
}
function reloadPage() {
var url = window.location.href;
var idx = url.lastIndexOf('?');
if (idx > 0) {
url = url.substr(0, idx);
}
window.location = url + '?pt=bind';
}
$('#Y_bindAccount').on('click', '.account-item .account-item-title', function() {
var $t = $(this);
var $b = $t.closest('.account-item').find('.account-item-body');
var $a = $t.find('a');
$a.removeClass('del-binding');
$b.toggle();
if ($b.is(':visible')) {
$a.html('收起');
} else {
if ($a.attr('data-binding') === '1') {
$a.html('解绑');
$a.addClass('del-binding');
} else {
$t.find('a').html('绑定');
}
}
});
$('#Y_bindAccount').on('click', '.account-item .bind-btn', function() {
var url = $(this).attr('data-url');
window.open(url, '3partybind', 'width=600px;height=400px');
});
$('#Y_bindAccount').on('click', '.account-item .cancel-bind-btn', function() {
var url = $(this).attr('data-url');
mconfirm(
'<i class="iconfont tip-icon"></i>确定要解除绑定' + labelMap[$(this).attr('data-type')] + '?',
'您确定要解除绑定?',
function() {
$.ajax({
url: url,
type: 'POST',
data: {_csrf: csrfToken},
dataType: 'json'
})
.then(function(data) {
if (data.code === 200) {
malert('解绑成功!', '解绑成功', function() {
reloadPage();
});
} else {
malert('解绑失败,请稍后再试!', '解绑失败');
}
})
.fail();
}
);
});
window.bindTip = function(ret, type, message) {
var typeLabel = labelMap[type] || '';
if (ret === 'success') {
malert('<i class="iconfont tip-icon"></i>您已成功绑定' + typeLabel + '账号!', '绑定成功', function() {
reloadPage();
});
} else {
malert('<i class="iconfont tip-icon"></i>' + (message || '绑定失败!'), '绑定' + typeLabel + '账号');
}
};
$(function() {
var qs = window.queryString();
if (qs && qs.pt === 'bind') {
$('#Y_bindAccount h2.sub-title').trigger('click');
}
});