会员礼包增加猜你喜欢 -- review by 孙凯
Showing
7 changed files
with
304 additions
and
4 deletions
@@ -12,31 +12,77 @@ import { | @@ -12,31 +12,77 @@ import { | ||
12 | TouchableOpacity, | 12 | TouchableOpacity, |
13 | } from 'react-native'; | 13 | } from 'react-native'; |
14 | 14 | ||
15 | -import {Map} from 'immutable'; | 15 | +import {Immutable, Map} from 'immutable'; |
16 | import ReceiveGiftAlert from './ReceiveGiftAlert'; | 16 | import ReceiveGiftAlert from './ReceiveGiftAlert'; |
17 | +import ProductListCell from '../../common/components/ListCell/ProductListCell'; | ||
17 | 18 | ||
18 | export default class AssociatorGift extends Component { | 19 | export default class AssociatorGift extends Component { |
19 | constructor(props) { | 20 | constructor(props) { |
20 | super(props); | 21 | super(props); |
22 | + | ||
23 | + this._renderRow = this._renderRow.bind(this); | ||
24 | + | ||
25 | + this.dataSource = new ListView.DataSource({ | ||
26 | + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | ||
27 | + }); | ||
28 | + | ||
29 | + } | ||
30 | + | ||
31 | + _renderRow(rowData, sectionID, rowID) { | ||
32 | + let paddingLeft = rowID % 2 === 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal; | ||
33 | + let customStyle = rowID === 0 || rowID === 1 ? {paddingLeft} : {paddingLeft}; | ||
34 | + | ||
35 | + return ( | ||
36 | + <ProductListCell | ||
37 | + style={[styles.listContainer, customStyle]} | ||
38 | + key={'row' + rowID} | ||
39 | + rowID={rowID} | ||
40 | + data={rowData} | ||
41 | + onPressProduct={this.props.onPressProduct} | ||
42 | + /> | ||
43 | + ); | ||
21 | } | 44 | } |
22 | 45 | ||
23 | render() { | 46 | render() { |
24 | let { | 47 | let { |
25 | showGiftAlert, | 48 | showGiftAlert, |
49 | + productList | ||
26 | } = this.props; | 50 | } = this.props; |
27 | 51 | ||
52 | + let dataSource = productList.product_list.toArray(); | ||
53 | + | ||
28 | return ( | 54 | return ( |
29 | <View style={styles.container}> | 55 | <View style={styles.container}> |
30 | <Text>aaaaa</Text> | 56 | <Text>aaaaa</Text> |
31 | <ReceiveGiftAlert showGiftAlert={showGiftAlert} hiddenGiftAlert={this.props.hiddenGiftAlert}/> | 57 | <ReceiveGiftAlert showGiftAlert={showGiftAlert} hiddenGiftAlert={this.props.hiddenGiftAlert}/> |
58 | + <ListView | ||
59 | + ref={(c) => { | ||
60 | + this.listView = c; | ||
61 | + }} | ||
62 | + yh_viewVisible = {true} | ||
63 | + contentContainerStyle={styles.contentContainer} | ||
64 | + enableEmptySections={true} | ||
65 | + dataSource={this.dataSource.cloneWithRows(dataSource)} | ||
66 | + renderRow={this._renderRow} | ||
67 | + /> | ||
32 | </View> | 68 | </View> |
33 | ); | 69 | ); |
34 | } | 70 | } |
35 | }; | 71 | }; |
36 | 72 | ||
37 | let {width, height} = Dimensions.get('window'); | 73 | let {width, height} = Dimensions.get('window'); |
74 | +let rowWidth = Math.ceil(137.5 * width / 320); | ||
75 | +let rowMarginHorizontal = (width - rowWidth * 2) / 3; | ||
76 | + | ||
38 | let styles = StyleSheet.create({ | 77 | let styles = StyleSheet.create({ |
39 | container: { | 78 | container: { |
40 | flex: 1, | 79 | flex: 1, |
41 | }, | 80 | }, |
81 | + contentContainer: { | ||
82 | + flexDirection: 'row', | ||
83 | + flexWrap: 'wrap', | ||
84 | + }, | ||
85 | + listContainer: { | ||
86 | + width: width / 2, | ||
87 | + }, | ||
42 | }); | 88 | }); |
@@ -7,4 +7,17 @@ export default keyMirror({ | @@ -7,4 +7,17 @@ export default keyMirror({ | ||
7 | SET_CHANNEL: null, | 7 | SET_CHANNEL: null, |
8 | SHOWGIFTALERT: null, | 8 | SHOWGIFTALERT: null, |
9 | DISMISSGIFTALERT: null, | 9 | DISMISSGIFTALERT: null, |
10 | + | ||
11 | + COUPONS_BAG_REQUEST: null, | ||
12 | + COUPONS_BAG_SUCCESS: null, | ||
13 | + COUPONS_BAG_FAILURE: null, | ||
14 | + | ||
15 | + ASSOCIATORGIFT_PRODUCT_REQUEST: null, | ||
16 | + ASSOCIATORGIFT_PRODUCT_SUCCESS: null, | ||
17 | + ASSOCIATORGIFT_PRODUCT_FAILURE: null, | ||
18 | + | ||
19 | + DRAW_COUPONS_BAG_REQUEST: null, | ||
20 | + DRAW_COUPONS_BAG_SUCCESS: null, | ||
21 | + DRAW_COUPONS_BAG_FAILURE: null, | ||
22 | + | ||
10 | }); | 23 | }); |
@@ -43,10 +43,11 @@ class AssociatorGiftContainer extends Component { | @@ -43,10 +43,11 @@ class AssociatorGiftContainer extends Component { | ||
43 | super(props); | 43 | super(props); |
44 | this._displayGiftAlert = this._displayGiftAlert.bind(this); | 44 | this._displayGiftAlert = this._displayGiftAlert.bind(this); |
45 | this._hiddenGiftAlert = this._hiddenGiftAlert.bind(this); | 45 | this._hiddenGiftAlert = this._hiddenGiftAlert.bind(this); |
46 | + this.onPressProduct = this.onPressProduct.bind(this); | ||
46 | } | 47 | } |
47 | 48 | ||
48 | componentDidMount() { | 49 | componentDidMount() { |
49 | - | 50 | + this.props.actions.getProductListForAssociatorGift(); |
50 | } | 51 | } |
51 | 52 | ||
52 | componentWillUnmount() { | 53 | componentWillUnmount() { |
@@ -61,17 +62,36 @@ class AssociatorGiftContainer extends Component { | @@ -61,17 +62,36 @@ class AssociatorGiftContainer extends Component { | ||
61 | this.props.actions.hiddenGiftAlert(); | 62 | this.props.actions.hiddenGiftAlert(); |
62 | } | 63 | } |
63 | 64 | ||
65 | + onPressProduct(product){ | ||
66 | + let productSkn = product && product.get('product_skn', 0); | ||
67 | + let is_global = product && product.get('is_global', 'N'); | ||
68 | + | ||
69 | + if (!productSkn) { | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
73 | + let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`; | ||
74 | + | ||
75 | + if (is_global === 'Y') { | ||
76 | + url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalpurchase","params":{"skn":"${productSkn}"}}`; | ||
77 | + } | ||
78 | + | ||
79 | + ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url); | ||
80 | + } | ||
81 | + | ||
64 | render() { | 82 | render() { |
65 | 83 | ||
66 | let { | 84 | let { |
67 | showGiftAlert, | 85 | showGiftAlert, |
68 | - | 86 | + productList |
69 | } = this.props.associatorGift; | 87 | } = this.props.associatorGift; |
70 | return ( | 88 | return ( |
71 | <AssociatorGift | 89 | <AssociatorGift |
72 | showGiftAlert={showGiftAlert} | 90 | showGiftAlert={showGiftAlert} |
73 | displayGiftAlert={this._displayGiftAlert} | 91 | displayGiftAlert={this._displayGiftAlert} |
74 | hiddenGiftAlert={this._hiddenGiftAlert} | 92 | hiddenGiftAlert={this._hiddenGiftAlert} |
93 | + productList={productList} | ||
94 | + onPressProduct={this.onPressProduct} | ||
75 | /> | 95 | /> |
76 | ); | 96 | ); |
77 | } | 97 | } |
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | import ReactNative from 'react-native'; | 3 | import ReactNative from 'react-native'; |
4 | -import CouponService from '../../services/AssociatorGiftService'; | 4 | +import AssociatorGiftService from '../../services/AssociatorGiftService'; |
5 | const Platform = require('Platform'); | 5 | const Platform = require('Platform'); |
6 | 6 | ||
7 | const { | 7 | const { |
8 | SHOWGIFTALERT, | 8 | SHOWGIFTALERT, |
9 | DISMISSGIFTALERT, | 9 | DISMISSGIFTALERT, |
10 | + | ||
11 | + COUPONS_BAG_REQUEST, | ||
12 | + COUPONS_BAG_SUCCESS, | ||
13 | + COUPONS_BAG_FAILURE, | ||
14 | + | ||
15 | + ASSOCIATORGIFT_PRODUCT_REQUEST, | ||
16 | + ASSOCIATORGIFT_PRODUCT_SUCCESS, | ||
17 | + ASSOCIATORGIFT_PRODUCT_FAILURE, | ||
18 | + | ||
19 | + DRAW_COUPONS_BAG_REQUEST, | ||
20 | + DRAW_COUPONS_BAG_SUCCESS, | ||
21 | + DRAW_COUPONS_BAG_FAILURE, | ||
22 | + | ||
10 | } = require('../../constants/actionTypes').default; | 23 | } = require('../../constants/actionTypes').default; |
11 | 24 | ||
12 | 25 | ||
@@ -22,3 +35,130 @@ export function hiddenGiftAlert() { | @@ -22,3 +35,130 @@ export function hiddenGiftAlert() { | ||
22 | type: DISMISSGIFTALERT, | 35 | type: DISMISSGIFTALERT, |
23 | } | 36 | } |
24 | } | 37 | } |
38 | + | ||
39 | +export function couponsBagRequest() { | ||
40 | + return { | ||
41 | + type: COUPONS_BAG_REQUEST, | ||
42 | + }; | ||
43 | +} | ||
44 | + | ||
45 | +export function couponsBagSuccess(json) { | ||
46 | + return { | ||
47 | + type: COUPONS_BAG_SUCCESS, | ||
48 | + payload: json | ||
49 | + }; | ||
50 | +} | ||
51 | + | ||
52 | +export function couponsBagFailure(error) { | ||
53 | + return { | ||
54 | + type: COUPONS_BAG_FAILURE, | ||
55 | + payload: error | ||
56 | + }; | ||
57 | +} | ||
58 | + | ||
59 | +export function productListForAssociatorGiftRequest() { | ||
60 | + return { | ||
61 | + type: ASSOCIATORGIFT_PRODUCT_REQUEST, | ||
62 | + } | ||
63 | +} | ||
64 | + | ||
65 | +export function productListForAssociatorGiftSuccess(json) { | ||
66 | + return { | ||
67 | + type: ASSOCIATORGIFT_PRODUCT_SUCCESS, | ||
68 | + payload: json, | ||
69 | + } | ||
70 | +} | ||
71 | + | ||
72 | +export function productListForAssociatorGiftFailure(error) { | ||
73 | + return { | ||
74 | + type: ASSOCIATORGIFT_PRODUCT_FAILURE, | ||
75 | + payload: error | ||
76 | + } | ||
77 | +} | ||
78 | + | ||
79 | +export function drawCouponsBagRequest() { | ||
80 | + return { | ||
81 | + type: DRAW_COUPONS_BAG_REQUEST, | ||
82 | + }; | ||
83 | +} | ||
84 | + | ||
85 | +export function drawCouponsBagSuccess(json) { | ||
86 | + return { | ||
87 | + type: DRAW_COUPONS_BAG_SUCCESS, | ||
88 | + payload: json | ||
89 | + }; | ||
90 | +} | ||
91 | + | ||
92 | +export function drawCouponsBagFailure(error) { | ||
93 | + return { | ||
94 | + type: DRAW_COUPONS_BAG_FAILURE, | ||
95 | + payload: error | ||
96 | + }; | ||
97 | +} | ||
98 | + | ||
99 | +export function getCouponsBagList() { | ||
100 | + return (dispatch, getState) => { | ||
101 | + let {app} = getState(); | ||
102 | + let fetchCouponsBag = (uid) => { | ||
103 | + dispatch(couponsBagRequest()); | ||
104 | + return new AssociatorGiftService(app.host).fetchCouponsBagList(uid) | ||
105 | + .then(json => { | ||
106 | + dispatch(couponsBagSuccess(json)); | ||
107 | + }) | ||
108 | + .catch(error => { | ||
109 | + dispatch(couponsBagFailure(error)); | ||
110 | + }); | ||
111 | + }; | ||
112 | + | ||
113 | + let uid = 0; | ||
114 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
115 | + .then(uid => { | ||
116 | + fetchCouponsBag(uid) | ||
117 | + }) | ||
118 | + .catch(error => { | ||
119 | + fetchCouponsBag(uid) | ||
120 | + }); | ||
121 | + | ||
122 | + }; | ||
123 | +} | ||
124 | + | ||
125 | +export function getProductListForAssociatorGift() { | ||
126 | + return (dispatch, getstate) => { | ||
127 | + let {app} = getstate(); | ||
128 | + dispatch(productListForAssociatorGiftRequest()); | ||
129 | + return new AssociatorGiftService(app.host).fetchAssociatorGiftProductList() | ||
130 | + .then(json => { | ||
131 | + dispatch(productListForAssociatorGiftSuccess(json)); | ||
132 | + }) | ||
133 | + .catch(error => { | ||
134 | + dispatch(productListForAssociatorGiftFailure(error)); | ||
135 | + }); | ||
136 | + } | ||
137 | + | ||
138 | +} | ||
139 | + | ||
140 | +export function getDrawCouponsBag() { | ||
141 | + return (dispatch, getState) => { | ||
142 | + let {app} = getState(); | ||
143 | + let fetchCouponsBag = (uid, couponsBagId) => { | ||
144 | + dispatch(drawCouponsBagRequest()); | ||
145 | + return new AssociatorGiftService(app.host).fetchDrawCouponsBag(uid, couponsBagId) | ||
146 | + .then(json => { | ||
147 | + dispatch(drawCouponsBagSuccess(json)); | ||
148 | + }) | ||
149 | + .catch(error => { | ||
150 | + dispatch(drawCouponsBagFailure(error)); | ||
151 | + }); | ||
152 | + }; | ||
153 | + | ||
154 | + let uid = 0; | ||
155 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
156 | + .then(uid => { | ||
157 | + fetchCouponsBag(uid) | ||
158 | + }) | ||
159 | + .catch(error => { | ||
160 | + fetchCouponsBag(uid) | ||
161 | + }); | ||
162 | + | ||
163 | + }; | ||
164 | +} |
@@ -4,6 +4,18 @@ import {Record, List, Map} from 'immutable'; | @@ -4,6 +4,18 @@ import {Record, List, Map} from 'immutable'; | ||
4 | 4 | ||
5 | let InitialState = Record({ | 5 | let InitialState = Record({ |
6 | showGiftAlert: false, | 6 | showGiftAlert: false, |
7 | + couponsBag: new (Record({ | ||
8 | + isFetching: false, | ||
9 | + error: null, | ||
10 | + couponsBag_list: List(), | ||
11 | + })), | ||
12 | + | ||
13 | + productList: new (Record({ | ||
14 | + isFetching: false, | ||
15 | + error: null, | ||
16 | + product_list: List(), | ||
17 | + rec_id:'', | ||
18 | + })), | ||
7 | }); | 19 | }); |
8 | 20 | ||
9 | export default InitialState; | 21 | export default InitialState; |
@@ -6,11 +6,17 @@ import Immutable, {Map} from 'immutable'; | @@ -6,11 +6,17 @@ import Immutable, {Map} from 'immutable'; | ||
6 | const { | 6 | const { |
7 | SHOWGIFTALERT, | 7 | SHOWGIFTALERT, |
8 | DISMISSGIFTALERT, | 8 | DISMISSGIFTALERT, |
9 | + ASSOCIATORGIFT_PRODUCT_SUCCESS, | ||
10 | + ASSOCIATORGIFT_PRODUCT_FAILURE, | ||
9 | } = require('../../constants/actionTypes').default; | 11 | } = require('../../constants/actionTypes').default; |
10 | 12 | ||
11 | const initialState = new InitialState; | 13 | const initialState = new InitialState; |
12 | 14 | ||
13 | export default function couponReducer(state=initialState, action) { | 15 | export default function couponReducer(state=initialState, action) { |
16 | + if (!(state instanceof InitialState)) { | ||
17 | + return initialState.merge(state); | ||
18 | + } | ||
19 | + | ||
14 | switch(action.type) { | 20 | switch(action.type) { |
15 | case SHOWGIFTALERT: { | 21 | case SHOWGIFTALERT: { |
16 | return state.set('showGiftAlert', true); | 22 | return state.set('showGiftAlert', true); |
@@ -18,6 +24,18 @@ export default function couponReducer(state=initialState, action) { | @@ -18,6 +24,18 @@ export default function couponReducer(state=initialState, action) { | ||
18 | case DISMISSGIFTALERT: { | 24 | case DISMISSGIFTALERT: { |
19 | return state.set('showGiftAlert', false); | 25 | return state.set('showGiftAlert', false); |
20 | } | 26 | } |
27 | + case ASSOCIATORGIFT_PRODUCT_SUCCESS: { | ||
28 | + let { | ||
29 | + product_list, | ||
30 | + rec_id, | ||
31 | + } = action.payload; | ||
32 | + | ||
33 | + return state.setIn(['productList', 'product_list'], Immutable.fromJS(product_list)) | ||
34 | + .setIn(['productList', 'rec_id'], rec_id); | ||
35 | + } | ||
36 | + case ASSOCIATORGIFT_PRODUCT_FAILURE: { | ||
37 | + return state.setIn(['productList', 'error'], Immutable.fromJS(action.payload)); | ||
38 | + } | ||
21 | } | 39 | } |
22 | 40 | ||
23 | return state; | 41 | return state; |
@@ -12,4 +12,55 @@ export default class AssociatorGiftService { | @@ -12,4 +12,55 @@ export default class AssociatorGiftService { | ||
12 | this.api = new Request(baseURL); | 12 | this.api = new Request(baseURL); |
13 | } | 13 | } |
14 | 14 | ||
15 | + async fetchCouponsBagList(uid) { | ||
16 | + return await this.api.get({ | ||
17 | + url: '', | ||
18 | + body: { | ||
19 | + uid, | ||
20 | + method: 'app.giftBag.getCouponsBagList', | ||
21 | + } | ||
22 | + }) | ||
23 | + .then((json) => { | ||
24 | + return json; | ||
25 | + }) | ||
26 | + .catch((error) => { | ||
27 | + throw(error); | ||
28 | + }); | ||
29 | + } | ||
30 | + | ||
31 | + async fetchAssociatorGiftProductList() { | ||
32 | + return await this.api.get({ | ||
33 | + url: '', | ||
34 | + body: { | ||
35 | + method: 'app.home.newPreference', | ||
36 | + limit: 30, | ||
37 | + rec_pos: 100004, | ||
38 | + fromPage: 'AssociatorGift_RecommendProduct', | ||
39 | + } | ||
40 | + }) | ||
41 | + .then((json) => { | ||
42 | + return json; | ||
43 | + }) | ||
44 | + .catch((error) => { | ||
45 | + throw(error); | ||
46 | + }); | ||
47 | + } | ||
48 | + | ||
49 | + async fetchDrawCouponsBag(uid, couponsBagId) { | ||
50 | + return await this.api.get({ | ||
51 | + url: '', | ||
52 | + body: { | ||
53 | + uid, | ||
54 | + couponsBagId, | ||
55 | + method: 'app.giftBag.drawCouponsBag', | ||
56 | + } | ||
57 | + }) | ||
58 | + .then((json) => { | ||
59 | + return json; | ||
60 | + }) | ||
61 | + .catch((error) => { | ||
62 | + throw(error); | ||
63 | + }); | ||
64 | + } | ||
65 | + | ||
15 | } | 66 | } |
-
Please register or login to post a comment