returns-detail.js
4.56 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
/**
* 退换货详情
* @author: yyqing<yanqing.yang@yoho.cn>
* @date: 2016/2/26
*/
var $ = require('yoho-jquery'),
Handlebars = require('yoho-handlebars'),
dialog = require('../common/dialog');
var $returnState = $('.visual-return-state li'),
$detail = $('.detail-container'),
$courierCode = $('.courier-code'),
$expressCompany = $('#express-company'),
$expressNumber = $('#express-number'),
$expressName = $('#express-name'),
$expressViewBox = $('.express-view-box > span');
var returnId = $('#return-id').val(),
expId = $('#express-old-id').val() === '' ? '0' : $('#express-old-id').val(),
expNumber = $expressNumber.val(),
expCompany = '',
expList = {},
isChange = false;
var Dialog = dialog.Dialog,
active,
cancelApplyDialog = '<p class="message-title"><i class="{{messageIcon}}"></i>{{messageTitle}}</p><p class="message-summary">{{messageSummary}}</p>'; // eslint-disable-line
function syncExpressInfo() {
expCompany = expList[expId] ? expList[expId] : '';
$expressViewBox.html(expCompany + ' 快递单号:' + expNumber);
$expressCompany.val(expId);
$expressNumber.val(expNumber);
}
// 其他快递公司需要填写物流
$expressCompany.on('change', function() {
if (+$(this).val() === 100) {
$expressName.removeClass('hide');
} else {
$expressName.addClass('hide');
}
});
function validateExpress() {
var send = {};
send.number = $expressNumber.val();
send.id = $expressCompany.val() * 1;
send.name = expList[send.id];
if (send.id === 100) {
send.name = $expressName.val();
}
if (!send.id) {
new dialog.Alert('请选择快递公司').show();
} else if (!send.name) {
new dialog.Alert('请填写快递公司').show();
} else if (!send.number) {
new dialog.Alert('请填入快递单号').show();
} else {
return send;
}
return false;
}
function sendExpressCode() {
var sendParm = validateExpress();
if (!sendParm) {
return;
}
$.ajax({
type: 'POST',
url: '/home/returns/setExpressNumber',
data: {
id: returnId,
isChange: isChange,
expressId: sendParm.id,
expressNumber: sendParm.number,
expressCompany: sendParm.name
}
}).then(function(jsonData) {
if (jsonData.code === 200) {
expId = sendParm.id;
expNumber = sendParm.number;
$returnState.eq(2).addClass('act');
} else {
new dialog.Alert(jsonData.message).show();
}
syncExpressInfo();
$courierCode.removeClass('in-edit');
});
}
function cancelApply(id, url) {
var template = Handlebars.compile(cancelApplyDialog); //eslint-disable-line
var html = template({messageIcon: 'icon-warn', messageTitle: '取消申请', messageSummary: '您确定要请取消申请吗?'}); //eslint-disable-line
var options = { //eslint-disable-line
mask: true,
btns: [
{
id: 'cancel-sure',
name: '确定',
btnClass: ['cancel-sure'],
cb: function() {
$.ajax({
type: 'POST',
url: url,
data: {
id: id
}
}).then(function(data) {
active.close();
if (data.code === 200) {
location.reload();
} else {
new dialog.Alert(data.message).show();
}
});
}
},
{
id: 'cancel-no',
name: '取消',
btnClass: ['cancel-no'],
cb: function() {
active.close();
}
}
],
content: html,
className: 'returns-cancel-dialog'
};
return new Dialog(options);
}
if ($detail.parent().hasClass('exchange-detail')) {
isChange = true;
}
$expressCompany.val(expId);
$detail.find('.company-list').each(function() {
var data = $(this).data();
expList[data.id] = data.name;
});
$('#modify').click(function() {
$courierCode.addClass('in-edit');
});
$('#submit-btn').click(function() {
sendExpressCode();
});
// 取消退换货
$('.cancel-trigger').click(function() {
active = cancelApply($(this).data('id'), $(this).data('url'));
active.show();
});