vipLevelActions.js
2.63 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
'use strict';
import ReactNative from 'react-native';
import {Platform} from 'react-native';
import VIPLevelService from '../../services/VIPLevelService';
import {Record, List, Map} from 'immutable';
const {
SET_NICKNAME,
FETCH_VIP_INFO_REQUEST,
FETCH_VIP_INFO_SUCCESS,
FETCH_VIP_INFO_FAILURE,
} = require('../../constants/actionTypes').default;
export function fetchVIPInfoRequest() {
return{
type: FETCH_VIP_INFO_REQUEST,
}
}
export function fetchVIPInfoSuccess(object) {
return{
type: FETCH_VIP_INFO_SUCCESS,
payload: object,
}
}
export function fetchVIPInfoFailure(error) {
return{
type: FETCH_VIP_INFO_FAILURE,
payload: error,
}
}
export function setNickname(nickname) {
return{
type: SET_NICKNAME,
payload: nickname,
}
}
export function fetchVIPInfo() {
return(dispatch, getState) => {
let {app, vipLevel} = getState();
let fetchVIP = (uid) => {
dispatch(fetchVIPInfoRequest());
return new VIPLevelService(app.host).getVIPInfo(uid)
.then(json => {
let vipShowPageInfo = processVIPInfo(json);
dispatch(fetchVIPInfoSuccess({
vipInfo: json,
upgradeNeedCost: vipShowPageInfo.upgradeNeedCost,
vipNextLevelProgress: vipShowPageInfo.vipNextLevelProgress,
}));
})
.catch(error => {
dispatch(fetchVIPInfoFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchVIP(uid);
})
.catch(error => {
fetchVIP(0);
});
}
}
function processVIPInfo(json) {
let upgradeNeedCost = 0.0;
let nextNeedCost = 0.0;
if (!json.upgrade_need_cost || json.upgrade_need_cost =='') {
upgradeNeedCost = 0.0;
} else {
upgradeNeedCost = parseFloat(json.upgrade_need_cost);
}
if (!json.next_need_cost || json.next_need_cost =='') {
nextNeedCost = 0.0;
} else {
nextNeedCost = parseFloat(json.next_need_cost);
}
let currentLevelCost = 0.0;
if (nextNeedCost - upgradeNeedCost >= 0) {
currentLevelCost = nextNeedCost - upgradeNeedCost;
}
let vipNextLevelProgress = 1.0;
if (nextNeedCost == 0.0) {
vipNextLevelProgress = 1.0;
}else{
vipNextLevelProgress = currentLevelCost/nextNeedCost;
}
return({upgradeNeedCost,vipNextLevelProgress})
}
export function onPressPrivilegeCell(cellInfo,rowID) {
return(dispatch, getState) => {
let {app, vipLevel} = getState();
let {vipInfo} =vipLevel;
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoVIPPrivilegeDetailPage({'id':cellInfo.get('id'),'current_vip_level':vipInfo.get('current_vip_level'),'title':cellInfo.get('title'),'rowID':rowID});
}
}
export function onPressAllVIPPrivilegeCell() {
return(dispatch, getState) => {
ReactNative.NativeModules.YH_PersonalInfoHelper.gotoAllVIPPrivilegePage();
}
}