refund.page.js
5.16 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* 退货申请页
* @author: yyqing<yanqing.yang@yoho.cn>
* @date: 2016/7/15
*/
var $ = require('yoho-jquery'),
lazyload = require('yoho-jquery-lazyload'),
handlebars = require('yoho-handlebars'),
upload = require('../plugins/upload');
var $refundTable = $('.refund-goods'),
$check = $('.check'),
$refundType = $('.refund-type'),
$typeInfo = $refundType.children('dl');
var $applyBtn = $('#apply-btn');
var orderCode = $('#order-code').val() || 0,
specialReason = $refundTable.data() || {},
payInfo = { // 退款信息
type: 3, // 2--银行卡 3--支付宝 4--yoho币
dom: $typeInfo.eq(0)
};
var tpl = '<div class="img-wrap">' +
'<div class="img-opt">' +
'<span>查看</span>' +
'<span>删除</span>' +
'</div>' +
'<div class="img-view"><img src="{{data}}"></div>' +
'</div>',
imgFn = handlebars.compile(tpl);
var checked;
require('../plugins/check');
lazyload($('img.lazy'));
function restApplyBtn() {
if (checked.documents && checked.documents.length) {
$applyBtn.removeClass('disable');
} else {
$applyBtn.addClass('disable');
}
}
function packApplyInfo() {
var dom,
isLack = false,
payment = {},
resData = {
orderCode: orderCode
};
if (checked && checked.documents) {
dom = checked.documents;
resData.goods = [];
// 打包商品信息
$.each(dom, function(key) {
var data = $(dom[key]).data(),
good = {
last_price: data.price,
goods_type: data.type,
product_skn: data.skn,
product_skc: data.skc,
product_sku: data.sku
};
if (isLack || !data.reason) {
isLack = true;
return;
} else {
good.returned_reason = data.reason;
// if (specialReason.hasOwnProperty(data.reason)) {
// remark: ,
// returned_reason: 3,
// evidence_images: ,
// }
}
resData.goods.push(good);
});
// 处理退款信息
if (payInfo) {
payment = {
return_amount_mode: payInfo.type
};
switch (payInfo.type) {
case 2:
payment.bank_name = payInfo.dom.find('.bank').val();
payment.bank_card = payInfo.dom.find('.account').val();
payment.payee_name = payInfo.dom.find('.name').val();
break;
case 3:
payment.alipay_account = payInfo.dom.find('.account').val();
payment.alipay_name = payInfo.dom.find('.name').val();
break;
default:
isLack = true;
break;
}
// 检查信息完整性
$.each(payment, function(key) {
if (!payment[key]) {
isLack = true;
}
});
resData.payment = payment;
}
}
if (isLack) {
return false;
}
return resData;
}
$check.check({
type: 'checkbox',
onChange: function() {
checked = $check.check('getChecked');
restApplyBtn();
}
});
$refundTable.on('change', '.refund-reason', function() {
var $this = $(this),
$specialDom = $this.parent().siblings('.special-reason'),
val = $this.val();
if (specialReason.hasOwnProperty(val)) {
$specialDom.slideDown();
} else {
$specialDom.slideUp();
}
$specialDom.siblings('.check').data({reason: val});
}).on('click', '.img-upload', function() {
var $this = $(this);
upload.up({
callback: function(result) {
if (result && result.code === 200) {
$this.before(imgFn(result));
}
}
});
});
$refundType.on('click', '.type-item', function() {
var $this = $(this),
index;
if (!$this.hasClass('cur')) {
if ($this.hasClass('ali-item')) {
payInfo.type = 3;
} else {
payInfo.type = 2;
}
index = $this.index();
// 切换退款卡片
$this.addClass('cur').siblings('.cur').removeClass('cur');
// 切换退款信息输入容器
payInfo.dom = $typeInfo.eq(index);
$typeInfo.addClass('hide');
payInfo.dom.removeClass('hide');
}
});
$applyBtn.click(function() {
var $tip = $applyBtn.siblings('.apply-tip'),
param = packApplyInfo();
if (!param) {
$tip.removeClass('hide');
return;
} else {
$tip.addClass('hide');
}
$.ajax({
type: 'POST',
url: '/me/return/refund/apply',
data: param,
success: function(data) {
if (data.code === 200) {
if (data.data && data.data.refer) {
location.href = data.data.refer;
}
$tip.text('申请成功').removeClass('hide');
}
}
});
});