detailActions.js
1.82 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
'use strict';
import ReactNative from 'react-native';
import DetailService from '../../services/DetailService';
import Immutable, {Map} from 'immutable';
const {
SET_ORDER_CODE,
GET_DETAIL_REQUEST,
GET_DETAIL_SUCCESS,
GET_DETAIL_FAILURE,
} = require('../../constants/actionTypes').default;
export function setOrderCode(order_code) {
return {
type: SET_ORDER_CODE,
payload: order_code,
};
}
export function getDetail() {
return (dispatch, getState) => {
let {app, detail} = getState();
let {order_code} = detail;
dispatch(getDetailRequest());
return new DetailService(app.host).getDetailWithOrderCode(order_code)
.then(json => {
//Get first product skn.
if (json.order_goods && json.order_goods.length) {
json.firstProductSKN = json.order_goods[0].product_skn;
}
//Get express type.
let type = 2;
if (json.express_detail && json.express_detail.length) {
let {accept_address, acceptTime} = json.express_detail[0];
type = acceptTime && accept_address ? 0 : 2;
json.acceptTime = acceptTime;
json.accept_address = accept_address;
} else if (json.express_number && json.express_number.length) {
type = 1;
}
json.expressType = type;
if (json.express_company) {
let {caption} = json.express_company;
json.expressName = caption;
}
// console.log(product_skn);
// console.log(json);
dispatch(getDetailSuccess(json));
})
.catch(error => {
dispatch(getDetailFailure(error));
});
};
}
export function getDetailRequest() {
return {
type: GET_DETAIL_REQUEST,
};
}
export function getDetailSuccess(json) {
return {
type: GET_DETAIL_SUCCESS,
payload: json
};
}
export function getDetailFailure(error) {
return {
type: GET_DETAIL_FAILURE,
payload: error
};
}