Authored by shixiang

分期开通界面 未添加事件处理 review 于良

... ... @@ -41,6 +41,7 @@ export default function native(platform) {
store.dispatch(setPlatform(platform));
let channel = this.props.channel;
channel && store.dispatch(setChannel(channel));
console.log(channel);
return (
<Provider store={store}>
<InstallmentContainer />
... ...
... ... @@ -12,37 +12,85 @@ import ReactNative, {
} from 'react-native';
import Immutable, {Map} from 'immutable';
import ProductListCell from '../../../common/components/ListCell/ProductListCell';
import OpenInstallmentTop from './OpenInstallmentTop';
export default class Installment extends React.Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._renderHeader=this._renderHeader.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
renderRow(rowData, sectionID, rowID, highlightRow) {
_renderRow(rowData, sectionID, rowID, highlightRow) {
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.onPressProductListProduct}
/>
);
}
renderTop(rowData, sectionID, rowID, highlightRow) {
_renderHeader() {
return (
<OpenInstallmentTop
/>
);
}
render() {
let {
isFetching,
productListForInstallment,
installmentInfo,
} = this.props;
let dataSource=null;
dataSource = productListForInstallment.list.toArray();
console.log('========');
console.log(dataSource);
console.log('========');
return(
<View style={styles.container}>
<ListView
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this.renderRow}
dataSource={this.dataSource.cloneWithRows(dataSource)}
renderRow={this._renderRow}
renderHeader={this._renderHeader}
onEndReached={() => {
if (productListForInstallment && productListForInstallment.list && productListForInstallment.list.size > 0) {
this.props.onEndReached && this.props.onEndReached();
}
}}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
contentContainer:{
flexDirection: 'row',
flexWrap: 'wrap',
},
listContainer: {
width: width / 2,
},
});
\ No newline at end of file
... ...
... ... @@ -4,4 +4,7 @@ export default keyMirror({
SET_PLATFORM:null,
SET_CHANNEL:null,
INSTALLMENT_PRODUCT_REQUEST:null,
INSTALLMENT_PRODUCT_SUCCESS:null,
INSTALLMENT_PRODUCT_FAILURE:null,
});
... ...
... ... @@ -40,9 +40,19 @@ class InstallmentContainer extends Component {
constructor(props) {
super(props);
}
render() {
componentDidMount() {
this.props.actions.productListForInstallment();
}
render() {
let {isFetching,open} = this.props.installment;
console.log(open);
console.log(open.productListForInstallment);
return (
<Installment
isFetching={open.isFetching}
productListForInstallment={open.productListForInstallment}
installmentInfo={open.installmentInfo}
/>
);
}
... ...
'use strict';
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
const {
SET_PLATFORM,
INSTALLMENT_PRODUCT_REQUEST,
INSTALLMENT_PRODUCT_SUCCESS,
INSTALLMENT_PRODUCT_FAILURE,
} = require('../../constants/actionTypes').default;
export function productListForInstallmentRequest(){
return {
type: INSTALLMENT_PRODUCT_REQUEST,
}
}
export function productListForInstallmentSuccess(json){
return {
type: INSTALLMENT_PRODUCT_SUCCESS,
payload:json,
}
}
export function productListForInstallmentFailure(){
return {
type: INSTALLMENT_PRODUCT_FAILURE,
}
}
export function productListForInstallment() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {isFetching,open} = installment;
if(isFetching){
return
}
console.log('----productListForInstallment-----');
dispatch(productListForInstallmentRequest());
return new InstallmentService(app.host).fetchInstallmentProductList()
.then(json => {
console.log(json);
let payload = json;//product_list
if (payload.page > 1) {
let oldList = open.fetchInstallmentProductList.list.toJS();
let list = [...oldList, ...payload.list];
payload.product_list = list;
}
dispatch(productListForInstallmentSuccess(payload));
})
.catch(error => {
console.log(error);
dispatch(productListForInstallmentFailure());
});
}
}
... ...
... ... @@ -3,7 +3,15 @@
import {Record, List, Map} from 'immutable';
let InitialState = Record({
isFetching:false,
open:new (Record({
productListForInstallment:new (Record({
list:List(),
page:1,
totalPage:1,
})),
installmentInfo:'',
})),
});
export default InitialState;
\ No newline at end of file
... ...
'use strict';
import InitialState from './installmentInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_PLATFORM,
SET_PLATFORM,
INSTALLMENT_PRODUCT_REQUEST,
INSTALLMENT_PRODUCT_SUCCESS,
INSTALLMENT_PRODUCT_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -12,7 +17,19 @@ export default function appReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case INSTALLMENT_PRODUCT_SUCCESS:{
let {
page,
page_total,
product_list,
} = action.payload;
let productListForInstallment = state.open.productListForInstallment.set('list', Immutable.fromJS(product_list))
.set('page', page)
.set('totalPage', page_total);
return state.setIn(['open', 'productListForInstallment'], productListForInstallment);
}
}
return state;
... ...
... ... @@ -10,4 +10,28 @@ export default class InstallmentService {
}
this.api = new Request(baseURL);
}
async fetchInstallmentProductList(yh_channel=1, order='s_n_asc', page=1, limit=60, brand='',v=7) {
return await this.api.get({
url: '',
body: {
method: 'app.search.li',
yh_channel,
order,
page,
limit,
status: 1,
sales: 'Y',
stocknumber: 1,
attribute_not: 2,
v,
brand,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
\ No newline at end of file
... ...