Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { StyleSheet, View, Text, Image, TouchableWithoutFeedback } from 'react-native';
  3. import { Card, CardItem, Body, H3, Toast, Button, Icon } from 'native-base';
  4. import { FlatGrid } from 'react-native-super-grid';
  5. import NavigationService from '../components/NavigationService.js';
  6. import Loading from '../components/Loading.js';
  7. import { URL } from '../components/url';
  8. import axios from 'axios';
  9.  
  10. export default class CategoryDetailGrid extends Component {
  11.  
  12.     constructor(props) {
  13.         super(props);
  14.         this.state = {
  15.             isLoading: false,
  16.             error: '',
  17.             categoryDetailList: [],
  18.             category_id: '',
  19.             startPoint: 0,
  20.             endReach: 20
  21.         }
  22.     }
  23.  
  24.     componentDidMount() {
  25.         this.getCategoryDetailList(this.props.id, this.state.startPoint, this.state.endReach);
  26.     }
  27.  
  28.     showErrorToast = () => {
  29.         Toast.show({
  30.             text: "İnternet bağlantısında problem yarandı",
  31.             buttonText: "Bağla",
  32.             type: "danger",
  33.             duration: 3000,
  34.             position: "top"
  35.         });
  36.     }
  37.  
  38.     getCategoryDetailList = (id, startPoint, endReach) => {
  39.         this.setState({ isLoading: true })
  40.         axios.get(URL + 'app/apiv3/index.php/get_mehsul_v/apikey/melhem3/dil/az/alt_kategoriya_id/' + id)
  41.             .then(result => this.setState({
  42.                 isLoading: false,
  43.                 categoryDetailList: result.data.slice(startPoint, endReach)
  44.             }))
  45.             .catch(error => this.setState({
  46.                 isLoading: true,
  47.                 error: error
  48.             }, () => this.showErrorToast()));
  49.     }
  50.  
  51.     _renderItem = ({ item }) => {
  52.         return (
  53.             <TouchableWithoutFeedback onPress={() => NavigationService.navigate('DrugDetail', { id: item.mehsul_id, image: item.mehsul_mini_sekil_url, title: item.mehsul_qisa_adi, price: item.endirimli_qiymet.slice(0, -2), description: item.aciqlama, rule: item.istifade_qaydasi, composition: item.terkibi })}>
  54.                 <Card style={styles.cardStyle}>
  55.                     <CardItem cardBody>
  56.                         <Image source={{ uri: URL + item.mehsul_thumbnail }} style={styles.itemImage} />
  57.                     </CardItem>
  58.                     <CardItem>
  59.                         <Body style={styles.cardBodyStyle}>
  60.                             <Text>{item.mehsul_qisa_adi}</Text>
  61.                             <Text style={styles.priceStyle}>{item.endirimli_qiymet.slice(0, -2)} AZN</Text>
  62.                         </Body>
  63.                     </CardItem>
  64.                 </Card>
  65.             </TouchableWithoutFeedback>
  66.         );
  67.     }
  68.  
  69.     back = () => {
  70.         this.setState({
  71.             startPoint: this.state.startPoint - 20,
  72.             endReach: this.state.endReach - 20
  73.         }, () => {
  74.             this.componentDidMount();
  75.         });
  76.     }
  77.  
  78.     next = () => {
  79.         this.setState({
  80.             startPoint: this.state.startPoint + 20,
  81.             endReach: this.state.endReach + 20
  82.         }, () => {
  83.             this.componentDidMount();
  84.         });
  85.     }
  86.  
  87.     render() {
  88.         const { isLoading, categoryDetailList } = this.state;
  89.         if (isLoading) {
  90.             return (
  91.                 <Loading />
  92.             );
  93.         }
  94.         return (
  95.             <View style={styles.viewStyle} >
  96.                 <H3 style={styles.titleStyle}>{this.props.title}</H3>
  97.                 <FlatGrid
  98.                     key={this.props.id}
  99.                     itemDimension={130}
  100.                     items={categoryDetailList}
  101.                     renderItem={this._renderItem}
  102.                 />
  103.                 <View style={styles.btnSectionStyle}>
  104.                     {(this.state.startPoint > 0) ?
  105.                         (<Button iconLeft style={styles.backButtonStyle} onPress={this.back}>
  106.                             <Icon name='arrow-back' />
  107.                             <Text style={styles.btnText}>Əvvəlki</Text>
  108.                         </Button>) :
  109.                         (<View></View>)}
  110.                     <Button iconRight style={styles.nextButtonStyle} onPress={this.next}>
  111.                         <Text style={styles.btnText}>Növbəti</Text>
  112.                         <Icon name='arrow-forward' />
  113.                     </Button>
  114.                 </View>
  115.             </View>
  116.         );
  117.     }
  118.  
  119. }
  120. const styles = StyleSheet.create({
  121.     viewStyle: {
  122.         padding: 20
  123.     },
  124.     cardStyle: {
  125.         borderRadius: 15,
  126.         overflow: 'hidden',
  127.         height: 235
  128.     },
  129.     itemImage: {
  130.         flex: 1,
  131.         width: null,
  132.         height: 150,
  133.     },
  134.     cardBodyStyle: {
  135.         justifyContent: 'flex-start',
  136.         alignItems: 'flex-start'
  137.     },
  138.     priceStyle: {
  139.         fontWeight: 'bold'
  140.     },
  141.     titleStyle: {
  142.         paddingLeft: 10,
  143.         fontWeight: 'bold'
  144.     },
  145.     btnSectionStyle: {
  146.         flex: 1,
  147.         flexDirection: 'row',
  148.         justifyContent: 'center',
  149.         alignItems: 'center'
  150.     },
  151.     backButtonStyle: {
  152.         borderRadius: 15,
  153.         marginRight: 10,
  154.         overflow: 'hidden',
  155.         backgroundColor: '#70BE44'
  156.     },
  157.     nextButtonStyle: {
  158.         borderRadius: 15,
  159.         marginLeft: 10,
  160.         overflow: 'hidden',
  161.         backgroundColor: '#70BE44'
  162.     },
  163.     btnText: {
  164.         padding: 10,
  165.         color: '#fff'
  166.     }
  167. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement