Authored by 张丽霞

明星原创店铺信息,review by 孙凯

... ... @@ -14,6 +14,10 @@ export default keyMirror({
SWITCH_SEGMENT: null,
SWITCH_GENDER: null,
BRAND_INFO_REQUEST: null,
BRAND_INFO_SUCCESS: null,
BRAND_INFO_FAILURE: null,
JUMP_WITH_URL: null,
});
... ...
... ... @@ -41,6 +41,9 @@ function mapDispatchToProps(dispatch) {
}
class DetailContainer extends Component {
componentDidMount() {
this.props.actions.getBrandInfo();
}
constructor(props) {
super(props);
}
... ...
'use strict';
import ReactNative from 'react-native';
import PlustarService from '../../services/DetailService';
import DetailService from '../../services/DetailService';
const {
BRAND_INFO_REQUEST,
BRAND_INFO_SUCCESS,
BRAND_INFO_FAILURE,
JUMP_WITH_URL
} = require('../../constants/actionTypes').default;
... ... @@ -19,3 +23,53 @@ export function jumpWithUrl(url) {
payload: url
};
}
export function brandInfoRequest(key) {
return {
type: BRAND_INFO_REQUEST,
payload: key
};
}
export function brandInfoSuccess(json) {
return {
type: BRAND_INFO_SUCCESS,
payload: json
};
}
export function brandInfoFailure(error) {
return {
type: BRAND_INFO_FAILURE,
payload: error
};
}
/*
* index number 请求数据的index
* reload bool 是否需要强制重新请求数据,
*/
export function getBrandInfo(brandId, reload = false) {
return (dispatch, getState) => {
let {app, detail} = getState();
let item = detail.get('brandInfo');
if (reload) {
// 强制刷新数据
} else {
if (item.isFetching) {
return;
}
}
dispatch(brandInfoRequest());
return new DetailService().getBrandInfo(brandId)
.then(json => {
console.log('----->>>>');
console.log(json);
dispatch(brandInfoSuccess(json));
})
.catch(error => {
dispatch(brandInfoFailure(error));
});
};
}
... ...
... ... @@ -4,6 +4,11 @@ import {Record, List, Map} from 'immutable';
let InitialState = Record({
isFetching: false,
brandInfo: new (Record({
isFetching: false,
detail: Map(),
error: null,
})),
});
export default InitialState;
... ...
... ... @@ -4,6 +4,10 @@ import InitialState from './detailInitialState';
import Immutable, {Map} from 'immutable';
const {
BRAND_INFO_REQUEST,
BRAND_INFO_SUCCESS,
BRAND_INFO_FAILURE,
JUMP_WITH_URL,
} = require('../../constants/actionTypes').default;
... ... @@ -11,8 +15,22 @@ const initialState = new InitialState;
export default function plustarReducer(state=initialState, action) {
switch(action.type) {
case JUMP_WITH_URL: {
case BRAND_INFO_REQUEST: {
return state.setIn(['brandInfo', 'isFetching'], true)
.setIn(['brandInfo', 'error'], null);
}
case BRAND_INFO_SUCCESS: {
return state.setIn(['brandInfo', 'detail'], Immutable.fromJS(action.payload))
.setIn(['brandInfo', 'isFetching'], false)
.setIn(['brandInfo', 'error'], null);
}
case BRAND_INFO_FAILURE: {
return state.setIn(['brandInfo', 'isFetching'], false)
.setIn(['brandInfo', 'error'], action.payload);
}
break;
break;
}
return state;
... ...
'use strict';
import Request from '../../common/services/Request';
export default class DetailService {
constructor () {
let baseURL = 'http://service.yoho.cn';
this.api = new Request(baseURL);
}
async getBrandInfo(id='153') {
return await this.api.get({
url: '/guang/api/v1/plustar/getbrandinfo',
body: {
id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...