talentRankActions.js
1.72 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
'use strict';
import ReactNative from 'react-native';
import Service from '../../services/TalentRankService';
const {
TALENT_RANK_REQUEST,
MONTH_RANK_SUCCESS,
TOTAL_RANK_SUCCESS,
TALENT_RANK_FAILURE
} = require('../../constants/actionTypes').default;
export function talentRankRequest() {
return {
type: TALENT_RANK_REQUEST
}
}
export function monthRankSuccess(json) {
return {
type: MONTH_RANK_SUCCESS,
payload: json
}
}
export function talentRankFailue(error) {
return {
type: TALENT_RANK_FAILURE,
payload: error
}
}
export function totalRankSuccess(json) {
return {
type: TOTAL_RANK_SUCCESS,
payload: json
}
}
export function fetchTalentRank(params) {
return async (dispatch, getState) => {
let uid = await ReactNative.NativeModules.YH_CommonHelper.uid();
let { app: { host }, talentRank } = getState();
let { type, page, pageSize } = params;
let originRank = talentRank.get(type == 1 ? 'monthRank' : 'totalRank').toJS();
!page && (params.page = originRank.rankList.page + 1) //如果page不存在 就是请求下一页
if (params.page > originRank.rankList.totalPage) {
let a = 1;
return
}
!pageSize && (params.pageSize = 10)
dispatch(talentRankRequest());
let data;
try {
data = await new Service(host).fetchTalentRank({uid, ...params});
} catch(error) {
dispatch(talentRankFailue(error));
}
data.rankList && (data.rankList.list = originRank.rankList.list.concat(data.rankList.list))
type == 1 ? dispatch(monthRankSuccess(data)) : dispatch(totalRankSuccess(data));
}
}