在此屏幕中,有两个选项卡 1.INVOICE SPECIFIC 和 2.AD-HOC 。现在在 1.Invoice SPECIFIC 我用复选框映射数组(“数组上方)值,有一些“data.TransactionAmount”我必须计算所有的总和并发送到下一个屏幕,但是如果我取消选中任何列表金额应该减去。就像有 3 个值 - 1050,1050,150 = 3150,如果我未选中单个值,那么它应该是 1050+1050=2100。如果我取消选中单个列表,则所有列表都未选中。2.特设,在这里我可以输入任何数字并按下按钮发送,但值没有更新,1 选项卡值正在运行。请帮助,谢谢,下面的链接是我正在实施的参考。
// Below is the array value
financialTransactionDetail: Array(3)
0:
AdjustedAmount: "0"
NetTransactionAmount: "1050"
TransactionAmount: 1050
1:
AdjustedAmount: "0"
NetTransactionAmount: "1050"
TransactionAmount: 1050
2:
AdjustedAmount: "0"
NetTransactionAmount: "1050"
Status: "Unpaid"
TransactionAmount: 1050
__typename: "FinancialTransactionDetail"
import React, { Component } from 'react';
import { ImageBackground, ScrollView } from 'react-native';
import { Body, Button, Card, CardItem, CheckBox, Text, View, Item, Input, Tab, Tabs, Container } from 'native-base';
import Header from '../../ui/header';
import BG from '../../../images/bg.jpg';
import _ from 'lodash';
import { RegularText, SmallText } from '../../ui/text';
const styles = {
container: {
flexDirection: 'column',
alignItems: 'stretch'
},
imgBG:{
width: '100%'
},
dataContainer:{
backgroundColor:'#fff', width:'100%', flexDirection:'column', justifyContent:'center', alignItems:'center'
},
checkBox : {paddingBottom:2}
}
class PaymentsInvoice extends Component {
constructor(props) {
super(props);
this.state = {
title: 'Payments against invoice',
icon: 'sim',
mobile:this.props.navigation.state.params.customer.service.serviceNumber,
isChecked:true,
sum :{},
transactionAmount :''
}
}
handleChange(){
this.setState({isChecked:!this.state.isChecked})
}
render() {
let { title, icon, mobile,sum } = this.state;
const { navigation,invoiceDetailsinfo } = this.props;
const{financialTransactionDetail} = invoiceDetailsinfo;
sum = financialTransactionDetail.financialTransactionDetail.reduce((a, c) => { return a + c.TransactionAmount}, 0);
console.log('sum: ', sum)
return (
<ImageBackground source={BG} style={styles.imgBG}>
<ScrollView keyboardShouldPersistTaps='always'>
<View style={styles.container}>
<View>
<Header title={title} icon={icon} subtitle={mobile} navigation={navigation} />
</View>
<View style={styles.dataContainer}>
<Container>
<Tabs>
<Tab heading="INVOICE SPECIFIC">
{ !_.isEmpty(financialTransactionDetail.financialTransactionDetail) && financialTransactionDetail.financialTransactionDetail.map(
(data, index) => {
return(
<View key={index} style={{flexDirection:'row', padding:10, alignItems:'center', justifyContent:'space-between'}}>
<View style={{paddingRight:10, marginRight:10}}>
<CheckBox style={styles.checkBox} color="#00678f" checked={this.state.isChecked} onPress={() =>this.handleChange()}/>
</View>
<View style={{flexDirection:'column',flex:1, padding:10, borderWidth:1, borderColor:'lightgrey', borderRadius:10}}>
<View style={{flexDirection:'row', alignItems:'center'}}>
{!this.state.isChecked && <RegularText text={`₦ ${data.TransactionAmount}`} style={{paddingBottom:10, paddingRight:5}}/>}
<SmallText text="From 1-Jan-2019 to 31-Jan-2019" style={{paddingBottom:10}}/>
</View>
{this.state.isChecked &&
<RegularText text={`₦ ${data.TransactionAmount}`} style={{borderColor: '#00fff', borderBottomWidth:1}}>
</RegularText>
/* <Input
value={this.state.transactionAmount}
onChangeText={(text) => this.setState({value1:text})}
/> */
}
</View>
</View>
)
}
)
}
</Tab>
<Tab heading="AD-HOC">
<View style={{flexDirection:'column', padding:20}}>
<RegularText text="Enter Specific Amount to pay" style={{paddingBottom:10}} textColor="darkgrey"/>
<View>
<Item style={{borderColor: '#00fff', borderBottomWidth:1}}>
<Input
value={this.state.sum}
onChangeText={(text) => this.setState({sum:text})}
/>
</Item>
</View>
</View>
</Tab>
</Tabs>
</Container>
</View>
<View>
<Button full onPress={()=>navigation.navigate('PaymentOptionsContainer',sum)}>
<Text>Receive Payment ({sum})</Text>
</Button>
</View>
</View>
</ScrollView>
</ImageBackground>
);
}
}
export default PaymentsInvoice;
谢谢