purchaseCodeActions.js
2.91 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
'use strict';
import ReactNative from 'react-native';
import PurchaseCodeService from '../../services/PurchaseCodeService';
const {
GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
DELETE_MINE_LIMIT_PURCHASE_REQUEST,
DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
DELETE_MINE_LIMIT_PURCHASE_FAILURE,
} = require('../../constants/actionTypes').default;
export function MineLimitPurchaseListRequest() {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
};
}
export function MineLimitPurchaseListSuccess(json) {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
payload: json
}
}
export function MineLimitPurchaseListFailure(error) {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
payload: error
}
}
export function getMineLimitPurchaseList() {
return (dispatch, getState) => {
let {app, purchaseCode} = getState();
let fetchMineLimitPurchaseList = (uid) => {
dispatch(MineLimitPurchaseListRequest());
return new PurchaseCodeService(app.host).getMineLimitPurchaseList(uid)
.then(json => {
dispatch(MineLimitPurchaseListSuccess(json));
})
.catch(error => {
dispatch(MineLimitPurchaseListFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchMineLimitPurchaseList(uid);
})
.catch(error => {
});
};
}
export function DeleteMinePurchaseCodeLimitCodeRequest() {
return {
type: DELETE_MINE_LIMIT_PURCHASE_REQUEST,
};
}
export function DeleteMinePurchaseCodeLimitCodeSuccess(json) {
return {
type: DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
payload: json
}
}
export function DeleteMinePurchaseCodeLimitCodeFailure(error) {
return {
type: DELETE_MINE_LIMIT_PURCHASE_FAILURE,
payload: error
}
}
export function deleteMinePurchaseCodeLimitCode(data) {
return (dispatch, getState) => {
let {app, purchaseCode} = getState();
let limitCode = data.limitCode;
let fetchDeleteMinePurchaseCodeLimitCode = (uid) => {
let res = parseMinePurchaseCodeLimitCode(data,purchaseCode?purchaseCode.toJS():'')
dispatch(DeleteMinePurchaseCodeLimitCodeSuccess(res));
return new PurchaseCodeService(app.host).deleteMinePurchaseCodeLimitCode(uid,limitCode)
.then(json => {
})
.catch(error => {
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchDeleteMinePurchaseCodeLimitCode(uid);
})
.catch(error => {
});
};
}
function parseMinePurchaseCodeLimitCode (data,purchaseCode) {
let invalidLimitCodeProducts = purchaseCode?purchaseCode.invalidLimitCodeProducts:[];
let index = -1;
for (var i = 0; i < invalidLimitCodeProducts.length; i++) {
let item = invalidLimitCodeProducts[i];
if (item.limitCode == data.limitCode) {
index = i;
}
}
if (index != -1) {
invalidLimitCodeProducts.splice( index, 1 );
}
return invalidLimitCodeProducts;
}