order-action.js
7.99 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* eslint-disable operator-linebreak */
/* eslint-disable space-before-function-paren */
import { orderActionsMap, ownType } from 'constants/order-constants';
import { createNamespacedHelpers } from 'vuex';
import DialogConfirmInfo from '../components/dialog-confirm-info';
const { mapActions, mapMutations } = createNamespacedHelpers('order/orderList');
export default {
data() {
return {
// 求购调价
changePrice: 0,
};
},
methods: {
...mapActions([
'cancelTradeConfirmInfo',
'cancelTrade',
'deleteOrder',
'computeChangePrice',
'confirmChangePrice',
]),
...mapMutations(['filterOrderList', 'resetData', 'resetOrderListItem']),
async onAction({ action, order, isDetail = false } = {}) {
const { owner = ownType.SELL, type, status } = this.$route.params;
const {
orderCode,
realPrice = '',
bidDepositInfo = {},
goodsInfo = {},
priceInfo = {},
} = order;
switch (action.name) {
case orderActionsMap.DEL_ORDER.name: {
this.$createConfirmDialog({
content: '确认删除订单?',
confirmBtn: { style: { color: '#D0021B' } },
cancelBtn: { active: true },
onConfirm: async () => {
const isOk = await this.deleteOrder({
orderCode,
owner,
});
if (isOk) {
if (isDetail) {
this.filterOrderList({
orderCode,
owner,
status,
});
this.$router.back();
} else {
this.filterOrderList({
orderCode,
owner,
status,
});
}
}
const txt = isOk ? '删除成功' : '删除失败';
this.$createToast({ txt, type: 'txt' }).show();
},
}).show();
break;
}
case orderActionsMap.CANCEL_ORDER.name: {
let confirmInfo = await this.cancelTradeConfirmInfo({
orderCode,
owner,
});
if (Array.isArray(confirmInfo)) {
confirmInfo = { confirmDesc: '确定取消求购' };
}
const confirmBtnText = confirmInfo.needPenalty
? '赔付并取消订单'
: '取消订单';
this.$createConfirmDialog(
{
confirmBtn: { text: confirmBtnText, style: { color: '#D0021B' } },
cancelBtn: { text: '保留订单', active: true },
onConfirm: async () => {
const isOk = await this.cancelTrade({
orderCode,
owner,
});
if (isOk) {
if (isDetail) {
const newOrder = await this.fetchOrderDetail(
this.$route.params,
);
// 重置订单列表中数据
this.resetOrderListItem({
order: newOrder,
owner,
status: type,
});
} else {
this.resetData(this.$route.params);
this.fetchData(this.$route.params);
}
}
const txt = isOk ? '取消成功' : '取消失败';
this.$createToast({ txt, type: 'txt' }).show();
},
},
createElement => {
return [
createElement(DialogConfirmInfo, {
props: { info: confirmInfo },
slot: 'content',
}),
];
},
).show();
break;
}
case orderActionsMap.NOW_BUY.name: {
let price = realPrice,
pageBackName = 'OrderList';
if (isDetail) {
price = priceInfo.realPayPrice;
pageBackName = 'buyOrderDetail';
}
this.$createOrderPayType({
orderCode,
price: parseFloat(price || '').toFixed(2),
desc: '金额',
extra: JSON.stringify({
back: {
name: pageBackName,
params: {
owner,
orderCode,
},
},
reportType: 'buy',
}),
}).show();
break;
}
case orderActionsMap.PAY_DEPOSIT.name: {
// 是否是求购
const isAskForBuy = status === 7;
this.$createOrderPayType({
orderCode,
price: parseFloat(bidDepositInfo.depositAmount).toFixed(2),
desc: '支付定金',
extra: JSON.stringify({
forward: {
name: 'OrderList',
params: {
owner: 'buy',
},
},
reportType: isAskForBuy ? 'qiugou_buy' : 'buy',
}),
}).show();
break;
}
case orderActionsMap.CONFIRM_DELIVERY.name: {
this.$createConfirmDialog({
content: '确认收货?',
confirmBtn: { style: { color: '#D0021B' } },
cancelBtn: { active: true },
onConfirm: async () => {
const isOk = await this.confirmReceipt({
orderCode,
owner,
});
if (isOk) {
if (isDetail) {
this.fetchOrderDetail(this.$route.params);
} else {
this.resetData(this.$route.params);
this.fetchData(this.$route.params);
}
}
},
}).show();
break;
}
case orderActionsMap.CHANGE_BID_PRICE.name: {
const { goodPrice } = goodsInfo;
const { code, message, data } = await this.computeChangePrice({
orderCode,
price: goodPrice,
});
let isStr = false;
if (code !== 200) {
isStr = true;
this.$createToast({
type: 'alert',
txt: message,
mask: true,
}).show();
// 有未完成调价
if (code === 401) {
return;
}
}
let that = this;
this.$createChangeBidPriceDialog({
computePriceInfo: isStr ? { promotionFormulaList: [] } : data,
goodsInfo,
orderCode,
onCloseAction() {},
onConfirmAction: async price => {
const {
isOk,
errMsg = '',
bidData,
} = await that.confirmChangePrice({
price: price,
orderCode,
});
if (isOk) {
// 重新支付保证金
this.$createOrderPayType({
orderCode: bidData.orderCode,
price: parseFloat(bidData.depositAmount),
desc: '支付定金',
extra: JSON.stringify({
forward: {
name: isDetail ? 'buyOrderDetail' : 'OrderList',
params: isDetail
? {
owner: this.$route.params.owner,
code: bidData.orderCode, //改为新订单号
}
: this.$route.params,
},
reportType: 'buy',
}),
}).show();
} else {
if (errMsg) {
that
.$createToast({
type: 'alert',
txt: errMsg,
})
.show();
}
}
},
}).show();
break;
}
default:
return;
}
},
},
};