Authored by 王海元

会员礼包增加猜你喜欢 -- review by 孙凯

... ... @@ -12,31 +12,77 @@ import {
TouchableOpacity,
} from 'react-native';
import {Map} from 'immutable';
import {Immutable, Map} from 'immutable';
import ReceiveGiftAlert from './ReceiveGiftAlert';
import ProductListCell from '../../common/components/ListCell/ProductListCell';
export default class AssociatorGift extends Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
_renderRow(rowData, sectionID, rowID) {
let paddingLeft = rowID % 2 === 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
let customStyle = rowID === 0 || rowID === 1 ? {paddingLeft} : {paddingLeft};
return (
<ProductListCell
style={[styles.listContainer, customStyle]}
key={'row' + rowID}
rowID={rowID}
data={rowData}
onPressProduct={this.props.onPressProduct}
/>
);
}
render() {
let {
showGiftAlert,
productList
} = this.props;
let dataSource = productList.product_list.toArray();
return (
<View style={styles.container}>
<Text>aaaaa</Text>
<ReceiveGiftAlert showGiftAlert={showGiftAlert} hiddenGiftAlert={this.props.hiddenGiftAlert}/>
<ListView
ref={(c) => {
this.listView = c;
}}
yh_viewVisible = {true}
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(dataSource)}
renderRow={this._renderRow}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
let styles = StyleSheet.create({
container: {
flex: 1,
},
contentContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
},
listContainer: {
width: width / 2,
},
});
... ...
... ... @@ -7,4 +7,17 @@ export default keyMirror({
SET_CHANNEL: null,
SHOWGIFTALERT: null,
DISMISSGIFTALERT: null,
COUPONS_BAG_REQUEST: null,
COUPONS_BAG_SUCCESS: null,
COUPONS_BAG_FAILURE: null,
ASSOCIATORGIFT_PRODUCT_REQUEST: null,
ASSOCIATORGIFT_PRODUCT_SUCCESS: null,
ASSOCIATORGIFT_PRODUCT_FAILURE: null,
DRAW_COUPONS_BAG_REQUEST: null,
DRAW_COUPONS_BAG_SUCCESS: null,
DRAW_COUPONS_BAG_FAILURE: null,
});
... ...
... ... @@ -43,10 +43,11 @@ class AssociatorGiftContainer extends Component {
super(props);
this._displayGiftAlert = this._displayGiftAlert.bind(this);
this._hiddenGiftAlert = this._hiddenGiftAlert.bind(this);
this.onPressProduct = this.onPressProduct.bind(this);
}
componentDidMount() {
this.props.actions.getProductListForAssociatorGift();
}
componentWillUnmount() {
... ... @@ -61,17 +62,36 @@ class AssociatorGiftContainer extends Component {
this.props.actions.hiddenGiftAlert();
}
onPressProduct(product){
let productSkn = product && product.get('product_skn', 0);
let is_global = product && product.get('is_global', 'N');
if (!productSkn) {
return;
}
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`;
if (is_global === 'Y') {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalpurchase","params":{"skn":"${productSkn}"}}`;
}
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
render() {
let {
showGiftAlert,
productList
} = this.props.associatorGift;
return (
<AssociatorGift
showGiftAlert={showGiftAlert}
displayGiftAlert={this._displayGiftAlert}
hiddenGiftAlert={this._hiddenGiftAlert}
productList={productList}
onPressProduct={this.onPressProduct}
/>
);
}
... ...
'use strict';
import ReactNative from 'react-native';
import CouponService from '../../services/AssociatorGiftService';
import AssociatorGiftService from '../../services/AssociatorGiftService';
const Platform = require('Platform');
const {
SHOWGIFTALERT,
DISMISSGIFTALERT,
COUPONS_BAG_REQUEST,
COUPONS_BAG_SUCCESS,
COUPONS_BAG_FAILURE,
ASSOCIATORGIFT_PRODUCT_REQUEST,
ASSOCIATORGIFT_PRODUCT_SUCCESS,
ASSOCIATORGIFT_PRODUCT_FAILURE,
DRAW_COUPONS_BAG_REQUEST,
DRAW_COUPONS_BAG_SUCCESS,
DRAW_COUPONS_BAG_FAILURE,
} = require('../../constants/actionTypes').default;
... ... @@ -22,3 +35,130 @@ export function hiddenGiftAlert() {
type: DISMISSGIFTALERT,
}
}
export function couponsBagRequest() {
return {
type: COUPONS_BAG_REQUEST,
};
}
export function couponsBagSuccess(json) {
return {
type: COUPONS_BAG_SUCCESS,
payload: json
};
}
export function couponsBagFailure(error) {
return {
type: COUPONS_BAG_FAILURE,
payload: error
};
}
export function productListForAssociatorGiftRequest() {
return {
type: ASSOCIATORGIFT_PRODUCT_REQUEST,
}
}
export function productListForAssociatorGiftSuccess(json) {
return {
type: ASSOCIATORGIFT_PRODUCT_SUCCESS,
payload: json,
}
}
export function productListForAssociatorGiftFailure(error) {
return {
type: ASSOCIATORGIFT_PRODUCT_FAILURE,
payload: error
}
}
export function drawCouponsBagRequest() {
return {
type: DRAW_COUPONS_BAG_REQUEST,
};
}
export function drawCouponsBagSuccess(json) {
return {
type: DRAW_COUPONS_BAG_SUCCESS,
payload: json
};
}
export function drawCouponsBagFailure(error) {
return {
type: DRAW_COUPONS_BAG_FAILURE,
payload: error
};
}
export function getCouponsBagList() {
return (dispatch, getState) => {
let {app} = getState();
let fetchCouponsBag = (uid) => {
dispatch(couponsBagRequest());
return new AssociatorGiftService(app.host).fetchCouponsBagList(uid)
.then(json => {
dispatch(couponsBagSuccess(json));
})
.catch(error => {
dispatch(couponsBagFailure(error));
});
};
let uid = 0;
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchCouponsBag(uid)
})
.catch(error => {
fetchCouponsBag(uid)
});
};
}
export function getProductListForAssociatorGift() {
return (dispatch, getstate) => {
let {app} = getstate();
dispatch(productListForAssociatorGiftRequest());
return new AssociatorGiftService(app.host).fetchAssociatorGiftProductList()
.then(json => {
dispatch(productListForAssociatorGiftSuccess(json));
})
.catch(error => {
dispatch(productListForAssociatorGiftFailure(error));
});
}
}
export function getDrawCouponsBag() {
return (dispatch, getState) => {
let {app} = getState();
let fetchCouponsBag = (uid, couponsBagId) => {
dispatch(drawCouponsBagRequest());
return new AssociatorGiftService(app.host).fetchDrawCouponsBag(uid, couponsBagId)
.then(json => {
dispatch(drawCouponsBagSuccess(json));
})
.catch(error => {
dispatch(drawCouponsBagFailure(error));
});
};
let uid = 0;
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchCouponsBag(uid)
})
.catch(error => {
fetchCouponsBag(uid)
});
};
}
\ No newline at end of file
... ...
... ... @@ -4,6 +4,18 @@ import {Record, List, Map} from 'immutable';
let InitialState = Record({
showGiftAlert: false,
couponsBag: new (Record({
isFetching: false,
error: null,
couponsBag_list: List(),
})),
productList: new (Record({
isFetching: false,
error: null,
product_list: List(),
rec_id:'',
})),
});
export default InitialState;
... ...
... ... @@ -6,11 +6,17 @@ import Immutable, {Map} from 'immutable';
const {
SHOWGIFTALERT,
DISMISSGIFTALERT,
ASSOCIATORGIFT_PRODUCT_SUCCESS,
ASSOCIATORGIFT_PRODUCT_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function couponReducer(state=initialState, action) {
if (!(state instanceof InitialState)) {
return initialState.merge(state);
}
switch(action.type) {
case SHOWGIFTALERT: {
return state.set('showGiftAlert', true);
... ... @@ -18,6 +24,18 @@ export default function couponReducer(state=initialState, action) {
case DISMISSGIFTALERT: {
return state.set('showGiftAlert', false);
}
case ASSOCIATORGIFT_PRODUCT_SUCCESS: {
let {
product_list,
rec_id,
} = action.payload;
return state.setIn(['productList', 'product_list'], Immutable.fromJS(product_list))
.setIn(['productList', 'rec_id'], rec_id);
}
case ASSOCIATORGIFT_PRODUCT_FAILURE: {
return state.setIn(['productList', 'error'], Immutable.fromJS(action.payload));
}
}
return state;
... ...
... ... @@ -12,4 +12,55 @@ export default class AssociatorGiftService {
this.api = new Request(baseURL);
}
async fetchCouponsBagList(uid) {
return await this.api.get({
url: '',
body: {
uid,
method: 'app.giftBag.getCouponsBagList',
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchAssociatorGiftProductList() {
return await this.api.get({
url: '',
body: {
method: 'app.home.newPreference',
limit: 30,
rec_pos: 100004,
fromPage: 'AssociatorGift_RecommendProduct',
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchDrawCouponsBag(uid, couponsBagId) {
return await this.api.get({
url: '',
body: {
uid,
couponsBagId,
method: 'app.giftBag.drawCouponsBag',
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...