Authored by 孙凯

add 限购码 review by hongmo

'use strict';
import React from 'react';
import ReactNative from 'react-native';
import YH_Image from '../../../common/components/YH_Image';
import {getSlicedUrl} from '../../../classify/utils/Utils';
const {
View,
TouchableOpacity,
StyleSheet,
Dimensions,
Platform,
Text,
} = ReactNative;
import Immutable, {Map} from 'immutable';
export default class NoDataView extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
render() {
return (
<View style={styles.container}>
<Text>没有 PurchaseCode</Text>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'red',
},
});
... ...
... ... @@ -2,6 +2,7 @@
import React, {Component} from 'react';
import Immutable, {Map} from 'immutable';
import NoDataView from './NoDataView';
import ReactNative, {
View,
... ... @@ -21,6 +22,14 @@ export default class PurchaseCode extends Component {
constructor(props) {
super(props);
this.renderRow = this.renderRow.bind(this);
this.renderSectionHeader = this.renderSectionHeader.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
}
shouldComponentUpdate(nextProps){
... ... @@ -32,13 +41,41 @@ export default class PurchaseCode extends Component {
}
}
renderRow(rowData, sectionID, rowID, highlightRow) {
return null;
}
renderSectionHeader(sectionData, sectionID) {
return null;
}
render() {
let {resource} = this.props;
let error = resource?resource.get('error'):null;
let invalidLimitCodeProducts = resource?resource.get('invalidLimitCodeProducts'):null;
let invalidLimitCodeProductsCount = invalidLimitCodeProducts?invalidLimitCodeProducts.size:0;
let limitCodeProducts = resource?resource.get('limitCodeProducts'):null;
let limitCodeProductsCount = limitCodeProducts?limitCodeProducts.size:0;
let isFetching = resource?resource.get('isFetching'):false;
let showNoContent = (error || (invalidLimitCodeProductsCount==0&&limitCodeProductsCount==0));
let dataSource = {
invalidLimitCodeProducts: invalidLimitCodeProducts?invalidLimitCodeProducts.toArray():[],
limitCodeProducts: limitCodeProducts?limitCodeProducts.toArray():[],
}
return (
<View style={styles.container}>
<Text>PurchaseCode</Text>
{showNoContent?<NoDataView />:<ListView
ref='PurchaseCode'
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this.renderRow}
renderSectionHeader={this.renderSectionHeader}
/>}
</View>
);
}
... ... @@ -50,4 +87,8 @@ let styles = StyleSheet.create({
container: {
flex: 1,
},
contentContainer:{
flexDirection: 'row',
flexWrap: 'wrap',
},
});
... ...
... ... @@ -26,4 +26,13 @@ export default keyMirror({
KIDS_FAVORITE_REQUEST: null,
KIDS_FAVORITE_SUCCESS: null,
KIDS_FAVORITE_FAILURE: null,
GET_MINE_LIMIT_PURCHASE_LIST_REQUEST: null,
GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS: null,
GET_MINE_LIMIT_PURCHASE_LIST_FAILURE: null,
DELETE_MINE_LIMIT_PURCHASE_REQUEST: null,
DELETE_MINE_LIMIT_PURCHASE_SUCCESS: null,
DELETE_MINE_LIMIT_PURCHASE_FAILURE: null,
});
... ...
... ... @@ -44,14 +44,20 @@ function mapDispatchToProps(dispatch) {
class PurchaseCodeContainer extends Component {
constructor(props) {
super(props);
this.subscription = NativeAppEventEmitter.addListener(
'purchaseListChange',
(reminder) => {
this.props.actions.getMineLimitPurchaseList();
}
);
}
componentDidMount() {
this.props.actions.getMineLimitPurchaseList();
}
componentWillUnmount() {
this.subscription && this.subscription.remove();
}
render() {
... ...
... ... @@ -4,5 +4,101 @@ import ReactNative from 'react-native';
import PurchaseCodeService from '../../services/PurchaseCodeService';
const {
SET_SERVICE_HOST
GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
DELETE_MINE_LIMIT_PURCHASE_REQUEST,
DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
DELETE_MINE_LIMIT_PURCHASE_FAILURE,
} = require('../../constants/actionTypes').default;
export function MineLimitPurchaseListRequest() {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
};
}
export function MineLimitPurchaseListSuccess(json) {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
payload: json
}
}
export function MineLimitPurchaseListFailure(error) {
return {
type: GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
payload: error
}
}
export function getMineLimitPurchaseList() {
return (dispatch, getState) => {
let {app, purchaseCode} = getState();
let fetchMineLimitPurchaseList = (uid) => {
dispatch(MineLimitPurchaseListRequest());
return new PurchaseCodeService(app.host).getMineLimitPurchaseList(uid)
.then(json => {
dispatch(MineLimitPurchaseListSuccess(json));
})
.catch(error => {
dispatch(MineLimitPurchaseListFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchMineLimitPurchaseList(uid);
})
.catch(error => {
});
};
}
export function fetchDeleteMinePurchaseCodeLimitCode() {
return {
type: DELETE_MINE_LIMIT_PURCHASE_REQUEST,
};
}
export function DeleteMinePurchaseCodeLimitCodeSuccess(json) {
return {
type: DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
payload: json
}
}
export function DeleteMinePurchaseCodeLimitCodeFailure(error) {
return {
type: DELETE_MINE_LIMIT_PURCHASE_FAILURE,
payload: error
}
}
export function deleteMinePurchaseCodeLimitCode(data) {
return (dispatch, getState) => {
let {app, purchaseCode} = getState();
let limitCode = data.limitCode;
let fetchDeleteMinePurchaseCodeLimitCode = (uid) => {
dispatch(MineLimitPurchaseListRequest());
return new PurchaseCodeService(app.host).DeleteMinePurchaseCodeLimitCode(uid,limitCode)
.then(json => {
dispatch(DeleteMinePurchaseCodeLimitCodeSuccess(json));
})
.catch(error => {
dispatch(DeleteMinePurchaseCodeLimitCodeFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
fetchDeleteMinePurchaseCodeLimitCode(uid);
})
.catch(error => {
});
};
}
... ...
... ... @@ -3,7 +3,10 @@
import {Record, List, Map} from 'immutable';
let InitialState = Record({
aaa: '',
invalidLimitCodeProducts: List(),
limitCodeProducts: List(),
isFetching: false,
error: null,
});
export default InitialState;
... ...
... ... @@ -4,7 +4,14 @@ import InitialState from './purchaseCodeInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_SERVICE_HOST,
GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,
DELETE_MINE_LIMIT_PURCHASE_REQUEST,
DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
DELETE_MINE_LIMIT_PURCHASE_FAILURE,
} = require('../../constants/actionTypes').default;
... ... @@ -12,8 +19,34 @@ const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case SET_SERVICE_HOST: {
case GET_MINE_LIMIT_PURCHASE_LIST_REQUEST: {
return state.set('isFetching', true)
.set('error', null);
}
case GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS: {
return state.set('isFetching', false)
.set('error', null)
.set('invalidLimitCodeProducts', Immutable.fromJS(action.payload.invalidLimitCodeProducts))
.set('limitCodeProducts', Immutable.fromJS(action.payload.limitCodeProducts));
}
case GET_MINE_LIMIT_PURCHASE_LIST_FAILURE: {
return state.set('isFetching', false)
.set('error', action.payload);
}
case DELETE_MINE_LIMIT_PURCHASE_REQUEST: {
return state.set('isFetching', true)
.set('error', null);
}
case DELETE_MINE_LIMIT_PURCHASE_SUCCESS: {
// return state.set('isFetching', false)
// .set('error', null)
// .set('invalidLimitCodeProducts', Immutable.fromJS(action.payload.invalidLimitCodeProducts))
// .set('limitCodeProducts', Immutable.fromJS(action.payload.limitCodeProducts));
}
case DELETE_MINE_LIMIT_PURCHASE_FAILURE: {
return state.set('isFetching', false)
.set('error', action.payload);
}
}
return state;
}
... ...
... ... @@ -11,4 +11,40 @@ export default class PurchaseCodeService {
}
this.api = new Request(baseURL);
}
async getMineLimitPurchaseList(uid,fromPage='iFP_MinePurchaseCode') {
return await this.api.get({
url: '',
body: {
method: 'app.limitcode.query',
uid,
fromPage,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async deleteMinePurchaseCodeLimitCode(uid,limitCode,fromPage='iFP_MinePurchaseCode') {
return await this.api.get({
url: '',
body: {
method: 'app.limitcode.deleteinvalid',
uid,
limitCode,
fromPage,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...