ChatRoom.js 17 KB
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity,Dimensions,Keyboard } from 'react-native';
import CouponeItem from '../CouponItem'
import StampItem from '../StampItem'
import Modal from 'react-native-modal'
import More from '../../assets/more_.svg'

import Coupon from '../../assets/coupon_chat.svg'
import Stamp from '../../assets/stamp_chat.svg'
import Menu from '../../assets/menu_chat.svg'
import Paper from '../../assets/paper_chat.svg'

import Message from '../Message'
import { TextInput } from 'react-native-gesture-handler';
import Camera from '../../assets/camera_chat.svg'
import Gallery from '../../assets/gallery_chat.svg'
import Option from '../../assets/options_chat.svg'
import ImagePicker from 'react-native-image-picker';
import CouponItem from '../CouponItem'
import MenuItem from '../MenuItem'
import X from '../../assets/X_white.svg'
import {get,post} from 'axios'
import { SERVER } from '../../common/servername';
import AsyncStorage from '@react-native-community/async-storage';
import Loading from './Loading'
const options = {
    storageOptions: {
      skipBackup: true,
      path: 'images',
    },
  };
export default class AddTab extends Component {
    static navigationOptions = {
        
        headerShown: false
        
    }
    state = {
        isModalVisible:false,
        current:1,
        select:'선택',
        top_height:0,
        bottom_height:0,
        couponModal:false,
        stampModal:false,
        menuModal:false,
        HistoryModal:false,
        loading:true,
        Store: {

        },
        Coupon:[
        ],
        Menu: [
        ]
        ,
        Stamp:[
        ],
        user:{}
    }
    constructor(props) {
        super(props)
        this.scroll = null
        this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
    }
    componentWillMount() {
        if(!this.props.navigation.state.params) {
            this.props.navigation.goBack(null)
            return alert('잘못된 접근입니다.')
        }
        get(`http://${SERVER}/stores/${this.props.navigation.state.params.id}`).then(res => {
            this.setState({
                Store:res.data.data[0]
            })
        })
        AsyncStorage.getItem("user",(err,res) => {
            this.setState({
                user:JSON.parse(res)
            },() => {
                console.log({StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id})
                post(`http://${SERVER}/coupons/read`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
                    console.log(res.data.data)
                    this.setState({
                        Coupon:res.data.data
                    })
                })
                get(`http://${SERVER}/stamps/${this.props.navigation.state.params.id}`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
                    this.setState({
                        Stamp:res.data.data
                    })
                    console.log(res.data.data)
                })
                get(`http://${SERVER}/menu/${this.props.navigation.state.params.id}`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
                    this.setState({
                        Menu:res.data.data,
                        loading:false
                    })
                    console.log(res.data.data)
                })
            })
        })
        
    }
    componentDidMount() {
        this.scroll.scrollToEnd()
        
    }
    ImagePick = () => {
        ImagePicker.launchImageLibrary(options, (response) => {
        
            if (response.didCancel) {
              console.log('User cancelled image picker');
            } else if (response.error) {
              console.log('ImagePicker Error: ', response.error);
            } else if (response.customButton) {
              console.log('User tapped custom button: ', response.customButton);
            } else {
              const source = { uri: response.uri };
            
              // You can also display the image using data:
              // const source = { uri: 'data:image/jpeg;base64,' + response.data };
            
              //this.setState({
                //avatarSource: source,
              //});
            }
          });
    }
    _keyboardDidShow() {
      this.scroll.scrollToEnd();
    }
  
    componentWillUnmount () {
        this.keyboardDidShowListener.remove();
      }
    OpenCamera = () => {
        ImagePicker.launchCamera(options,(response) => {
        
            if (response.didCancel) {
              console.log('User cancelled image picker');
            } else if (response.error) {
              console.log('ImagePicker Error: ', response.error);
            } else if (response.customButton) {
              console.log('User tapped custom button: ', response.customButton);
            } else {
              const source = { uri: response.uri };
            
              // You can also display the image using data:
              // const source = { uri: 'data:image/jpeg;base64,' + response.data };
            
              //this.setState({
                //avatarSource: source,
              //});
            }

        })
    }
    render() {
        return (
            <View style={{width:"100%", height:"100%"}}>
                <View onLayout={e => {
                    if(e.nativeEvent.layout.height >0) {
                        this.setState({
                            top_height:e.nativeEvent.layout.height
                        })    
                    }}} 
                    style={{marginBottom:8,width:"100%",justifyContent:"space-between",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"#615F5F"}}>
                    <TouchableOpacity style={{justifyContent:"center"}} onPress={() => this.props.navigation.goBack(null)}>
                        <Image source={require('../../assets/back.png')}/>
                    </TouchableOpacity>
                    <Text style={{color:"white",fontSize:16,marginLeft:16,alignSelf:"center"}}>
                        {this.state.Store.name}
                    </Text>
                    <TouchableOpacity onPress={() => this.props.navigation.navigate("ChatRoomConfig",{id:this.props.navigation.state.params.id})} style={{justifyContent:"center",width:"10%"}}>
                        <More style={{marginLeft:"auto"}}/>
                    </TouchableOpacity>
                </View>
                <View style={{width:"100%",justifyContent:"space-between",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"#615F5F"}}>
                    <TouchableOpacity onPress={() => this.setState({couponModal:true})} style={{flexDirection:"row"}}>
                        <Coupon/>
                        <Text style={{color:"white",marginLeft:8}}>
                            {this.state.Coupon.length}
                        </Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={() => this.setState({stampModal:true})} style={{flexDirection:"row"}}>
                        <Stamp/>
                        <Text style={{color:"white",marginLeft:8}}>
                            {this.state.Stamp.length}
                        </Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={() => this.setState({menuModal:true})} style={{flexDirection:"row"}}>
                        <Menu/>
                        <Text style={{color:"white",marginLeft:8}}>
                            {this.state.Menu.length}
                        </Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={() => this.setState({HistoryModal:true})} style={{flexDirection:"row"}}>
                        <Paper/>
                        <Text style={{color:"white",marginLeft:8}}>
                            3
                        </Text>
                    </TouchableOpacity>
                </View>
                <ScrollView onContentSizeChange={() => this.scroll.scrollToEnd()} ref={(ref) => this.scroll = ref} style={{paddingLeft:16,paddingRight:16,paddingTop:16,paddingBottom:16,backgroundColor:"#F1F1F1",width:"100%"}}>
                    <Message/>
                    <Message/>
                    <Message/>
                    <Message/>
                    <Message/>
                    <Message/>
                </ScrollView>
                <View onLayout={e => {
                    if(e.nativeEvent.layout.height >0) {
                        this.setState({
                            bottom_height:e.nativeEvent.layout.height
                        })    
                    }}}  style={{
                        shadowColor: "#000",
                        shadowOffset: {
                            width: 0,
                            height: 6,
                        },
                        shadowOpacity: 0.39,
                        shadowRadius: 8.30,
                        
                        elevation: 13,flexDirection:"row",justifyContent:"space-between",backgroundColor:"white",width:"100%",paddingTop:11,paddingBottom:10,paddingLeft:16,paddingRight:16}}>
                    <Camera onPress={() => this.OpenCamera()} style={{alignSelf:"center"}} />
                    <Gallery onPress={() => this.ImagePick()} style={{alignSelf:"center"}} />
                    <TextInput style={{width:"71%",borderColor:"#615F5F",borderWidth:1,paddingLeft:16,paddingTop:3,fontSize:15,fontWeight:"bold",paddingBottom:3}} placeholder="메시지를 입력하세요."/>
                    <Option style={{alignSelf:"center"}}  />
                </View>


                {// Top Tab Modal view
                }
                <Modal isVisible={this.state.couponModal}  onBackButtonPress={() => this.setState({couponModal:false})} >
                    <View style={{ width:Dimensions.get("screen").width,alignSelf:"center"}}>
                        <Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
                            {this.state.user.nickname}님의 보유쿠폰
                        </Text>
                        <ScrollView style={{height:"79%"}}>
                            <View style={{marginBottom:9}}>
                                <CouponItem user={this.state.user} index={0} height={0}
                                handleHeight={(e) => this.setHeight(e)} item={this.state.Coupon}/>
                            </View>
                        </ScrollView>
                    </View>
                    
                    <TouchableOpacity onPress={() => this.setState({couponModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
                            <X style={{alignSelf:"center"}}/>
                        </TouchableOpacity>
                </Modal>







                <Modal isVisible={this.state.stampModal}  onBackButtonPress={() => this.setState({stampModal:false})} >
                        <Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
                        {this.state.user.nickname}님의 보유 스탬프
                        </Text>
                    <View style={{justifyContent:"center"}}>
                    <View style={{ width:Dimensions.get("screen").width,alignSelf:"center",}}>
                        <ScrollView style={{height:"79%"}}>
                            <View style={{marginBottom:9}}>
                                <StampItem user={this.state.user} index={0} height={0}
                                handleHeight={(e) => this.setHeight(e)} item={this.state.Stamp} />
                            </View>
                        </ScrollView>
                    </View>
                    </View>
                    <TouchableOpacity onPress={() => this.setState({stampModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
                            <X style={{alignSelf:"center"}}/>
                        </TouchableOpacity>
                </Modal>

                        



                        
                <Modal isVisible={this.state.menuModal}  onBackButtonPress={() => this.setState({menuModal:false})} >
                        <Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
                            메뉴
                        </Text>
                    <View style={{justifyContent:"center"}}>
                    <View style={{ width:"100%",alignSelf:"center",}}>
                        <ScrollView style={{height:"79%"}}>
                            <View style={{marginBottom:9}}>
                                <MenuItem store={this.state.Store} isModal={true} index={0} height={0}
                                handleHeight={(e) => {}} item={this.state.Menu} />
                            </View>
                        </ScrollView>
                    </View>
                    </View>
                    <TouchableOpacity onPress={() => this.setState({menuModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
                            <X style={{alignSelf:"center"}}/>
                        </TouchableOpacity>
                </Modal>



                                
                <Modal isVisible={this.state.HistoryModal}  onBackButtonPress={() => this.setState({HistoryModal:false})} >
                        <Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
                            결제내역
                        </Text>
                    <View style={{justifyContent:"center"}}>
                    <View style={{ width:"100%",alignSelf:"center",}}>
                        <ScrollView style={{backgroundColor:"white",paddingTop:7,paddingBottom:23.5,paddingLeft:16,paddingRight:16}}>
                            <View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
                                <Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
                                <Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
                                    네네치킨 송도신도시점
                                </Text>
                                <Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
                                    20/3/1
                                </Text>
                                <Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
                                    5000
                                </Text>
                            </View>
                            <View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
                                <Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
                                <Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
                                    네네치킨 송도신도시점
                                </Text>
                                <Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
                                    20/3/1
                                </Text>
                                <Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
                                    5000
                                </Text>
                            </View>
                            <View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
                                <Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
                                <Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
                                    네네치킨 송도신도시점
                                </Text>
                                <Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
                                    20/3/1
                                </Text>
                                <Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
                                    5000
                                </Text>
                            </View>
                            
                            
                        </ScrollView>
                    </View>
                    </View>
                    <TouchableOpacity onPress={() => this.setState({HistoryModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
                            <X style={{alignSelf:"center"}}/>
                        </TouchableOpacity>
                </Modal>    
                </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    }
});