MyCoupon.js 5.14 KB
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity } from 'react-native';
import CouponeItem from '../CouponItem.1'
import StampItem from '../StampItem'

import {get} from 'axios'
import { SERVER } from '../../common/servername';
import AsyncStorage from '@react-native-community/async-storage';
import Loading from '../Pages/Loading'
import { createDeepLinkingHandler } from 'react-native-deep-link';

export default class AddTab extends Component {
    static navigationOptions = {
        
        headerShown: false
        
    }
    state = {
        current:2,
        Coupon:[
        ],
        Stamp:[
        ],
        isLoading_coupon:true,
        isLoading_stamp:true,
        user:{}
    }
    constructor(props) {
        super(props)
    }
    componentDidMount() {
        if(this.props.navigation.state.params && this.props.navigation.state.params.current ) {
            this.setState({
                current:this.props.navigation.state.params.current
            })
        }
        AsyncStorage.getItem("user",(err,res) => {
            if(res) {
                this.setState({user:JSON.parse(res)})
                get(`http://${SERVER}/coupons/user/${JSON.parse(res).id}`).then(res => {
                    this.setState({
                        Coupon:res.data.data,
                        isLoading_coupon:false
                    })
                })
                get(`http://${SERVER}/stamps/user/${JSON.parse(res).id}`).then(res => {
                    this.setState({
                        Stamp:res.data.data,
                        isLoading_stamp:false
                    })
                })
            
            }
            else {
                this.props.navigation.replace("LoginTab")
            }
        })
    }
    render() {
        return (
            <View>
                <View  style={{position:"relative",backgroundColor:"white",width:"100%",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,backgroundColor:"#615F5F"}}>
                    <TouchableOpacity onPress={() => this.props.navigation.goBack(null)}>
                        <Image source={require('../../assets/back.png')}/>
                    </TouchableOpacity>
                    <Text style={{color:"white",fontSize:16,marginLeft:16}}>
                         쿠폰 & 스탬프
                    </Text>
                </View>
                <ScrollView style={{height:"90%"}}>
                    <View style={{
                        width:"100%",
                    shadowColor: "#000",
                    shadowOffset: {
                        width: 0,
                        height: 2,
                    },
                    backgroundColor:"white",
                    shadowOpacity: 0.25,
                    shadowRadius: 3.84,
                    elevation: 5,}}>
                    <View style={{flex:1,flexDirection:"row", }}>
                        <TouchableOpacity onPress={() => this.setState({current:1})} style={{width:"50%",paddingTop:8.9, paddingBottom:11.1,}}>
                            <Text style={[{textAlign:"center",borderRightColor:"#615F5F",borderRightWidth:1},this.state.current==1?{color:"#615F5F"}:{color:"#BDBCBC"}]}>
                                coupon
                            </Text>
                        </TouchableOpacity>
                        <TouchableOpacity  onPress={() => this.setState({current:2})}  style={{width:"50%",paddingTop:8.9, paddingBottom:11.1}}>
                            <Text style={[{textAlign:"center"},this.state.current==2?{color:"#615F5F"}:{color:"#BDBCBC"}]}>
                                stamp
                            </Text>
                        </TouchableOpacity>
                    </View>
                    </View>
                    <View>
                    {this.state.current==1? 
                        <View style={{marginBottom:8}}>
                        {this.state.isLoading_coupon?<Loading/>:this.state.Coupon.length >0? 
                        <CouponeItem user={this.state.user} setItemNum={()=>{}} item={this.state.Coupon} index={0} height={this.state.height}
                        handleHeight={(e) => {}}/>:undefined}
                    </View>
                        :
                            <View style={{marginBottom:8}}>
                            {this.state.isLoading_coupon?<Loading/>:
                            this.state.Stamp.length >0?
                            this.state.Stamp.map((e,i) => {
                                return (
                                    
                            <StampItem StoreData={e} user={this.state.user} setItemNum={()=>{}} index={0} height={this.state.height}
                            handleHeight={(e) => {}} item={e.StampConditions} />
                                )
                            }) :undefined}
                            </View>
                        
                    }</View>
                    
                </ScrollView>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    }
});