|
|
const initailData = () => ({
|
|
|
page: 1,
|
|
|
pageSize: 10,
|
|
|
pagetotal: 0,
|
|
|
orderList: [], // 订单列表
|
|
|
// scroll 组件参数,是否触发上拉事件
|
|
|
pullUpLoad: true,
|
|
|
|
|
|
// 当前查询订单状态
|
|
|
currentStatus: null,
|
|
|
routeParamStatus: null,
|
|
|
isShowEmpty: false,
|
|
|
});
|
|
|
import {
|
|
|
buyerOrderStatusList,
|
|
|
sellerOrderStatusList,
|
|
|
orderStatusKey,
|
|
|
ownType,
|
|
|
} from "constants/order-constants";
|
|
|
|
|
|
function initialOrderState() {
|
|
|
return {
|
|
|
page: 1,
|
|
|
pageSize: 10,
|
|
|
pagetotal: 0,
|
|
|
orderList: [], // 订单列表
|
|
|
// scroll 组件参数,是否触发上拉事件
|
|
|
pullUpLoad: true,
|
|
|
isShowEmpty: 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,
|
|
|
|
|
|
// 当前查询订单状态
|
|
|
currentStatus: null,
|
|
|
routeParamStatus: null,
|
|
|
};
|
|
|
};
|
|
|
|
|
|
export default function() {
|
|
|
return {
|
|
|
namespaced: true,
|
|
|
modules: {},
|
|
|
state: initailData,
|
|
|
state: initialState,
|
|
|
mutations: {
|
|
|
setOrderList(state, res) {
|
|
|
setOrderList(state, {res, owner, status}) {
|
|
|
let { page, pagetotal, data = [] } = res;
|
|
|
const orderState = state.orderListByType[orderStatusKey(owner, status)];
|
|
|
|
|
|
state.isShowEmpty = page === 1 && data.length === 0;
|
|
|
state.page = ++page;
|
|
|
state.pagetotal = pagetotal;
|
|
|
state.orderList = state.orderList.concat(data);
|
|
|
orderState.isShowEmpty = page === 1 && data.length === 0;
|
|
|
orderState.page = ++page;
|
|
|
orderState.pagetotal = pagetotal;
|
|
|
orderState.orderList = orderState.orderList.concat(data);
|
|
|
|
|
|
// 分页结束
|
|
|
if (page > pagetotal) {
|
|
|
state.pullUpLoad = false;
|
|
|
orderState.pullUpLoad = false;
|
|
|
}
|
|
|
},
|
|
|
filterOrderList(state, orderCode) {
|
|
|
state.orderList = state.orderList.filter(
|
|
|
filterOrderList(state, {orderCode, owner, status}) {
|
|
|
const orderState = state.orderListByType[orderStatusKey(owner, status)];
|
|
|
|
|
|
orderState.orderList = orderState.orderList.filter(
|
|
|
order => order.orderCode !== orderCode,
|
|
|
);
|
|
|
state.isShowEmpty = state.orderList.length === 0;
|
|
|
orderState.isShowEmpty = orderState.orderList.length === 0;
|
|
|
},
|
|
|
setOrderStatus(state, currentStatus) {
|
|
|
state.currentStatus = +currentStatus;
|
...
|
...
|
@@ -43,22 +70,18 @@ export default function() { |
|
|
setRouteParamStatus(state, status = 1) {
|
|
|
state.routeParamStatus = +status;
|
|
|
},
|
|
|
resetPartialData(state) {
|
|
|
state.page = 1;
|
|
|
state.orderList = [];
|
|
|
state.pagetotal = 0;
|
|
|
state.pullUpLoad = true;
|
|
|
resetPartialData(state, {owner, status}) {
|
|
|
Object.assign(state.orderListByType[orderStatusKey(owner, status)], {
|
|
|
page: 1,
|
|
|
orderList: [],
|
|
|
pagetotal: 0,
|
|
|
pullUpLoad: true,
|
|
|
});
|
|
|
},
|
|
|
resetData(state) {
|
|
|
const s = initailData();
|
|
|
const keyList = Object.keys(s);
|
|
|
const keyBlackList = ['currentStatus', 'routeParamStatus'];
|
|
|
|
|
|
for (const key of keyList) {
|
|
|
if (!keyBlackList.includes(key)) {
|
|
|
state[key] = s[key];
|
|
|
}
|
|
|
}
|
|
|
resetData(state, {owner, status}) {
|
|
|
const orderListState = initialOrderState();
|
|
|
|
|
|
state.orderListByType[orderStatusKey(owner, status)] = orderListState;
|
|
|
},
|
|
|
},
|
|
|
actions: {
|
...
|
...
|
@@ -71,22 +94,17 @@ export default function() { |
|
|
* }
|
|
|
* r
|
|
|
*/
|
|
|
async fetchOrderList(
|
|
|
{
|
|
|
commit,
|
|
|
state: { page, currentStatus, routeParamStatus },
|
|
|
},
|
|
|
param = {},
|
|
|
) {
|
|
|
const { owner } = param;
|
|
|
async fetchOrderList({commit, state}, { owner, status }) {
|
|
|
const { page } = state.orderListByType[orderStatusKey(owner, status)];
|
|
|
|
|
|
const res = await this.$api.get('/api/order/list', {
|
|
|
tabType: owner,
|
|
|
type: currentStatus || routeParamStatus || 1, // 1表示我的订单全部
|
|
|
type: status,
|
|
|
page,
|
|
|
});
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
commit('setOrderList', res.data);
|
|
|
commit('setOrderList', { res: res.data, owner, status});
|
|
|
}
|
|
|
},
|
|
|
|
...
|
...
|
@@ -97,7 +115,7 @@ export default function() { |
|
|
* owner: 订单来源 buy | sell
|
|
|
* } param1
|
|
|
*/
|
|
|
async deleteOrder({ commit }, { orderCode, owner }) {
|
|
|
async deleteOrder({ commit }, { orderCode, owner, status }) {
|
|
|
// owner: ownType
|
|
|
const res = await this.$api.get(`/api/${owner}/order/delete`, {
|
|
|
orderCode,
|
...
|
...
|
@@ -107,7 +125,7 @@ export default function() { |
|
|
// data 为true时删除成功
|
|
|
if (code === 200) {
|
|
|
if (data) {
|
|
|
commit('filterOrderList', orderCode);
|
|
|
commit('filterOrderList', {orderCode, owner, status});
|
|
|
}
|
|
|
}
|
|
|
return data;
|
...
|
...
|
@@ -157,8 +175,6 @@ export default function() { |
|
|
orderCode,
|
|
|
});
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
return res.code === 200 ? res.data : null;
|
|
|
},
|
|
|
|
...
|
...
|
@@ -172,8 +188,6 @@ export default function() { |
|
|
},
|
|
|
);
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
return res.code === 200 ? res.data : res.message || '';
|
|
|
},
|
|
|
|
...
|
...
|
@@ -183,7 +197,6 @@ export default function() { |
|
|
orderCode: `${orderCode}`,
|
|
|
price: +price,
|
|
|
});
|
|
|
console.log(res);
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
return { errMsg: '', isOk: true , bidData: res.data};
|
...
|
...
|
@@ -192,6 +205,5 @@ export default function() { |
|
|
}
|
|
|
},
|
|
|
},
|
|
|
getters: {},
|
|
|
};
|
|
|
} |
...
|
...
|
|