order-confirm.js
6.23 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
import { get, find, filter } from 'lodash';
export const Types = {
FETCH_ORDER_ADDRESS: 'FETCH_ORDER_ADDRESS',
FETCH_ORDER_USER_STATUS: 'FETCH_ORDER_USER_STATUS',
FETCH_ORDER_FEE: 'FETCH_ORDER_FEE',
CHANGE_PRICE: 'CHANGE_PRICE',
CHANGE_AGREE: 'CHANGE_AGREE',
FETCH_ORDER_BUY_ORDER: 'FETCH_ODER_BUY_ORDER',
FETCH_ORDER_COUPON_LIST: 'FETCH_ORDER_COUPON_LIST',
CHANGE_SELECT_COUPON_LIST: 'CHANGE_SELECT_COUPON_LIST',
CHANGE_SELECT_PROMOTION: 'CHANGE_SELECT_PROMOTION',
COMPUTE_ORDER: 'COMPUTE_ORDER',
UPDATE_ORDER: 'UPDATE_ORDER'
};
export const UserType = {
sell: 'sell',
buy: 'buy'
};
export default function() {
return {
namespaced: true,
state: {
address: {},
fee: {
income: '',
bankTransferFee: '',
platformFee: {
amount: '',
appraiseFee: '',
goodsPaymentRatePercent: '',
packageFee: '',
payChannelPercentage: '',
serviceFee: ''
}
},
alipayStatus: false,
userStatus: false,
price: '',
agree: false,
orderDetail: {},
selectedCouponList: [],
selectedPromotion: null,
couponList: []
},
mutations: {
[Types.FETCH_ORDER_ADDRESS](state, data) {
state.address = data;
},
[Types.FETCH_ORDER_FEE](state, data) {
state.fee = data;
},
[Types.CHANGE_PRICE](state, data) {
state.price = data;
},
[Types.CHANGE_AGREE](state, data) {
state.agree = data;
},
[Types.FETCH_ORDER_BUY_ORDER](state, data) {
state.orderDetail = data;
},
[Types.UPDATE_ORDER](state, { amount, couponInfo, couponList, promotionFormulaList, promotionList, promotionTips }) {
state.orderDetail.amount = amount;
state.orderDetail.promotionFormulaList = promotionFormulaList;
state.orderDetail.recommendedCouponInfo = couponInfo;
state.orderDetail.couponList = couponList;
state.orderDetail.promotionList = promotionList;
state.orderDetail.promotionTips = promotionTips;
},
[Types.CHANGE_SELECT_COUPON_LIST](state, { couponCode, couponType }) {
const item = find(get(state.orderDetail, 'couponList', []), { coupon_code: couponCode });
if (!item) {
return;
}
if (item.selected === 'Y') {
item.selected = 'N';
state.orderDetail.recommendedCouponInfo.coupon_code =
filter(get(state.orderDetail, 'couponList', []), { selected: 'Y' }).map(i => i.coupon_code).join(',');
} else {
filter(get(state.orderDetail, 'couponList', []), { coupon_type: couponType }).forEach(i => {
i.selected = 'N';
});
item.selected = 'Y';
state.orderDetail.recommendedCouponInfo.coupon_code =
filter(get(state.orderDetail, 'couponList', []), { selected: 'Y' }).map(i => i.coupon_code).join(',');
}
},
[Types.CHANGE_SELECT_PROMOTION](state, { promotionId }) {
const item = find(get(state.orderDetail, 'promotionList', []), { promotionId });
if (!item) {
return;
}
if (item.selected === 'Y') {
get(state.orderDetail, 'promotionList', []).forEach(i => {
i.selected = 'N';
});
state.orderDetail.promotionTips.promotionIds = '';
} else {
get(state.orderDetail, 'promotionList', []).forEach(i => {
i.selected = 'N';
});
item.selected = 'Y';
state.orderDetail.promotionTips.promotionIds = promotionId;
}
}
},
actions: {
async fetchOrderAddress({ commit, state }, payload) {
const orderCount = await this.$api.get('/api/order/confirm/count', payload);
if (state.address?.address_id) {
return;
}
if (get(orderCount, 'data.cnt', 0)) {
const addressInfo = await this.$api.get('/api/order/confirm/address');
const address = find(get(addressInfo, 'data', []), { is_default: 'Y' });
commit(Types.FETCH_ORDER_ADDRESS, address);
}
},
async fetchOrderPrice({ commit }, payload) {
const order = await this.$api.post('/api/order/confirm/compute', payload);
if (order.code !== 200) {
return {
error: order.message
};
}
commit(Types.FETCH_ORDER_FEE, order.data);
return order.data;
},
async fetchUserStatus() {
// const alipayStatus = await this.$api.get('/api/order/alipay/status');
// const userStatus = await this.$api.get('/api/order/user/status');
},
async submitOrder({ commit }, payload) {
return this.$api.post('/api/order/presubmit', payload);
},
async fetchPayList({ commit }, payload) {
return this.$api.post('/api/order/paytype', payload);
},
async fetchPayment({ commit }, { skup }) {
const orderInfo = await this.$api.post('/api/order/confirm/buypayment', { skup, api_version: 1 });
if (orderInfo.code !== 200) {
return orderInfo;
}
commit(Types.FETCH_ORDER_BUY_ORDER, orderInfo.data);
return orderInfo;
},
async computeOrder({ commit }, { skup, couponCode, addressId, promotionId }) {
const orderInfo = await this.$api.post('/api/order/confirm/buycompute', {
skup,
addressId,
coupon_code: couponCode,
promotionId,
depositRequirement: 'N'
});
if (orderInfo.code !== 200) {
return orderInfo;
}
commit(Types.UPDATE_ORDER, orderInfo.data);
return orderInfo;
},
async buyPayAction(ctx, { skup, couponCode, addressId, promotionId }) {
const order = await this.$api.post('/api/order/submit', {
skup,
addressId,
coupon_code: couponCode,
promotionId,
depositRequirement: 'N'
});
return order;
},
async payAction(ctx, { orderCode }) {
const payResult = await this.$api.post('/api/order/pay', {
orderCode,
payment: 2
});
if (payResult.code !== 200) {
return Promise.reject(payResult);
}
return payResult;
}
},
getters: {},
};
}