67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
import * as API from 'api/real/orders';
|
|
|
|
const state = {
|
|
real_orders: {},
|
|
cards: [],
|
|
selected: []
|
|
};
|
|
|
|
const mutations = {
|
|
SET_REAL_ORDERS(state, data) {
|
|
state.real_orders = data;
|
|
},
|
|
SET_CARDS(state, data) {
|
|
state.cards = data;
|
|
},
|
|
SET_REAL_ORDER_SELECTED(state, data) {
|
|
state.selected = data;
|
|
},
|
|
PUSH_REAL_ORDER_SELECTED(state, obj) {
|
|
state.selected.push(obj);
|
|
},
|
|
REMOVE_REAL_ORDER_SELECTED(state, orderId) {
|
|
let index = state.selected.findIndex(item => {
|
|
return item.id === orderId;
|
|
});
|
|
|
|
if (index !== -1) {
|
|
state.selected.splice(index, 1);
|
|
}
|
|
}
|
|
};
|
|
|
|
const actions = {
|
|
getOrders(context, params) {
|
|
API.index(params).then(res => {
|
|
if (res.code === 0) {
|
|
context.commit('SET_REAL_ORDERS', res.data);
|
|
}
|
|
});
|
|
},
|
|
getCards(context, params) {
|
|
return new Promise((resolve, reject) => {
|
|
API.cards(params).then(res => {
|
|
if (res.code === 0) {
|
|
let data = res.data.map(item => {
|
|
item.order_id = params.order_id;
|
|
return item;
|
|
});
|
|
|
|
context.commit('SET_CARDS', data);
|
|
resolve(data);
|
|
} else {
|
|
reject(res);
|
|
}
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
export default {
|
|
state,
|
|
mutations,
|
|
actions
|
|
};
|