in-sale-order-list.js
3.11 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
const initailData = () => ({
entryOrder: {
page: 1,
pageSize: 10,
pagetotal: 0,
list: [], // 订单列表
pullUpLoad: true,
},
notEntryOrder: {
page: 1,
pageSize: 10,
pagetotal: 0,
list: [], // 订单列表
pullUpLoad: true,
},
isShowEmpty: false,
});
export default function() {
return {
namespaced: true,
state: initailData,
mutations: {
setEntryOrder(state, res) {
let { page, pagetotal, data = [] } = res;
state.entryOrder.page = ++page;
state.entryOrder.pagetotal = pagetotal;
state.entryOrder.list = state.entryOrder.list.concat(data);
// 分页结束
if (page > pagetotal) {
state.entryOrder.pullUpLoad = false;
}
},
setNotEntryOrder(state, res) {
let { page, pagetotal, data = [] } = res;
state.isShowEmpty =
state.entryOrder.list.length === 0 && page === 1 && data.length === 0;
state.notEntryOrder.page = ++page;
state.notEntryOrder.pagetotal = pagetotal;
state.notEntryOrder.list = state.notEntryOrder.list.concat(data);
// 分页结束
if (page > pagetotal) {
state.notEntryOrder.pullUpLoad = false;
}
},
filterInSaleOrderList(state, orderCode) {
state.entryOrder.list = state.entryOrder.list.filter(
order => order.orderCode !== orderCode,
);
state.notEntryOrder.list = state.notEntryOrder.list.filter(
order => order.orderCode !== orderCode,
);
state.isShowEmpty =
state.entryOrder.list.length === 0 &&
state.notEntryOrder.list.length === 0;
},
resetData(state) {
const s = initailData();
Object.keys(s).forEach(key => {
state[key] = s[key];
});
},
},
getters: {
// scroll 组件参数,是否触发上拉事件
pullUpLoad: state =>
state.entryOrder.pullUpLoad || state.notEntryOrder.pullUpLoad,
orderList: state => {
const {
entryOrder: { list: entryOrderList },
notEntryOrder: { list: notEntryOrderList },
} = state;
return entryOrderList.concat(notEntryOrderList);
},
},
actions: {
async fetchEntryOrderList({ dispatch, commit, state: { entryOrder } }) {
const { page } = entryOrder;
const res = await this.$api.get('/api/ufo/seller/entryPrdList', {
page,
// TODO 注释type含义
type: 1,
});
if (res.code === 200) {
const { data } = res;
commit('setEntryOrder', data);
const { pagetotal } = data;
if (pagetotal === 0 || page > pagetotal) {
return dispatch('fetchNotEntryOrderList');
}
}
},
async fetchNotEntryOrderList({ commit, state: { notEntryOrder } }) {
const { page } = notEntryOrder;
const res = await this.$api.get('/api/ufo/seller/notEntryPrdList', {
page,
type: 1,
});
if (res.code === 200) {
commit('setNotEntryOrder', res.data);
}
},
},
};
}