|
|
|
@ -1,32 +1,101 @@
|
|
|
|
|
import { FC, useContext } from 'react'
|
|
|
|
|
import { FlatList, ScrollView, Text, View } from 'react-native'
|
|
|
|
|
import { FlatList, Image, ScrollView, Text, TextInput, View } from 'react-native'
|
|
|
|
|
import { SalesOrderContext } from '../screens/salesorder/SalesOrderContex';
|
|
|
|
|
import { InputNumber } from './InputNumber';
|
|
|
|
|
import NumericInput from 'react-native-numeric-input'
|
|
|
|
|
import { CardItem } from './CardItem';
|
|
|
|
|
import { Avatar } from '@ui-kitten/components';
|
|
|
|
|
|
|
|
|
|
const OneToMany = () => {
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
//control: any,
|
|
|
|
|
//fields: any
|
|
|
|
|
}
|
|
|
|
|
const { lines, setLines } = useContext(SalesOrderContext);
|
|
|
|
|
|
|
|
|
|
const setCantidad = (productoId: number, nuevaCantidad: number) => {
|
|
|
|
|
|
|
|
|
|
setLines(lines.map(line => {
|
|
|
|
|
if (line.producto.id == productoId) {
|
|
|
|
|
line.cantidad = nuevaCantidad;
|
|
|
|
|
}
|
|
|
|
|
return line;
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
const OneToMany: FC<Props> = ({}) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { lines } = useContext(SalesOrderContext);
|
|
|
|
|
|
|
|
|
|
const setPrecio = (productoId: number, nuevoPrecio: number) => {
|
|
|
|
|
setLines(lines.map(line => {
|
|
|
|
|
if (line.producto.id == productoId) {
|
|
|
|
|
line.precio = nuevoPrecio;
|
|
|
|
|
}
|
|
|
|
|
return line;
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ScrollView >
|
|
|
|
|
<FlatList
|
|
|
|
|
data={lines}
|
|
|
|
|
renderItem={({ item }) =>
|
|
|
|
|
<View >
|
|
|
|
|
<>
|
|
|
|
|
<Text className='text-xl text-center my-4'>{item.producto.nombre}</Text>
|
|
|
|
|
</>
|
|
|
|
|
<View className='flex-row'>
|
|
|
|
|
<CardItem>
|
|
|
|
|
<View className='flex-row'>
|
|
|
|
|
<View>
|
|
|
|
|
<Image
|
|
|
|
|
source={{ uri: 'https://images.philips.com/is/image/PhilipsConsumer/271V8_69-IMS-en_HK?$jpglarge$&wid=1250' }}
|
|
|
|
|
style={{
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 80
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<NumericInput
|
|
|
|
|
value={item.cantidad}
|
|
|
|
|
onChange={value => setCantidad(item.producto.id, value)}
|
|
|
|
|
onLimitReached={(isMax, msg) => console.log(isMax, msg)}
|
|
|
|
|
minValue={1}
|
|
|
|
|
totalWidth={100}
|
|
|
|
|
totalHeight={50}
|
|
|
|
|
iconSize={50}
|
|
|
|
|
step={1}
|
|
|
|
|
valueType='integer'
|
|
|
|
|
rounded
|
|
|
|
|
textColor='#B0228C'
|
|
|
|
|
iconStyle={{ backgroundColor: 'white' }}
|
|
|
|
|
rightButtonBackgroundColor='#1d4ed8'
|
|
|
|
|
leftButtonBackgroundColor='#0ea5e9'
|
|
|
|
|
type='plus-minus'
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<View className='mx-4'>
|
|
|
|
|
<Text className='text-xl text-center'>{item.producto.nombre}</Text>
|
|
|
|
|
<View className='flex-row justify-center'>
|
|
|
|
|
<Text className=' my-2 font-bold text-black text-4xl text-center'>{item.precio * item.cantidad}</Text>
|
|
|
|
|
<Text className=' my-2 ml-2 text-3xl text-left text-teal-500'>$</Text>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<View className='flex-row items-center border-b-2 border-sky-500'>
|
|
|
|
|
<TextInput
|
|
|
|
|
id={'precio'}
|
|
|
|
|
value={String(item.precio)}
|
|
|
|
|
onChangeText={value => setPrecio(item.producto.id, Number(value))}
|
|
|
|
|
placeholder={'Precio'}
|
|
|
|
|
keyboardType="decimal-pad"
|
|
|
|
|
className='p-2 h-10 text-right '
|
|
|
|
|
/>
|
|
|
|
|
<Text>/ unidad</Text>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
</CardItem>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</View>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
{lines.map((line: SalesOrderLine) =>(<Text key={line.producto.id}>{line.producto.id}</Text>))}
|
|
|
|
|
</ScrollView>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|