order-block.js
5.45 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
/**
* 订单
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/2/17
*/
var $ = require('yoho.jquery');
var Handlebars = require('yoho.handlebars');
var dialog = require('../common/dialog');
var Dialog = dialog.Dialog;
var Confirm = dialog.Confirm;
var $tpl = $('#cancel-dialog-tpl');
var deleteDialog = '<div class="order-delete-confirm">' +
'<div class="header">' +
'<p>删除订单</p>' +
'<a href="javascript:;" title="关闭"></a>' +
'</div>' +
'<div class="body">' +
'<p class="confirm-tip"><i class="icon-doubt"></i>{{deleteMessage}}</p>' +
'<p class="delete-tip">{{deleteTip}}</p>' +
'</div>' +
'</div>';
var html = $tpl.html();
var active;
function cancelFactory(id) {
var options = {
mask: false,
btns: [
{
id: 'cancel-sure',
name: '确定并取消订单',
btnClass: ['cancel-sure'],
cb: function () {
var $checked = $('.cancel-dialog :checked');
var $tip = $('.cancel-dialog .cancel-tip');
if ($checked.length === 0) {
$tip.html('请选择要取消订单的原因');
return;
}
$.ajax({
type: 'POST',
url: '/home/orders/cancelorder',
data: {
orderCode: id,
reason: $checked.val()
}
}).then(function (data) {
if (data.code === 200) {
active.close();
history.go(0);
} else {
$tip.html(data.message);
}
});
}
},
{
id: 'cancel-no',
name: '取消',
btnClass: ['cancel-no'],
cb: function () {
active.close();
}
}
],
content: html,
className: 'cancel-dialog'
};
return new Dialog(options);
}
$tpl.remove();
//查看物流
$('.check-logistics').click(function () {
$(this).siblings('.logistics').removeClass('hide');
});
$('.close-logistics').click(function () {
$(this).closest('.logistics').addClass('hide');
});
//订单列表&订单详情【取消订单和确认收货】
$('.me-orders, .order-detail').on('click', '.cancel-order', function (e) {
//取消订单
active = cancelFactory($(this).closest('.order, .order-detail').data('id'));
active.show();
}).on('click', '.confirm-received', function (e) {
var id = $(this).closest('.order, .order-detail').data('id');
//确认收货
active = new Confirm({
cb: function () {
$.ajax({
type: 'POST',
url: '/home/orders/confirmorder',
data: {
orderCode: id
}
}).then(function (data) {
if (data.code === 200) {
active.close();
history.go(0);
}
});
},
content: '您确定要确认收货吗?'
});
active.show();
}).on('click', '.order-delete', function () {
var id = $(this).closest('.order, .order-detail').data('id');
active = deleteOrder(id, this);
active.show();
});
function deleteOrder(id, obj) {
// 是否为彻底删除
var isFullyDelete = true;
var $order = $(obj).parents(".order");
var deleteMessage = isFullyDelete ? "您确定要永久删除订单吗?" : "您确定要删除订单吗?";
var deleteTip = isFullyDelete ? "永久删除后,订单将无法恢复,您将无法对该订单的商品申请售后服务,请谨慎操作。" : "删除后,您可以在订单回收站找回该订单,也可以做永久删除。";
var insert = Handlebars.compile(deleteDialog);
var html = insert({deleteMessage: deleteMessage, deleteTip: deleteTip});
var options = {
mask: false,
btns: [
{
id: 'delete-sure',
name: '确定',
btnClass: ['delete-sure'],
cb: function () {
$.ajax({
type: 'POST',
url: '/home/orders/delOrder',
data: {
orderCode: id,
isFullyDelete: isFullyDelete,
}
}).then(function (data) {
if (data.code === 200) {
active.close();
$order.remove();
location.reload();
}else{
active.close();
new dialog.Alert(data.message).show();
}
});
}
},
{
id: 'delete-no',
name: '取消',
btnClass: ['delete-no'],
cb: function () {
active.close();
}
}
],
content: html,
className: 'delete-dialog',
};
return new Dialog(options);
}