Commit 811b48c0 by Nguyễn Thị Thúy

complete calculator escrow and profit loss UI

parent 8f273cc7
import React, {Component, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {View, Text} from 'react-native';
import CalculatorProfitLossView from './CalculatorProfitLossView'; import CalculatorProfitLossView from './CalculatorProfitLossView';
import EscrowCalculatorView from '../EscrowCalculator/EscrowCalculatorView';
import {RadioBuySale} from '../../../Config/constants'; import {RadioBuySale} from '../../../Config/constants';
import I18n from '../../../helper/i18/i18n';
import {checkFormatArray} from '../../../Config/Functions';
import {showAlert, TYPE} from '../../../components/DropdownAlert';
import {getTransactionListByCategory} from '../../../apis/Functions/Transaction';
import {Platform} from 'react-native';
const CalculatorProfitLoss = (props) => { const CalculatorProfitLoss = (props) => {
const [dataProduct, setDataProduct] = useState([ const [dataProduct, setDataProduct] = useState([]);
{
id: 0,
name: 'Ngô',
},
{
id: 1,
name: 'Đậu tương',
}]);
const [product, setProduct] = useState(null); const [product, setProduct] = useState(null);
const [transactionType, setTransactionType] = useState(RadioBuySale[0].value); const [transactionType, setTransactionType] = useState(RadioBuySale[0].value);
const [dataCalculator, setDataCalculator] = useState([ const [dataCalculator, setDataCalculator] = useState([]);
{ const [lotTransactionNumber, setLotTransactionNumber] = useState(null);
name: 'Ngô', const [openPrice, setOpenPrice] = useState(null);
status: 'Mua', const [closeStatusPrice, setCloseStatusPrice] = useState(null);
slot_number: 6, useEffect(() => {
profit_loss_usd: 639324325, getProductData()
profit_loss_vnd: 1234349235455, }, [])
},
{ const getProductData = async () => {
name: 'Đậu tương', const res = await getTransactionListByCategory({
status: 'Bán', keyword: '',
slot_number: 6, platform: Platform.OS,
profit_loss_usd: 639324325, page_size: 1000,
profit_loss_vnd: 1234349235455, page_index: 1,
}, type: 'PRICE_TABLE',
{ category_id: -1,
});
if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data);
} else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data')))
}
};
const onCalculator = () => {
const titles = [
I18n.t('Product'),
I18n.t('LotTransactionNumber'),
I18n.t('OpenPrice'),
I18n.t('CloseStatusPrice'),
];
const index = checkFormatArray([
product,
lotTransactionNumber,
openPrice,
closeStatusPrice,
]);
if (index === true) {
let newData = [...dataCalculator]
newData.push({
name: 'Bạc', name: 'Bạc',
status: 'Mua', status: 'Mua',
slot_number: 6, slot_number: 6,
profit_loss_usd: 639324325, profit_loss_usd: 639324325,
profit_loss_vnd: 1234349235455, profit_loss_vnd: 1234349235455,
}, })
]); setDataCalculator(newData)
const [lotTransactionNUmber, setLotTransactionNUmber] = useState(0); setLotTransactionNumber(null)
const [openPrice, setOpenPrice] = useState(0); setOpenPrice(null)
const [closeStatusPrice, setCloseStatusPrice] = useState(0); setCloseStatusPrice(null)
} else {
const onCalculator = () => { showAlert(TYPE.ERROR, I18n.t('Notification'), `${I18n.t('Please_fill_in')}${titles[index]}`)
}
}; };
const onDelete = () => { const onDelete = () => {
setDataCalculator([])
setLotTransactionNumber(null)
setOpenPrice(null)
setCloseStatusPrice(null)
}; };
const setLotNUmber = (text) => { const setLotNumber = (text) => {
setLotTransactionNUmber(text.split(',').join('')); setLotTransactionNumber(text.split(',').join(''));
}; };
const setOpenPriceEvent = (text) => { const setOpenPriceEvent = (text) => {
...@@ -66,12 +90,13 @@ const CalculatorProfitLoss = (props) => { ...@@ -66,12 +90,13 @@ const CalculatorProfitLoss = (props) => {
<CalculatorProfitLossView <CalculatorProfitLossView
dataProduct={dataProduct} dataProduct={dataProduct}
setProduct={setProduct} setProduct={setProduct}
product={product}
dataCalculator={dataCalculator} dataCalculator={dataCalculator}
onCalculator={onCalculator} onCalculator={onCalculator}
onDelete={onDelete} onDelete={onDelete}
setTransactionType={setTransactionType} setTransactionType={setTransactionType}
setLotNUmber={setLotNUmber} setLotNumber={setLotNumber}
lotTransactionNUmber={lotTransactionNUmber} lotTransactionNumber={lotTransactionNumber}
openPrice={openPrice} openPrice={openPrice}
setOpenPrice={setOpenPriceEvent} setOpenPrice={setOpenPriceEvent}
closeStatusPrice={closeStatusPrice} closeStatusPrice={closeStatusPrice}
......
...@@ -8,7 +8,6 @@ import R from '../../../assets/R'; ...@@ -8,7 +8,6 @@ import R from '../../../assets/R';
import RadioForm from 'react-native-simple-radio-button'; import RadioForm from 'react-native-simple-radio-button';
import {RadioBuySale} from '../../../Config/constants'; import {RadioBuySale} from '../../../Config/constants';
import TextMoney from '../../../components/Input/InputMoney'; import TextMoney from '../../../components/Input/InputMoney';
import ItemPrice from '../../Home/ItemPrice';
import ItemCalculator from './ItemCalculator'; import ItemCalculator from './ItemCalculator';
const CalculatorProfitLossView = (props) => { const CalculatorProfitLossView = (props) => {
...@@ -26,6 +25,7 @@ const CalculatorProfitLossView = (props) => { ...@@ -26,6 +25,7 @@ const CalculatorProfitLossView = (props) => {
onValueChange={(value, item) => { onValueChange={(value, item) => {
props.setProduct(item); props.setProduct(item);
}} }}
defaultValue={props.product?.name}
iconSize={WIDTHXD(40)} iconSize={WIDTHXD(40)}
iconColor={R.colors.black} iconColor={R.colors.black}
/> />
...@@ -48,15 +48,15 @@ const CalculatorProfitLossView = (props) => { ...@@ -48,15 +48,15 @@ const CalculatorProfitLossView = (props) => {
</View> </View>
<TextMoney <TextMoney
onChangeText={(val) => { onChangeText={(val) => {
props.setLotNUmber(val) props.setLotNumber(val);
}} }}
title={I18n.t('LotTransactionNumber')} title={I18n.t('LotTransactionNumber')}
value={toPriceVnd(props.lotTransactionNUmber)} value={toPriceVnd(props.lotTransactionNumber)}
titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}} titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}}
/> />
<TextMoney <TextMoney
onChangeText={(val) => { onChangeText={(val) => {
props.setOpenPrice(val) props.setOpenPrice(val);
}} }}
title={I18n.t('OpenPrice')} title={I18n.t('OpenPrice')}
value={toPriceVnd(props.openPrice)} value={toPriceVnd(props.openPrice)}
...@@ -64,7 +64,7 @@ const CalculatorProfitLossView = (props) => { ...@@ -64,7 +64,7 @@ const CalculatorProfitLossView = (props) => {
/> />
<TextMoney <TextMoney
onChangeText={(val) => { onChangeText={(val) => {
props.setCloseStatusPrice(val) props.setCloseStatusPrice(val);
}} }}
title={I18n.t('CloseStatusPrice')} title={I18n.t('CloseStatusPrice')}
value={toPriceVnd(props.closeStatusPrice)} value={toPriceVnd(props.closeStatusPrice)}
...@@ -78,12 +78,12 @@ const CalculatorProfitLossView = (props) => { ...@@ -78,12 +78,12 @@ const CalculatorProfitLossView = (props) => {
marginTop: HEIGHTXD(50), marginTop: HEIGHTXD(50),
}}> }}>
<TouchableOpacity onPress={() => { <TouchableOpacity onPress={() => {
props.onDelete() props.onDelete();
}} style={[styles.btn, {backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)}]}> }} style={[styles.btn, {backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)}]}>
<Text style={styles.txtButton}>{I18n.t('Delete')}</Text> <Text style={styles.txtButton}>{I18n.t('Delete')}</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => { <TouchableOpacity onPress={() => {
props.onCalculator() props.onCalculator();
}} style={styles.btn}> }} style={styles.btn}>
<Text style={styles.txtButton}>{I18n.t('Calculator')}</Text> <Text style={styles.txtButton}>{I18n.t('Calculator')}</Text>
</TouchableOpacity> </TouchableOpacity>
...@@ -93,7 +93,8 @@ const CalculatorProfitLossView = (props) => { ...@@ -93,7 +93,8 @@ const CalculatorProfitLossView = (props) => {
style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}} style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}}
keyExtractor={(item) => item.id} keyExtractor={(item) => item.id}
data={props.dataCalculator} data={props.dataCalculator}
renderItem={({item, index}) => <ItemCalculator item={item} isLastItem={index === props.dataCalculator.length - 1}/>} renderItem={({item, index}) => <ItemCalculator item={item}
isLastItem={index === props.dataCalculator.length - 1}/>}
/> />
</ScrollView> </ScrollView>
</View> </View>
......
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import EscrowCalculatorView from './EscrowCalculatorView'; import EscrowCalculatorView from './EscrowCalculatorView';
import {getTransactionListByCategory} from '../../../apis/Functions/Transaction';
import {Platform} from 'react-native';
import {showAlert, TYPE} from '../../../components/DropdownAlert';
import I18n from '../../../helper/i18/i18n';
const EscrowCalculator = (props) => { const EscrowCalculator = (props) => {
const [dataProduct, setDataProduct] = useState([ const [dataProduct, setDataProduct] = useState([]);
{ const [listInput, setListInput] = useState([{
id: 0, product: null,
name: 'Ngô', lotNumber: null,
}, firstEscrow: 0,
{ }]);
id: 1, const [firstEscrow, setFirstEscrow] = useState(null);
name: 'Đậu tương', const [firstEscrowTotal, setFirstEscrowTotal] = useState(0);
}]) useEffect(() => {
const [product, setProduct] = useState(null) getProductData()
const [lotNumber, setLotNumber] = useState(null) }, [])
const [firstEscrow, setFirstEscrow] = useState(null)
const getProductData = async () => {
const setLotNumberEvent = (text) => { const res = await getTransactionListByCategory({
setLotNumber(text.split(',').join('')); keyword: '',
setFirstEscrow(text.split(',').join('')); platform: Platform.OS,
page_size: 1000,
page_index: 1,
type: 'PRICE_TABLE',
category_id: -1,
});
if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data);
} else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data')))
}
}; };
const onCalculator = () => { const onCalculator = () => {
} };
const onDelete = () => { const onDelete = () => {
} };
const onAdd = () => {
const setItemInput = (item, index) => {
let data = [...listInput]
data[index] = item
setListInput(data)
let firstEscrowTotalTmp = 0
data.map((item) => {
if(item.firstEscrow) firstEscrowTotalTmp = firstEscrowTotalTmp + item.firstEscrow
})
setFirstEscrowTotal(firstEscrowTotalTmp)
} }
const onAdd = () => {
let data = [...listInput];
data.push({
product: null,
lotNumber: null,
firstEscrow: null,
});
setListInput(data);
};
return ( return (
<EscrowCalculatorView <EscrowCalculatorView
dataProduct={dataProduct} dataProduct={dataProduct}
setProduct={setProduct}
lotNumber={lotNumber}
firstEscrow={firstEscrow} firstEscrow={firstEscrow}
setLotNumber={setLotNumberEvent}
onCalculator={onCalculator} onCalculator={onCalculator}
onDelete={onDelete} onDelete={onDelete}
onAdd={onAdd} onAdd={onAdd}
listInput={listInput}
firstEscrowTotal={firstEscrowTotal}
setItemInput={setItemInput}
setFirstEscrow={setFirstEscrow}
/> />
); );
}; };
......
import React from 'react'; import React from 'react';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'; import {FlatList, StyleSheet, Text, TouchableOpacity, View, ScrollView} from 'react-native';
import HeaderBack from '../../../components/Header/HeaderBack'; import HeaderBack from '../../../components/Header/HeaderBack';
import {getFontXD, getWidth, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../../Config/Functions'; import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../../Config/Functions';
import R from '../../../assets/R'; import R from '../../../assets/R';
import I18n from '../../../helper/i18/i18n'; import I18n from '../../../helper/i18/i18n';
import PickerItem from '../../../components/Picker/PickerItem';
import TextMoney from '../../../components/Input/InputMoney'; import TextMoney from '../../../components/Input/InputMoney';
import {ADDMETHODPAY} from '../../../routers/ScreenNames';
import Icon from 'react-native-vector-icons/Entypo'; import Icon from 'react-native-vector-icons/Entypo';
import ItemEscrowCalculator from './ItemEscrowCalculator';
const EscrowCalculatorView = (props) => { const EscrowCalculatorView = (props) => {
return ( return (
<View style={{flex: 1, flexDirection: 'column', backgroundColor: 'white'}}> <View style={{flex: 1, flexDirection: 'column', backgroundColor: 'white'}}>
<HeaderBack title={'EscrowCalculator'} isWhite={true}/> <HeaderBack title={'EscrowCalculator'} isWhite={true}/>
<View style={styles.viewInput}> <ScrollView style={{paddingVertical:HEIGHTXD(60)}}>
<Text <View >
style={styles.textTitle}> <FlatList
{I18n.t('Product')} keyExtractor={(item) => item.id}
</Text> data={props.listInput}
<PickerItem renderItem={({item, index}) => <ItemEscrowCalculator item={item}
data={props.dataProduct} dataProduct={props.dataProduct}
onValueChange={(value, item) => { setProduct={(product) => {
props.setProduct(item); item.product = product
props.setItemInput(item, index)
}} }}
iconSize={WIDTHXD(40)} setLotNumber={(lotNumber) => {
iconColor={R.colors.black} item.lotNumber = lotNumber.split('.').join('')
item.firstEscrow = parseFloat(item.lotNumber)*12312
props.setItemInput(item, index)
}}/>}
/> />
<TextMoney
onChangeText={(val) => {
props.setLotNumber(val)
}}
title={I18n.t('LotTransactionNumber')}
value={toPriceVnd(props.lotNumber)}
titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}}
/>
<TextMoney
onChangeText={(val) => {
}}
title={I18n.t('FirstEscrow')}
value={props.firstEscrow}
titleStyle={{ontSize: getFontXD(39)}}
editable={false}
inputStyle={{backgroundColor: R.colors.gray7}}
/>
</View>
<View style={{flexDirection: 'row', justifyContent: 'flex-end'}}> <View style={{flexDirection: 'row', justifyContent: 'flex-end'}}>
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
props.onAdd() props.onAdd();
}} }}
style={styles.containerBtn}> style={styles.containerBtn}>
<Icon name={'plus'} size={27} color={R.colors.white}/> <Icon name={'plus'} size={27} color={R.colors.white}/>
...@@ -57,6 +41,7 @@ const EscrowCalculatorView = (props) => { ...@@ -57,6 +41,7 @@ const EscrowCalculatorView = (props) => {
<View style={{paddingHorizontal: WIDTHXD(60)}}> <View style={{paddingHorizontal: WIDTHXD(60)}}>
<TextMoney <TextMoney
onChangeText={(val) => { onChangeText={(val) => {
props.setFirstEscrow(val.split('.').join(''))
}} }}
title={I18n.t('FirstEscrow')} title={I18n.t('FirstEscrow')}
value={props.firstEscrow} value={props.firstEscrow}
...@@ -68,33 +53,36 @@ const EscrowCalculatorView = (props) => { ...@@ -68,33 +53,36 @@ const EscrowCalculatorView = (props) => {
<TextMoney <TextMoney
editable={false} editable={false}
title={I18n.t('FirstEscrowTotal')} title={I18n.t('FirstEscrowTotal')}
value={props.firstEscrow} value={props.firstEscrowTotal}
titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}} titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}}
inputStyle={{backgroundColor: R.colors.gray7}} inputStyle={{backgroundColor: R.colors.gray7}}
/> />
<Text style={styles.textMessage}>Bn có th giao dch các hp đồng k trên vi mc ký qu <Text style={styles.textMessage}>Bn có th giao dch các hp đồng k trên vi mc ký qu
kh dung hin ti</Text> kh dung hin ti</Text>
</View> </View>
<View style={{ <View style={{
width: '100%', width: '100%',
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
position: 'absolute', marginTop: HEIGHTXD(80),
bottom: HEIGHTXD(50), marginBottom: HEIGHTXD(150)
}}> }}>
<TouchableOpacity onPress={() => { <TouchableOpacity onPress={() => {
props.onDelete() props.onDelete();
}} style={[styles.btn, {backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)}]}> }} style={[styles.btn, {backgroundColor: R.colors.red2, marginRight: WIDTHXD(72)}]}>
<Text style={styles.txtButton}>{I18n.t('Delete')}</Text> <Text style={styles.txtButton}>{I18n.t('Delete')}</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity onPress={() => { <TouchableOpacity onPress={() => {
props.onCalculator() props.onCalculator();
}} style={styles.btn}> }} style={styles.btn}>
<Text style={styles.txtButton}>{I18n.t('Calculator')}</Text> <Text style={styles.txtButton}>{I18n.t('Calculator')}</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
</ScrollView>
</View>
); );
}; };
...@@ -116,7 +104,7 @@ const styles = StyleSheet.create({ ...@@ -116,7 +104,7 @@ const styles = StyleSheet.create({
textMessage: { textMessage: {
fontSize: getFontXD(39), fontSize: getFontXD(39),
color: R.colors.black, color: R.colors.black,
marginTop: HEIGHTXD(68) marginTop: HEIGHTXD(68),
}, },
containerBtn: { containerBtn: {
marginHorizontal: WIDTHXD(36), marginHorizontal: WIDTHXD(36),
......
import React from 'react';
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import I18n from '../../../helper/i18/i18n';
import PickerItem from '../../../components/Picker/PickerItem';
import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../../Config/Functions';
import R from '../../../assets/R';
import TextMoney from '../../../components/Input/InputMoney';
import Icon from 'react-native-vector-icons/Entypo';
const ItemEscrowCalculator = (props) => {
return (
<View style={styles.viewInput}>
<Text
style={styles.textTitle}>
{I18n.t('Product')}
</Text>
<PickerItem
data={props.dataProduct}
onValueChange={(value, item) => {
props.setProduct(item);
}}
iconSize={WIDTHXD(40)}
iconColor={R.colors.black}
/>
<TextMoney
onChangeText={(val) => {
props.setLotNumber(val);
}}
title={I18n.t('LotTransactionNumber')}
value={toPriceVnd(props.item.lotNumber)}
titleStyle={{marginTop: HEIGHTXD(20), fontSize: getFontXD(39)}}
/>
<TextMoney
onChangeText={(val) => {
}}
title={I18n.t('FirstEscrow')}
value={props.item.firstEscrow}
titleStyle={{ontSize: getFontXD(39)}}
editable={false}
inputStyle={{backgroundColor: R.colors.gray7}}
/>
</View>
);
};
const styles = StyleSheet.create({
viewInput: {
marginHorizontal: WIDTHXD(36),
marginBottom: WIDTHXD(30),
borderWidth: 0.3,
borderColor: '#707070',
paddingHorizontal: WIDTHXD(24),
paddingVertical: WIDTHXD(24),
},
textTitle: {
fontSize: getFontXD(39),
color: R.colors.color777,
},
})
export default ItemEscrowCalculator;
...@@ -248,7 +248,7 @@ export default { ...@@ -248,7 +248,7 @@ export default {
Buy: 'Buy', Buy: 'Buy',
Sale: 'Sale', Sale: 'Sale',
OpenPrice: 'Open price', OpenPrice: 'Open price',
CloseStatusPrice: 'Giá đóng trạng thái', CloseStatusPrice: 'Close stauts price',
SlotNumber: 'Số slot', SlotNumber: 'Slot number',
ProfitLoss: 'Lãi/lỗ', ProfitLoss: 'Profit/Loss',
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment