add 限购码 review by hongmo
Showing
8 changed files
with
281 additions
and
7 deletions
1 | +'use strict'; | ||
2 | + | ||
3 | +import React from 'react'; | ||
4 | +import ReactNative from 'react-native'; | ||
5 | +import YH_Image from '../../../common/components/YH_Image'; | ||
6 | +import {getSlicedUrl} from '../../../classify/utils/Utils'; | ||
7 | + | ||
8 | +const { | ||
9 | + View, | ||
10 | + TouchableOpacity, | ||
11 | + StyleSheet, | ||
12 | + Dimensions, | ||
13 | + Platform, | ||
14 | + Text, | ||
15 | +} = ReactNative; | ||
16 | + | ||
17 | +import Immutable, {Map} from 'immutable'; | ||
18 | + | ||
19 | +export default class NoDataView extends React.Component { | ||
20 | + | ||
21 | + constructor(props) { | ||
22 | + super (props); | ||
23 | + } | ||
24 | + | ||
25 | + shouldComponentUpdate(nextProps){ | ||
26 | + if (Immutable.is(nextProps.resource, this.props.resource)) { | ||
27 | + return false; | ||
28 | + } else { | ||
29 | + return true; | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | + render() { | ||
34 | + return ( | ||
35 | + <View style={styles.container}> | ||
36 | + <Text>没有 PurchaseCode</Text> | ||
37 | + </View> | ||
38 | + ); | ||
39 | + } | ||
40 | +} | ||
41 | + | ||
42 | +let {width, height} = Dimensions.get('window'); | ||
43 | + | ||
44 | +let styles = StyleSheet.create({ | ||
45 | + container: { | ||
46 | + flex: 1, | ||
47 | + backgroundColor: 'red', | ||
48 | + }, | ||
49 | + | ||
50 | +}); |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | import React, {Component} from 'react'; | 3 | import React, {Component} from 'react'; |
4 | import Immutable, {Map} from 'immutable'; | 4 | import Immutable, {Map} from 'immutable'; |
5 | +import NoDataView from './NoDataView'; | ||
5 | 6 | ||
6 | import ReactNative, { | 7 | import ReactNative, { |
7 | View, | 8 | View, |
@@ -21,6 +22,14 @@ export default class PurchaseCode extends Component { | @@ -21,6 +22,14 @@ export default class PurchaseCode extends Component { | ||
21 | 22 | ||
22 | constructor(props) { | 23 | constructor(props) { |
23 | super(props); | 24 | super(props); |
25 | + | ||
26 | + this.renderRow = this.renderRow.bind(this); | ||
27 | + this.renderSectionHeader = this.renderSectionHeader.bind(this); | ||
28 | + | ||
29 | + this.dataSource = new ListView.DataSource({ | ||
30 | + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | ||
31 | + sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), | ||
32 | + }); | ||
24 | } | 33 | } |
25 | 34 | ||
26 | shouldComponentUpdate(nextProps){ | 35 | shouldComponentUpdate(nextProps){ |
@@ -32,13 +41,41 @@ export default class PurchaseCode extends Component { | @@ -32,13 +41,41 @@ export default class PurchaseCode extends Component { | ||
32 | } | 41 | } |
33 | } | 42 | } |
34 | 43 | ||
44 | + renderRow(rowData, sectionID, rowID, highlightRow) { | ||
45 | + return null; | ||
46 | + } | ||
47 | + | ||
48 | + renderSectionHeader(sectionData, sectionID) { | ||
49 | + return null; | ||
50 | + } | ||
51 | + | ||
35 | render() { | 52 | render() { |
36 | 53 | ||
37 | let {resource} = this.props; | 54 | let {resource} = this.props; |
38 | 55 | ||
56 | + let error = resource?resource.get('error'):null; | ||
57 | + let invalidLimitCodeProducts = resource?resource.get('invalidLimitCodeProducts'):null; | ||
58 | + let invalidLimitCodeProductsCount = invalidLimitCodeProducts?invalidLimitCodeProducts.size:0; | ||
59 | + let limitCodeProducts = resource?resource.get('limitCodeProducts'):null; | ||
60 | + let limitCodeProductsCount = limitCodeProducts?limitCodeProducts.size:0; | ||
61 | + let isFetching = resource?resource.get('isFetching'):false; | ||
62 | + let showNoContent = (error || (invalidLimitCodeProductsCount==0&&limitCodeProductsCount==0)); | ||
63 | + | ||
64 | + let dataSource = { | ||
65 | + invalidLimitCodeProducts: invalidLimitCodeProducts?invalidLimitCodeProducts.toArray():[], | ||
66 | + limitCodeProducts: limitCodeProducts?limitCodeProducts.toArray():[], | ||
67 | + } | ||
68 | + | ||
39 | return ( | 69 | return ( |
40 | <View style={styles.container}> | 70 | <View style={styles.container}> |
41 | - <Text>PurchaseCode</Text> | 71 | + {showNoContent?<NoDataView />:<ListView |
72 | + ref='PurchaseCode' | ||
73 | + contentContainerStyle={styles.contentContainer} | ||
74 | + enableEmptySections={true} | ||
75 | + dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)} | ||
76 | + renderRow={this.renderRow} | ||
77 | + renderSectionHeader={this.renderSectionHeader} | ||
78 | + />} | ||
42 | </View> | 79 | </View> |
43 | ); | 80 | ); |
44 | } | 81 | } |
@@ -50,4 +87,8 @@ let styles = StyleSheet.create({ | @@ -50,4 +87,8 @@ let styles = StyleSheet.create({ | ||
50 | container: { | 87 | container: { |
51 | flex: 1, | 88 | flex: 1, |
52 | }, | 89 | }, |
90 | + contentContainer:{ | ||
91 | + flexDirection: 'row', | ||
92 | + flexWrap: 'wrap', | ||
93 | + }, | ||
53 | }); | 94 | }); |
@@ -26,4 +26,13 @@ export default keyMirror({ | @@ -26,4 +26,13 @@ export default keyMirror({ | ||
26 | KIDS_FAVORITE_REQUEST: null, | 26 | KIDS_FAVORITE_REQUEST: null, |
27 | KIDS_FAVORITE_SUCCESS: null, | 27 | KIDS_FAVORITE_SUCCESS: null, |
28 | KIDS_FAVORITE_FAILURE: null, | 28 | KIDS_FAVORITE_FAILURE: null, |
29 | + | ||
30 | + | ||
31 | + GET_MINE_LIMIT_PURCHASE_LIST_REQUEST: null, | ||
32 | + GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS: null, | ||
33 | + GET_MINE_LIMIT_PURCHASE_LIST_FAILURE: null, | ||
34 | + | ||
35 | + DELETE_MINE_LIMIT_PURCHASE_REQUEST: null, | ||
36 | + DELETE_MINE_LIMIT_PURCHASE_SUCCESS: null, | ||
37 | + DELETE_MINE_LIMIT_PURCHASE_FAILURE: null, | ||
29 | }); | 38 | }); |
@@ -44,14 +44,20 @@ function mapDispatchToProps(dispatch) { | @@ -44,14 +44,20 @@ function mapDispatchToProps(dispatch) { | ||
44 | class PurchaseCodeContainer extends Component { | 44 | class PurchaseCodeContainer extends Component { |
45 | constructor(props) { | 45 | constructor(props) { |
46 | super(props); | 46 | super(props); |
47 | + this.subscription = NativeAppEventEmitter.addListener( | ||
48 | + 'purchaseListChange', | ||
49 | + (reminder) => { | ||
50 | + this.props.actions.getMineLimitPurchaseList(); | ||
51 | + } | ||
52 | + ); | ||
47 | } | 53 | } |
48 | 54 | ||
49 | componentDidMount() { | 55 | componentDidMount() { |
50 | - | 56 | + this.props.actions.getMineLimitPurchaseList(); |
51 | } | 57 | } |
52 | 58 | ||
53 | componentWillUnmount() { | 59 | componentWillUnmount() { |
54 | - | 60 | + this.subscription && this.subscription.remove(); |
55 | } | 61 | } |
56 | 62 | ||
57 | render() { | 63 | render() { |
@@ -4,5 +4,101 @@ import ReactNative from 'react-native'; | @@ -4,5 +4,101 @@ import ReactNative from 'react-native'; | ||
4 | import PurchaseCodeService from '../../services/PurchaseCodeService'; | 4 | import PurchaseCodeService from '../../services/PurchaseCodeService'; |
5 | 5 | ||
6 | const { | 6 | const { |
7 | - SET_SERVICE_HOST | 7 | + |
8 | + GET_MINE_LIMIT_PURCHASE_LIST_REQUEST, | ||
9 | + GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS, | ||
10 | + GET_MINE_LIMIT_PURCHASE_LIST_FAILURE, | ||
11 | + | ||
12 | + DELETE_MINE_LIMIT_PURCHASE_REQUEST, | ||
13 | + DELETE_MINE_LIMIT_PURCHASE_SUCCESS, | ||
14 | + DELETE_MINE_LIMIT_PURCHASE_FAILURE, | ||
15 | + | ||
8 | } = require('../../constants/actionTypes').default; | 16 | } = require('../../constants/actionTypes').default; |
17 | + | ||
18 | +export function MineLimitPurchaseListRequest() { | ||
19 | + return { | ||
20 | + type: GET_MINE_LIMIT_PURCHASE_LIST_REQUEST, | ||
21 | + }; | ||
22 | +} | ||
23 | + | ||
24 | +export function MineLimitPurchaseListSuccess(json) { | ||
25 | + return { | ||
26 | + type: GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS, | ||
27 | + payload: json | ||
28 | + } | ||
29 | +} | ||
30 | + | ||
31 | +export function MineLimitPurchaseListFailure(error) { | ||
32 | + return { | ||
33 | + type: GET_MINE_LIMIT_PURCHASE_LIST_FAILURE, | ||
34 | + payload: error | ||
35 | + } | ||
36 | +} | ||
37 | + | ||
38 | +export function getMineLimitPurchaseList() { | ||
39 | + return (dispatch, getState) => { | ||
40 | + let {app, purchaseCode} = getState(); | ||
41 | + | ||
42 | + let fetchMineLimitPurchaseList = (uid) => { | ||
43 | + dispatch(MineLimitPurchaseListRequest()); | ||
44 | + return new PurchaseCodeService(app.host).getMineLimitPurchaseList(uid) | ||
45 | + .then(json => { | ||
46 | + dispatch(MineLimitPurchaseListSuccess(json)); | ||
47 | + }) | ||
48 | + .catch(error => { | ||
49 | + dispatch(MineLimitPurchaseListFailure(error)); | ||
50 | + }); | ||
51 | + } | ||
52 | + | ||
53 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
54 | + .then(uid => { | ||
55 | + fetchMineLimitPurchaseList(uid); | ||
56 | + }) | ||
57 | + .catch(error => { | ||
58 | + }); | ||
59 | + }; | ||
60 | +} | ||
61 | + | ||
62 | +export function fetchDeleteMinePurchaseCodeLimitCode() { | ||
63 | + return { | ||
64 | + type: DELETE_MINE_LIMIT_PURCHASE_REQUEST, | ||
65 | + }; | ||
66 | +} | ||
67 | + | ||
68 | +export function DeleteMinePurchaseCodeLimitCodeSuccess(json) { | ||
69 | + return { | ||
70 | + type: DELETE_MINE_LIMIT_PURCHASE_SUCCESS, | ||
71 | + payload: json | ||
72 | + } | ||
73 | +} | ||
74 | + | ||
75 | +export function DeleteMinePurchaseCodeLimitCodeFailure(error) { | ||
76 | + return { | ||
77 | + type: DELETE_MINE_LIMIT_PURCHASE_FAILURE, | ||
78 | + payload: error | ||
79 | + } | ||
80 | +} | ||
81 | + | ||
82 | +export function deleteMinePurchaseCodeLimitCode(data) { | ||
83 | + return (dispatch, getState) => { | ||
84 | + let {app, purchaseCode} = getState(); | ||
85 | + let limitCode = data.limitCode; | ||
86 | + let fetchDeleteMinePurchaseCodeLimitCode = (uid) => { | ||
87 | + dispatch(MineLimitPurchaseListRequest()); | ||
88 | + return new PurchaseCodeService(app.host).DeleteMinePurchaseCodeLimitCode(uid,limitCode) | ||
89 | + .then(json => { | ||
90 | + dispatch(DeleteMinePurchaseCodeLimitCodeSuccess(json)); | ||
91 | + }) | ||
92 | + .catch(error => { | ||
93 | + dispatch(DeleteMinePurchaseCodeLimitCodeFailure(error)); | ||
94 | + }); | ||
95 | + } | ||
96 | + | ||
97 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
98 | + .then(uid => { | ||
99 | + fetchDeleteMinePurchaseCodeLimitCode(uid); | ||
100 | + }) | ||
101 | + .catch(error => { | ||
102 | + }); | ||
103 | + }; | ||
104 | +} |
@@ -3,7 +3,10 @@ | @@ -3,7 +3,10 @@ | ||
3 | import {Record, List, Map} from 'immutable'; | 3 | import {Record, List, Map} from 'immutable'; |
4 | 4 | ||
5 | let InitialState = Record({ | 5 | let InitialState = Record({ |
6 | - aaa: '', | 6 | + invalidLimitCodeProducts: List(), |
7 | + limitCodeProducts: List(), | ||
8 | + isFetching: false, | ||
9 | + error: null, | ||
7 | }); | 10 | }); |
8 | 11 | ||
9 | export default InitialState; | 12 | export default InitialState; |
@@ -4,7 +4,14 @@ import InitialState from './purchaseCodeInitialState'; | @@ -4,7 +4,14 @@ import InitialState from './purchaseCodeInitialState'; | ||
4 | import Immutable, {Map} from 'immutable'; | 4 | import Immutable, {Map} from 'immutable'; |
5 | 5 | ||
6 | const { | 6 | const { |
7 | - SET_SERVICE_HOST, | 7 | + |
8 | + GET_MINE_LIMIT_PURCHASE_LIST_REQUEST, | ||
9 | + GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS, | ||
10 | + GET_MINE_LIMIT_PURCHASE_LIST_FAILURE, | ||
11 | + | ||
12 | + DELETE_MINE_LIMIT_PURCHASE_REQUEST, | ||
13 | + DELETE_MINE_LIMIT_PURCHASE_SUCCESS, | ||
14 | + DELETE_MINE_LIMIT_PURCHASE_FAILURE, | ||
8 | 15 | ||
9 | } = require('../../constants/actionTypes').default; | 16 | } = require('../../constants/actionTypes').default; |
10 | 17 | ||
@@ -12,8 +19,34 @@ const initialState = new InitialState; | @@ -12,8 +19,34 @@ const initialState = new InitialState; | ||
12 | 19 | ||
13 | export default function detailReducer(state=initialState, action) { | 20 | export default function detailReducer(state=initialState, action) { |
14 | switch(action.type) { | 21 | switch(action.type) { |
15 | - case SET_SERVICE_HOST: { | 22 | + case GET_MINE_LIMIT_PURCHASE_LIST_REQUEST: { |
23 | + return state.set('isFetching', true) | ||
24 | + .set('error', null); | ||
16 | } | 25 | } |
26 | + case GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS: { | ||
27 | + return state.set('isFetching', false) | ||
28 | + .set('error', null) | ||
29 | + .set('invalidLimitCodeProducts', Immutable.fromJS(action.payload.invalidLimitCodeProducts)) | ||
30 | + .set('limitCodeProducts', Immutable.fromJS(action.payload.limitCodeProducts)); | ||
31 | + } | ||
32 | + case GET_MINE_LIMIT_PURCHASE_LIST_FAILURE: { | ||
33 | + return state.set('isFetching', false) | ||
34 | + .set('error', action.payload); | ||
35 | + } | ||
36 | + case DELETE_MINE_LIMIT_PURCHASE_REQUEST: { | ||
37 | + return state.set('isFetching', true) | ||
38 | + .set('error', null); | ||
39 | + } | ||
40 | + case DELETE_MINE_LIMIT_PURCHASE_SUCCESS: { | ||
41 | + // return state.set('isFetching', false) | ||
42 | + // .set('error', null) | ||
43 | + // .set('invalidLimitCodeProducts', Immutable.fromJS(action.payload.invalidLimitCodeProducts)) | ||
44 | + // .set('limitCodeProducts', Immutable.fromJS(action.payload.limitCodeProducts)); | ||
45 | + } | ||
46 | + case DELETE_MINE_LIMIT_PURCHASE_FAILURE: { | ||
47 | + return state.set('isFetching', false) | ||
48 | + .set('error', action.payload); | ||
49 | + } | ||
17 | } | 50 | } |
18 | return state; | 51 | return state; |
19 | } | 52 | } |
@@ -11,4 +11,40 @@ export default class PurchaseCodeService { | @@ -11,4 +11,40 @@ export default class PurchaseCodeService { | ||
11 | } | 11 | } |
12 | this.api = new Request(baseURL); | 12 | this.api = new Request(baseURL); |
13 | } | 13 | } |
14 | + | ||
15 | + async getMineLimitPurchaseList(uid,fromPage='iFP_MinePurchaseCode') { | ||
16 | + return await this.api.get({ | ||
17 | + url: '', | ||
18 | + body: { | ||
19 | + method: 'app.limitcode.query', | ||
20 | + uid, | ||
21 | + fromPage, | ||
22 | + } | ||
23 | + }) | ||
24 | + .then((json) => { | ||
25 | + return json; | ||
26 | + }) | ||
27 | + .catch((error) => { | ||
28 | + throw(error); | ||
29 | + }); | ||
30 | + } | ||
31 | + | ||
32 | + async deleteMinePurchaseCodeLimitCode(uid,limitCode,fromPage='iFP_MinePurchaseCode') { | ||
33 | + return await this.api.get({ | ||
34 | + url: '', | ||
35 | + body: { | ||
36 | + method: 'app.limitcode.deleteinvalid', | ||
37 | + uid, | ||
38 | + limitCode, | ||
39 | + fromPage, | ||
40 | + } | ||
41 | + }) | ||
42 | + .then((json) => { | ||
43 | + return json; | ||
44 | + }) | ||
45 | + .catch((error) => { | ||
46 | + throw(error); | ||
47 | + }); | ||
48 | + } | ||
49 | + | ||
14 | } | 50 | } |
-
Please register or login to post a comment