Authored by 孙凯

add 获取 bannerresource 数据 显示 review by 红魔

... ... @@ -48,18 +48,28 @@ export default class Brand extends Component {
renderHeader(){
let data = this.props.reourceForBoy;
let brandFliter = this.props.brandFliter;
let bannerForBoy = data.get('bannerForBoy');
let custom_brandsForBoy = data.get('custom_brandsForBoy');
let brandsTextForBoy = data.get('brandsTextForBoy');
let channelFliter = this.props.channelFliter;
if (channelFliter == 0) {
data = this.props.reourceForBoy;
} else if (channelFliter == 1) {
data = this.props.reourceForGirl;
} else if (channelFliter == 2) {
data = this.props.reourceForKid;
} else if (channelFliter == 3) {
data = this.props.reourceForLifeStyle;
}
let banner = data.get('banner');
let custom_brands = data.get('custom_brands');
let brandsText = data.get('brandsText');
return (
<View style={styles.header}>
<YH_SearchBar
/>
{bannerForBoy?<BrandSwiper resource={bannerForBoy} onPressSlideItem={this.props.onPressSlideItem}/>:null}
{custom_brandsForBoy?<BannerReourceList resource={custom_brandsForBoy} onPressSlideItem={this.props.onPressSlideItem}/>:null}
<BrandFliter dataSource={brandsTextForBoy} selectID={brandFliter} onPressFilter={this.props.onPressFilter}/>
<YH_SearchBar/>
{banner?<BrandSwiper resource={banner} onPressSlideItem={this.props.onPressSlideItem}/>:null}
{custom_brands?<BannerReourceList resource={custom_brands} onPressSlideItem={this.props.onPressSlideItem}/>:null}
{brandsText?<BrandFliter dataSource={brandsText} selectID={brandFliter} onPressFilter={this.props.onPressFilter}/>:null}
</View>
);
}
... ... @@ -94,6 +104,9 @@ export default class Brand extends Component {
brandListForKid,
brandListForLifeStyle,
reourceForBoy,
reourceForGirl,
reourceForKid,
reourceForLifeStyle,
} = this.props;
let data;
... ...
... ... @@ -47,6 +47,18 @@ export default keyMirror({
GETBRANDRESOURCE_FOR_BOY_SUCCESS: null,
GETBRANDRESOURCE_FOR_BOY_FAILURE: null,
GETBRANDRESOURCE_FOR_GIRL_REQUEST: null,
GETBRANDRESOURCE_FOR_GIRL_SUCCESS: null,
GETBRANDRESOURCE_FOR_GIRL_FAILURE: null,
GETBRANDRESOURCE_FOR_KID_REQUEST: null,
GETBRANDRESOURCE_FOR_KID_SUCCESS: null,
GETBRANDRESOURCE_FOR_KID_FAILURE: null,
GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST: null,
GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS: null,
GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE: null,
SET_BRAND_FILTER: null,
SET_CHANNEL_FILTER: null,
... ...
... ... @@ -72,6 +72,7 @@ class BrandContainer extends Component {
_onChannelPressFliter(value){
this.props.actions.getBrandList(value);
this.props.actions.getBrandResource(value);
this.props.actions.setChannelFilter(value);
}
... ... @@ -84,6 +85,9 @@ class BrandContainer extends Component {
brandListForKid,
brandListForLifeStyle,
reourceForBoy,
reourceForGirl,
reourceForKid,
reourceForLifeStyle,
} = this.props.brand;
return (
<View style={styles.container}>
... ... @@ -95,6 +99,9 @@ class BrandContainer extends Component {
brandListForKid= {brandListForKid}
brandListForLifeStyle= {brandListForLifeStyle}
reourceForBoy= {reourceForBoy}
reourceForGirl={reourceForGirl}
reourceForKid={reourceForKid}
reourceForLifeStyle={reourceForLifeStyle}
onPressFilter= {this._onPressFilter}
onPressSlideItem= {this._onPressSlideItem}
onChannelPressFliter={this._onChannelPressFliter}
... ...
... ... @@ -29,6 +29,19 @@ const {
GETBRANDRESOURCE_FOR_BOY_SUCCESS,
GETBRANDRESOURCE_FOR_BOY_FAILURE,
GETBRANDRESOURCE_FOR_GIRL_REQUEST,
GETBRANDRESOURCE_FOR_GIRL_SUCCESS,
GETBRANDRESOURCE_FOR_GIRL_FAILURE,
GETBRANDRESOURCE_FOR_KID_REQUEST,
GETBRANDRESOURCE_FOR_KID_SUCCESS,
GETBRANDRESOURCE_FOR_KID_FAILURE,
GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST,
GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS,
GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE,
} = require('../../constants/actionTypes').default;
... ... @@ -184,47 +197,137 @@ export function getBrandResourceForBoyFailure(error) {
}
}
export function getBrandResourceForGirlRequest() {
return {
type: GETBRANDRESOURCE_FOR_GIRL_REQUEST,
};
}
export function getBrandResourceForGirlSuccess(json) {
return {
type: GETBRANDRESOURCE_FOR_GIRL_SUCCESS,
payload: json
}
}
export function getBrandResourceForGirlFailure(error) {
return {
type: GETBRANDRESOURCE_FOR_GIRL_FAILURE,
payload: error
}
}
export function getBrandResourceForKidRequest() {
return {
type: GETBRANDRESOURCE_FOR_KID_REQUEST,
};
}
export function getBrandResourceForKidSuccess(json) {
return {
type: GETBRANDRESOURCE_FOR_KID_SUCCESS,
payload: json
}
}
export function getBrandResourceForKidFailure(error) {
return {
type: GETBRANDRESOURCE_FOR_KID_FAILURE,
payload: error
}
}
export function getBrandResourceForLifeStyleRequest() {
return {
type: GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST,
};
}
export function getBrandResourceForLifeStyleSuccess(json) {
return {
type: GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS,
payload: json
}
}
export function getBrandResourceForLifeStyleFailure(error) {
return {
type: GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE,
payload: error
}
}
export function getBrandResource(channel) {
return (dispatch, getState) => {
let {app, classify} = getState();
dispatch(getBrandResourceForBoyRequest());
return new BrandService(app.serviceHost).getBrandResource()
let content_code;
if (channel == 0) {
dispatch(getBrandResourceForBoyRequest());
content_code = 'ce6ac059493ec26241a8cbe0bfa1b17a';
}else if (channel == 1) {
dispatch(getBrandResourceForGirlRequest());
content_code = 'dac99cdedc1f948e84c145aca561f7d2';
}else if (channel == 2) {
dispatch(getBrandResourceForKidRequest());
content_code = '713784f93f52bb1a7b93916b2bb15510';
}else if (channel == 3) {
dispatch(getBrandResourceForLifeStyleRequest());
content_code = 'f1aa914fd23cbcda71a87de6f5416c75';
}
return new BrandService(app.serviceHost).getBrandResource(content_code)
.then(json => {
let payload = parseResourceResources(json);
dispatch(getBrandResourceForBoySuccess(payload));
if (channel == 0) {
dispatch(getBrandResourceForBoySuccess(payload));
}else if (channel == 1) {
dispatch(getBrandResourceForGirlSuccess(payload));
}else if (channel == 2) {
dispatch(getBrandResourceForKidSuccess(payload));
}else if (channel == 3) {
dispatch(getBrandResourceForLifeStyleSuccess(payload));
}
})
.catch(error => {
dispatch(getBrandResourceForBoyFailure(error));
if (channel == 0) {
dispatch(getBrandResourceForBoyFailure(error));
}else if (channel == 1) {
dispatch(getBrandResourceForGirlFailure(error));
}else if (channel == 2) {
dispatch(getBrandResourceForKidFailure(error));
}else if (channel == 3) {
dispatch(getBrandResourceForLifeStyleFailure(error));
}
});
};
}
export function parseResourceResources(json) {
let bannerForBoy = [];
let custom_brandsForBoy = [];
let brandsTextForBoy = [];
let banner = [];
let custom_brands = [];
let brandsText = [];
brandsTextForBoy.push({key: 'default',name: '全部品牌'});
brandsText.push({key: 'default',name: '全部品牌'});
for (var i = 0; i < json.length; i++) {
if (json[i].template_name == 'focus') {
bannerForBoy = json[i];
banner = json[i];
}
if (json[i].template_name == 'custom_brands') {
custom_brandsForBoy = json[i];
custom_brands = json[i];
}
if (json[i].template_name == 'text') {
let data = json[i].data;
let template_id = json[i].template_id;
let text = data.text;
brandsTextForBoy.push({key: template_id,name: text});
brandsText.push({key: template_id,name: text});
}
}
return {
bannerForBoy,
custom_brandsForBoy,
brandsTextForBoy,
banner,
custom_brands,
brandsText,
};
}
... ...
... ... @@ -26,9 +26,24 @@ let InitialState = Record({
new_list: List(),
})),
reourceForBoy: new (Record({
bannerForBoy: Map(),
custom_brandsForBoy: Map(),
brandsTextForBoy: List(),
banner: Map(),
custom_brands: Map(),
brandsText: List(),
})),
reourceForGirl: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
})),
reourceForKid: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
})),
reourceForLifeStyle: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
})),
});
... ...
... ... @@ -29,6 +29,18 @@ const {
GETBRANDRESOURCE_FOR_BOY_SUCCESS,
GETBRANDRESOURCE_FOR_BOY_FAILURE,
GETBRANDRESOURCE_FOR_GIRL_REQUEST,
GETBRANDRESOURCE_FOR_GIRL_SUCCESS,
GETBRANDRESOURCE_FOR_GIRL_FAILURE,
GETBRANDRESOURCE_FOR_KID_REQUEST,
GETBRANDRESOURCE_FOR_KID_SUCCESS,
GETBRANDRESOURCE_FOR_KID_FAILURE,
GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST,
GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS,
GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -134,19 +146,83 @@ export default function brandReducer(state=initialState, action) {
case GETBRANDRESOURCE_FOR_BOY_SUCCESS:
{
let {
bannerForBoy,
custom_brandsForBoy,
brandsTextForBoy,
banner,
custom_brands,
brandsText,
} = action.payload;
return state.setIn(['reourceForBoy', 'bannerForBoy'], Immutable.fromJS(bannerForBoy))
.setIn(['reourceForBoy', 'custom_brandsForBoy'], Immutable.fromJS(custom_brandsForBoy))
.setIn(['reourceForBoy', 'brandsTextForBoy'], Immutable.fromJS(brandsTextForBoy))
return state.setIn(['reourceForBoy', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForBoy', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForBoy', 'brandsText'], Immutable.fromJS(brandsText))
}
case GETBRANDRESOURCE_FOR_BOY_FAILURE:
{
return state;
}
case GETBRANDRESOURCE_FOR_GIRL_REQUEST:
{
return state;
}
case GETBRANDRESOURCE_FOR_GIRL_SUCCESS:
{
let {
banner,
custom_brands,
brandsText,
} = action.payload;
return state.setIn(['reourceForGirl', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForGirl', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForGirl', 'brandsText'], Immutable.fromJS(brandsText))
}
case GETBRANDRESOURCE_FOR_GIRL_FAILURE:
{
return state;
}
case GETBRANDRESOURCE_FOR_KID_REQUEST:
{
return state;
}
case GETBRANDRESOURCE_FOR_KID_SUCCESS:
{
let {
banner,
custom_brands,
brandsText,
} = action.payload;
return state.setIn(['reourceForKid', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForKid', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForKid', 'brandsText'], Immutable.fromJS(brandsText))
}
case GETBRANDRESOURCE_FOR_KID_FAILURE:
{
return state;
}
case GETBRANDRESOURCE_FOR_LIFESTYLE_REQUEST:
{
return state;
}
case GETBRANDRESOURCE_FOR_LIFESTYLE_SUCCESS:
{
let {
banner,
custom_brands,
brandsText,
} = action.payload;
return state.setIn(['reourceForLifeStyle', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForLifeStyle', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForLifeStyle', 'brandsText'], Immutable.fromJS(brandsText))
}
case GETBRANDRESOURCE_FOR_LIFESTYLE_FAILURE:
{
return state;
}
}
return state;
... ...
... ... @@ -29,7 +29,7 @@ export default class BrandService {
});
}
async getBrandResource(content_code='ce6ac059493ec26241a8cbe0bfa1b17a',fromPage='iFP_Brand'){
async getBrandResource(content_code,fromPage='iFP_Brand'){
return await this.api.post({
url: '/operations/api/v5/resource/get',
body: {
... ...