mine.js
7.18 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
import {parseAssetList, formatNumber, maskAccount} from '../../utils/mine-handler';
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
// const uid = '600046428';
const uid = '500031424';
const MINE_RESOURCE_CODE1 = '11a73219a63b50067d88e75c0fe04d10';
const MINE_RESOURCE_CODE2 = 'dc2731fbbebcba6329c74a379e9c41ec';
export default function() {
return {
namespaced: true,
state: {
animate: false,
timer: null,
rollNoticeList: [],
sellerNum: 0,
readyNum: 0,
sentNum: 0,
finishNum: 0,
failNum: 0,
favoriteNum: 0,
buyNum: 0,
askBuyNum: 0,
assetData: {
isFetching: false,
list: [],
currentPage: 1,
pageSize: 20,
endReached: false,
compensateIncome: '¥0.00',
goodsIncome: '¥0.00',
totalIncome: '¥0.00'
},
resource1: {},
resource2: {}
},
getters: {
getOrderNums(state) {
let orderSum = {
ready: {name: '待发货', num: state.readyNum, page: {name: 'OrderList', status: 0} },
sent: {name: '已发货', num: state.sentNum, page: {name: 'OrderList', status: 1}},
finish: {name: '交易成功', num: state.finishNum, page: {name: 'OrderList', status: 2}},
fail: {name: '交易失败', num: state.failNum, page: {name: 'OrderList', status: 3}}
};
return orderSum;
},
getMineList(state) {
let tabList = {
board: { title: '公告栏', page: 'noticeList'},
sale: { title: '出售中', num: state.sellerNum, page: ''},
order: {name: 'order'},
resource1: {name: 'resource1', data: state.resource1},
income: {title: '交易收入', num: state.assetData.totalIncome, page: 'tradeIncome'},
buyOrder: {title: '我购买的订单', num: state.buyNum, page: ''},
buy: {name: 'buy', title: '我的求购', num: state.askBuyNum, page: ''},
collect: {name: 'collect', title: '我的收藏', num: state.favoriteNum, page: 'favorite'},
resource2: {name: 'resource2', data: state.resource2}
};
return tabList;
}
},
mutations: {
addList(state, { list }) {
state.rollNoticeList = list;
},
startAnimate(state) {
state.animate = true;
},
setTimer(state, timer) {
state.timer = timer;
},
animateHandler(state) {
state.rollNoticeList.push(state.rollNoticeList[0]);
state.rollNoticeList.shift();
state.animate = false;
},
addSellerOrder(state, { orderSumList }) {
orderSumList.forEach((item) => {
switch (item.listType) {
case 1:
state.sellerNum = item.sum;
break;
case 2:
state.readyNum = item.sum;
break;
case 3:
state.sentNum = item.sum;
break;
case 5:
state.finishNum = item.sum;
break;
case 6:
state.failNum = item.sum;
break;
default:
break;
}
});
},
addFavoriteNum(state, {count}) {
state.favoriteNum = count;
},
addOrderSummary(state, {data}) {
data.forEach((item) => {
switch (item.actor) {
case 'buy':
state.buyNum = item.sum;
break;
case 'bid':
state.askBuyNum = item.sum;
break;
default:
break;
}
});
},
addAssets(state, assetData) {
assetData.totalIncome = formatNumber(assetData.totalIncome);
assetData.compensateIncome = formatNumber(assetData.compensateIncome);
assetData.goodsIncome = formatNumber(assetData.goodsIncome);
state.assetData = Object.assign({}, state.assetData, assetData);
},
assetFetching(state, {isFetching}) {
state.assetData.isFetching = isFetching;
},
addResource(state, {resource1 = {}, resource2 = {}}) {
state.resource1 = Object.assign({}, state.resource1, resource1);
state.resource2 = Object.assign({}, state.resource1, resource2);
}
},
actions: {
async fetchRollBoardList({ commit }) {
const result = await this.$api.get('/api/ufo/mine/rollBoardList', {});
if (result.code === 200) {
commit('addList', { list: result.data });
}
return result.data || [];
},
async showMarquee({ commit }) {
commit('startAnimate');
let timer = setTimeout(() => {
commit('animateHandler');
}, 500);
commit('setTimer', timer);
},
async hideMarquee({commit}) {
commit('setTimer', null);
},
async fetchResource({commit}) {
const result = await this.$api.get('/api/ufo/mine/resource', {
content_code: MINE_RESOURCE_CODE1,
uid
});
const result1 = await this.$api.get('/api/ufo/mine/resource', {
content_code: MINE_RESOURCE_CODE2,
uid
});
if (result.code === 200) {
let src = getImgUrl(get(result, 'data[0].data[0].src') || '', 1000, 240);
set(result, 'data[0].data[0].src', src);
commit('addResource', {resource1: result.data[0]});
}
if (result1.code === 200) {
let src = getImgUrl(get(result1, 'data[0].data[0].src') || '', 1000, 240);
set(result1, 'data[0].data[0].src', src);
commit('addResource', {resource2: result1.data[0]});
}
},
async fetchSellerOrder({ commit }) {
const result = await this.$api.get('/api/ufo/mine/seller/orderSummary', {uid});
if (result.code === 200) {
commit('addSellerOrder', { orderSumList: result.data });
}
},
async fetchFavoriteNum({ commit }) {
const result = await this.$api.get('/api/ufo/mine/favoriteNum', {uid});
if (result.code === 200) {
commit('addFavoriteNum', { count: result.data.product_favorite_total });
}
},
async fetchOrderSummary({ commit }) {
const result = await this.$api.get('/api/ufo/mine/order/summary', {uid});
if (result.code === 200) {
commit('addOrderSummary', { data: result.data});
}
},
async fetchAssets({ commit, state }, isRefresh) {
let {isFetching, endReached, currentPage, list, pageSize} = state.assetData;
if (isFetching || (!isRefresh && endReached)) {
return;
}
let oldList = isRefresh ? [] : list;
// commit('assetFetching', {isFetching: true});
let page = isRefresh ? 1 : currentPage + 1;
const result = await this.$api.get('/api/ufo/mine/assets', {page, limit: pageSize, uid});
// commit('assetFetching', {isFetching: false});
if (result.code === 200) {
let assetData = parseAssetList(result.data);
let newList = [...oldList, ...assetData.list];
assetData.list = newList;
if (typeof assetData.totalIncome !== 'undefined') {
commit('addAssets', assetData);
}
}
return result.data;
},
},
};
}