order-list.js
6.25 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
import {
buyerOrderStatusList,
sellerOrderStatusList,
orderStatusKey,
ownType,
} from 'constants/order-constants';
function initialOrderState() {
return {
page: 1,
pageSize: 10,
pagetotal: 0,
orderList: [], // 订单列表
// scroll 组件参数,是否触发上拉事件
pullUpLoad: true,
isShowEmpty: false,
hasAction: false,
};
}
const initialState = () => {
const orderListByType = {};
[
[ownType.BUY, buyerOrderStatusList],
[ownType.SELL, sellerOrderStatusList],
].forEach(statusInfo => {
statusInfo[1].forEach(orderStatus => {
const key = orderStatusKey(statusInfo[0], orderStatus.value);
orderListByType[key] = initialOrderState();
});
});
return {
orderListByType,
isRefresh: true,
};
};
export default function() {
return {
namespaced: true,
state: initialState,
mutations: {
setIsRefresh(state, isRefresh) {
state.isRefresh = isRefresh;
},
setOrderList(state, { res, owner, status }) {
let { page, pagetotal, data = [] } = res;
const orderState = state.orderListByType[orderStatusKey(owner, status)];
orderState.isShowEmpty = page === 1 && data.length === 0;
orderState.page = ++page;
orderState.pagetotal = pagetotal;
orderState.orderList = orderState.orderList.concat(data);
// 分页结束
if (page > pagetotal) {
orderState.pullUpLoad = false;
}
},
filterOrderList(state, { orderCode, owner = ownType.SELL, status = 1 }) {
let orderState = state.orderListByType[orderStatusKey(owner, status)];
orderState.orderList = orderState.orderList.filter(
order => order.orderCode !== orderCode,
);
orderState.isShowEmpty = orderState.orderList.length === 0;
},
resetOrderListItem(state, { owner, status = 1, order }) {
let orderState = state.orderListByType[orderStatusKey(owner, status)];
orderState.orderList = orderState.orderList.map(item => {
if (item.orderCode === order.orderCode) {
const {
buttons = [],
statusDetail: { statuStr = '' } = {},
} = order;
// 详情接口取消时leftTime任返回值
const isIncludeDeleteAction = !!buttons.find(btn => {
return btn.code === 'del_order';
});
let { leftTime } = item;
leftTime = isIncludeDeleteAction ? 0 : leftTime;
item = { ...item, buttons, statuStr, leftTime };
}
return item;
});
},
setOrderStatus(state, currentStatus) {
state.currentStatus = +currentStatus;
},
setRouteParamStatus(state, status = 1) {
state.routeParamStatus = +status;
},
resetPartialData(state, { owner = ownType.SELL, status = 1 }) {
Object.assign(state.orderListByType[orderStatusKey(owner, status)], {
page: 1,
orderList: [],
pagetotal: 0,
pullUpLoad: true,
});
},
resetData(state, { owner = ownType.SELL, status = 1 }) {
const orderListState = initialOrderState();
state.orderListByType[orderStatusKey(owner, status)] = orderListState;
},
},
actions: {
/**
* 获取订单列表
* @param {*} param0 vue store context
* @param {
* owner: 订单来源
* status: 订单状态 默认全部
* }
* r
*/
async fetchOrderList(
{ commit, state },
{ owner = ownType.SELL, status = 1 },
) {
const { page } = state.orderListByType[orderStatusKey(owner, status)];
const res = await this.$api.post('/api/order/list', {
tabType: owner,
type: status,
page,
});
if (res.code === 200) {
commit('setOrderList', { res: res.data, owner, status });
}
},
/**
* 删除订单
* @param {
* orderCode: 订单编码
* owner: 订单来源 buy | sell
* } param1
*/
async deleteOrder(_, { orderCode, owner }) {
// owner: ownType
const res = await this.$api.get(`/api/${owner}/order/delete`, {
orderCode,
});
const { data } = res;
return data;
},
/**
* 取消订单
* 买家取消购买
* 卖家取消出售
* @param {
* orderCode: 订单编码
* owner: 订单来源 buy | sell
* } param1
*/
async cancelTrade(_, { orderCode, owner }) {
const res = await this.$api.get(`/api/${owner}/trade/cancel`, {
orderCode,
});
const isOk = res.code === 200 ? res.data : false;
return isOk;
},
/**
* 取消订单 提示信息
* 买家取消购买
* 卖家取消出售
* @param {
* orderCode: 订单编码
* owner: 订单来源 buy | sell
* } param1
*/
async cancelTradeConfirmInfo(_, { orderCode, owner }) {
const res = await this.$api.get(
`/api/${owner}/trade/cancel/confirm/info`,
{ orderCode },
);
return res.code === 200 ? res.data : null;
},
/**
* 确认收货
*/
async confirmReceipt(_, { orderCode }) {
const res = await this.$api.post('/api/buy/confirm/receipt', {
orderCode,
});
return res.code === 200 ? res.data : null;
},
// 买家调价计算
async computeChangePrice(_, { orderCode, price }) {
const res = await this.$api.get(
'/api/order/buyerask/computechangeprice',
{
orderCode: `${orderCode}`,
price: +price,
},
);
const { code, message } = res;
return code === 200 ? res : { code, message };
},
// 买家调价
async confirmChangePrice(_, { orderCode, price }) {
const res = await this.$api.post('/api/order/buyerask/changeprice', {
orderCode: `${orderCode}`,
price: +price,
});
if (res.code === 200) {
return { errMsg: '', isOk: true, bidData: res.data };
} else {
return { errMsg: res.message, isOk: false };
}
},
},
};
}