Advertisement
Guest User

listar_articulos.js

a guest
Mar 26th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { StyleSheet, Text, View, Button, Image, TextInput, ScrollView, Alert } from 'react-native';
  3. import {List, ListItem, Col, Row} from 'native-base'
  4. import { FontAwesome, AntDesign, Ionicons, MaterialIcons } from '@expo/vector-icons';
  5. import * as SQLite from 'expo-sqlite';
  6.  
  7. const db = SQLite.openDatabase('aalmarketapp.db');
  8.  
  9. export default class AppMarket extends Component {
  10.     constructor(props) {
  11.       super(props);
  12.       this.state = {
  13.         dataTodo : []
  14.       };
  15.     }
  16.  
  17.     fetchData(search){
  18.         var query = "SELECT * FROM productos WHERE cod='" + search + "'";
  19.         var params = [];
  20.         db.transaction((tx) => {
  21.             tx.executeSql(query, params, (tx,results) => {
  22.              
  23.               if(results.rows._array.length > 0){
  24.                   this.setState({
  25.                       dataTodo: results.rows._array
  26.                   });
  27.               }
  28.  
  29.             }, function(tx, err){
  30.                 Alert.alert("welcome");
  31.             });
  32.         });
  33.     }
  34.  
  35.     async handleSearch(val){
  36.         await this.fetchData(val);
  37.     }
  38.  
  39.     render() {
  40.  
  41.     const listItem = this.state.dataTodo.map((item) =>
  42.    
  43.     <List key={item.productos_id}>
  44.         <ListItem>
  45.           <Row>
  46.             <Col>
  47.                 <Image style={{width: 150, height: 150}} source={{uri: `data:image/jpeg;base64,${item.card_front}`}}/>
  48.             </Col>
  49.             <Col>
  50.               <Text>{item.cod}</Text>
  51.               <Text>{item.descripcion}</Text>
  52.               <Text>{item.precio}</Text>
  53.               <Text>VER DETALLES</Text>
  54.              
  55.             </Col>
  56.           </Row>
  57.         </ListItem>
  58.       </List>
  59.       );
  60.  
  61.         return (
  62.             <ScrollView>
  63.                 <View style={styles.footer_form}>
  64.                     <Button rounded success type="outline" title="Mostrar Registro" onPress={() => {this.handleSearch('wap')}}/>
  65.                 </View>
  66.                 <View>
  67.                     {listItem}
  68.                 </View>
  69.             </ScrollView>
  70.             );
  71.     }
  72. }
  73.  
  74. const styles = StyleSheet.create({
  75.     footer_form : {
  76.       flex: 1,
  77.       flexDirection : 'row',
  78.       marginTop : 25,
  79.       alignItems: 'center',
  80.       justifyContent: 'center',
  81.     },
  82.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement