order-handle.js
2.82 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
import wx from '../../../utils/wx';
import orderModel from '../../../models/home/order';
import { wechatPay } from '../../../utils/wechat-pay';
const REASON_CACHE_KEY = 'refund_reason_cache';
let app = getApp();
let router = global.router;
export default {
deleteOrder(orderCode, callback) {
if (!orderCode) {
return;
}
wx.showModal({
title: '确认删除该订单吗?',
content: '删除了的订单不可恢复!',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000'
}).then(res => {
if (res.confirm) {
orderModel.delOrder({order_code: orderCode}).then(json => {
callback && callback(json);
});
}
});
},
confirmReceive(orderCode, callback) {
if (!orderCode) {
return;
}
wx.showModal({
title: '确认收货',
content: '请您收到货后再点击“确认”!',
cancelText: '取消',
confirmText: '确定',
confirmColor: '#FF0000'
}).then(res => {
if (res.confirm) {
orderModel.confirmReceive({order_code: orderCode, miniapp_type: app.getMiniappType()}).then(json => {
callback && callback(json);
});
}
});
},
cancelOrder(orderCode, callback) {
if (!orderCode) {
return;
}
wx.showModal({
title: '取消订单',
content: '确认取消该订单吗?',
cancelText: '返回',
confirmText: '取消订单',
confirmColor: '#000000'
}).then(res => {
if (res.confirm) {
orderModel.cancelOrder({order_code: orderCode}).then((json) => {
if (json.code !== 200) {
wx.showModal({title: json.message, showCancel: false});
}
callback && callback(json);
});
}
});
},
expressDetail(orderCode) {
if (!orderCode) {
return;
}
router.go('orderExpress', {order_code: orderCode});
},
payNow(data, callback) {
if (!data.order_code) {
return;
}
wechatPay(data, callback);
},
refundNow(orderCode, reason, callback) {
orderModel.refundOrder({
order_code: orderCode,
reason_id: reason.reason_id,
reason: reason.reason,
fromPage: 'aFP_MineOrderContent'
}).then(json => {
callback && callback(json);
});
},
getRefundReason(callback) {
let reason;
try {
reason = wx.getStorageSync(REASON_CACHE_KEY);
if (reason) {
reason = JSON.parse(reason);
}
} catch (e) {
console.log(JSON.stringify(e));
}
if (reason) {
return callback && callback(reason);
}
orderModel.getRefundSeason().then(res => {
if (res.code === 200) {
wx.setStorage({
key: REASON_CACHE_KEY,
data: JSON.stringify(res.data)
});
return callback && callback(res.data);
}
});
},
};