Send_Alarm.js 17.1 KB
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity, Dimensions,TextInput } from 'react-native';
import CouponeItem from '../CouponItem'
import StampItem from '../StampItem'
import Modal from 'react-native-modal'
import DropDownPicker from 'react-native-dropdown-picker';
import Setting from '../../assets/setting.svg'
import Bin from '../../assets/bin.svg'
import AsyncStorage from '@react-native-community/async-storage';
import {get,post, delete as remove} from 'axios'
import { SERVER } from '../../common/servername';
import moment from 'moment'
import Search from '../../assets/search_yellow.svg'
import X from '../../assets/X.svg'
export default class AddTab extends Component {
    static navigationOptions = {
        
        headerShown: false
        
    }
    state = {
        isModalVisible:false,
        current:1,
        select:'',
        select_type:'전체',
        dropdownVisible:false,
        dropdownVisible_type:false,
        store:[],
        selectId:0,
        selectId_type:0,
        menu:[],
        user:{},
        content:""
    }
    constructor(props) {
        super(props)
    }
    componentDidMount() {
        this.onLoad()
        
        AsyncStorage.getItem("user",(err,res) => {
            if(res) {
                this.setState({
                    user:JSON.parse(res)
                })
                get(`http://${SERVER}/stores/managerRead/${JSON.parse(res).id}`).then(res => {
                    if(res.data.success) {
                        this.setState({
                            store:res.data.data,
                            select:res.data.data[0].name,
                            selectId:res.data.data[0].id
                        })
                        
                        get(`http://${SERVER}/menu/${res.data.data[0].id}`).then(res => {
                            if(res.data.success) {
                            this.setState({
                                menu:res.data.data,
                            })
                            console.log(res.data.data)
                            }
                        })
                    }
                })
            }
        })

    }
    
    onLoad = () => {
        this.props.navigation.addListener('willFocus', () => {
            this.onRefresh();
        });
    };
    onRefresh = () => {
        get(`http://${SERVER}/stores/managerRead/${this.state.user.id}`).then(res => {
            if(res.data.success) {
                this.setState({
                    store:res.data.data,
                    select:res.data.data[0].name,
                    selectId:res.data.data[0].id
                })
                
                get(`http://${SERVER}/menu/${res.data.data[0].id}`).then(res => {
                    if(res.data.success) {
                    this.setState({
                        menu:res.data.data,
                    })
                    console.log(res.data.data)
                    }
                })
            }
        })

    }
    pushAlarm = () => {
        post(`http://${SERVER}/fcms`,{StoreId:this.state.selectId,name:this.state.select,content:this.state.content,type:this.state.selectId_type}).then(res => {
            if(res.data.success) {
                this.props.navigation.goBack(null)
            }
            else {
                alert("서버 오류입니다. 다시 시도해주세요.")
            }
        })
    }
    handleDropdown = (e) => {
        this.setState({dropdownVisible:false,select:e.name,selectId:e.id})
        if(this.state.dropdownVisible_type==true) {
            this.setState({
                dropdownVisible_type:false
            })
        }
    }
    handleDropdown_type = (e,type) => {
        this.setState({dropdownVisible_type:false,select_type:e,selectId_type:type})
        if(this.state.dropdownVisible==true) {
            this.setState({
                dropdownVisible:false
            })
        }
    }
    render() {
        return (
            <View>
                <View style={{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={{backgroundColor:"white",paddingTop:16,height:"100%"}}>
                    <View style={{flexDirection:"row"}}>
                        <View style={{width:"75%",paddingLeft:16,paddingRight:16,}}>
                            <TouchableOpacity onPress={() => {this.setState({dropdownVisible:true,dropdownVisible_type:false})}} style={{paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1}}>
                                <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                    {this.state.select}
                                </Text>
                            </TouchableOpacity>
                        
                        </View>
                    </View>
                    {this.state.dropdownVisible? 
                        <View style={{width:"75%",height:"100%",position:"absolute",backgroundColor:"transparent",zIndex:10,paddingLeft:16,paddingRight:16}}>
                            <View>
                                {this.state.store.map((e,i,arr) => {
                                    return (
                                        
                                        <TouchableOpacity onPress={() => this.handleDropdown(e)
                                        } 
                                        style={[{position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0},i==0?{borderTopWidth:1}:i==arr.length-1?{borderBottomWidth:1}:{}]}>
                                            <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                                {e.name}
                                            </Text>
                                        </TouchableOpacity>
                                    )
                                })}
                            </View>
                        </View>:undefined}
                        <View style={{marginTop:16}}>
                            <View style={{flexDirection:"row"}}>
                            <View style={{width:"75%",paddingLeft:16,paddingRight:16}}>
                                <TouchableOpacity onPress={() => this.setState({dropdownVisible_type:true,dropdownVisible:false})} style={{paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1}}>
                                    <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                        {this.state.select_type}
                                    </Text>
                                </TouchableOpacity>
                                
                            </View>
                        </View>
                        {this.state.dropdownVisible_type? 
                            <View style={{width:"75%",height:"100%",position:"absolute",backgroundColor:"transparent",zIndex:10,paddingLeft:16,paddingRight:16}}>
                                <View>
                                    
                                        {//,i==0?{borderTopWidth:1}:i==arr.length-1?{borderBottomWidth:1}:{}}
                                        }
                                    <TouchableOpacity onPress={() => this.handleDropdown_type('전체','all')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:1}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                            {'전체'}
                                        </Text>
                                    </TouchableOpacity>
                                    <TouchableOpacity onPress={() => this.handleDropdown_type(`쿠폰고객 ( ${1}명 )`,'coupon')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                            {`쿠폰고객 ( ${1}명 )`}
                                        </Text>
                                    </TouchableOpacity>
                                    <TouchableOpacity onPress={() => this.handleDropdown_type(`스탬프고객 ( ${1}명 )`,'stamp')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                            {`스탬프고객 ( ${1}명 )`}
                                        </Text>
                                    </TouchableOpacity>
                                    <TouchableOpacity onPress={() => this.handleDropdown_type(`찜한고객 ( ${1}명 )`,'like')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                        {`찜한고객 ( ${1}명 )`}
                                        </Text>
                                    </TouchableOpacity>
                                    <TouchableOpacity onPress={() => this.handleDropdown_type(`리뷰고객 ( ${1}명 )`,'review')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:0,borderTopWidth:0}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                        {`리뷰고객 ( ${1}명 )`}
                                        </Text>
                                    </TouchableOpacity>
                                    <TouchableOpacity onPress={() => this.handleDropdown_type('개별선택','ind')} 
                                            style={[{zIndex:10,position:"relative",width:"100%",backgroundColor:"white",paddingLeft:16,paddingTop:11,paddingBottom:9,backgroundColor:"white",borderColor:"#FFD63A",borderWidth:1,borderBottomWidth:1,borderTopWidth:0}]}>
                                        <Text style={{fontSize:14,fontWeight:"bold",color:"#615F5F"}}>
                                        {`개별선택`}
                                        </Text>
                                    </TouchableOpacity>


                                </View>
                        </View>:undefined}
                    <View style={{height:"100%",paddingTop:16,paddingBottom:16,zIndex:0}}>
                        <View>
                                <Text style={{textAlignVertical:"center",paddingLeft:16,paddingRight:16,color:"#979292",fontSize:12,fontWeight:"200"}}>
                                    5인이상 단체알림 :  4 제한
                                </Text>
                                <Text style={{textAlignVertical:"center",paddingLeft:16,paddingRight:16,color:"#979292",fontSize:12,fontWeight:"200"}}>
                                    5인미만 개별알림 :  2 제한
                                </Text>
                        </View>
                        <View style={{width:"100%",marginTop:16.2}}>
                            <TextInput value={this.state.content} onChangeText={e => this.setState({content:e})} placeholder={`ex ) 단골 고객을 위한 특별한 계약\n\n1월 26일 배곧카페에서 새해 축하 치즈게이크를 무료로 드리니 많이 방문해 주시기 바랍니다.\n\n단, 1월 26일 당일 매장 방문 고객에 한함.`} style={{fontSize:14,paddingTop:23,paddingBottom:23,height:161,textAlignVertical:"top",paddingLeft:37,paddingRight:37,borderColor:"#615F5F",borderWidth:1}} multiline={true}/>
                        </View>
                    <View style={{flexDirection:'row',}}>
                        <TouchableOpacity onPress={() => this.pushAlarm()} style={{width:"50%",backgroundColor:"#FFD63A",paddingTop:16,paddingBottom:16}}>
                            <Text style={{color:"#000000",fontSize:12,fontWeight:"bold",textAlign:"center"}}>
                                발송
                            </Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={() => this.props.navigation.goBack(null)} style={{width:"50%",backgroundColor:"white",paddingTop:16,paddingBottom:16}}>
                            <Text style={{color:"#615F5F",fontSize:12,fontWeight:"bold",textAlign:"center"}}>
                                취소
                            </Text>
                        </TouchableOpacity>
                    </View>
                    <View style={{width:"92%",marginRight:16,flexDirection:"row",marginLeft:16,paddingBottom:16,borderBottomColor:"#BDBCBC",borderBottomWidth:1}}>
                        <View style={{marginTop:16,borderRightColor:"#BDBCBC",borderRightWidth:1,paddingRight:10}}>
                            <View style={{flexDirection:"row",justifyContent:"space-between",marginBottom:16}}>
                                <Text style={{color:"#615F5F",fontSize:14}}>
                                    20.1.23
                                </Text>
                                <Text style={{width:"70%"}} numberOfLines={1}>
                                    크리스마스 특별 이벤트 ㄴ어리ㅏㅁㅇ너리ㅏㄴㅇ머라ㅣ
                                </Text>
                            </View>
                                        
                            <View style={{flexDirection:"row",justifyContent:"space-between"}}>
                                <Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
                                    발송 {1234}
                                </Text>
                                <Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
                                    미확인 {990}
                                </Text>
                                <Text style={{color:"#615F5F",fontSize:15,fontWeight:"bold"}}>
                                    확인 {345}
                                </Text>
                            </View>
                        </View>
                        <View style={{justifyContent:"center",marginTop:16,marginLeft:"auto",marginRight:"auto"}}>
                            <Search onPress={() => this.setState({isModalVisible:true})} width={20} height={20} style={{marginLeft:"auto",marginRight:"auto"}}/>
                        </View>
                    </View>
                    </View>
                    </View>
                </ScrollView>

                 
      <Modal onBackButtonPress={() => this.setState({isModalVisible:false})} onBackdropPress={() => this.setState({isModalVisible:false})} isVisible={this.state.isModalVisible}>
        
                <View style={{width:"100%",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"white"}}>
                    <X style={{marginLeft:"auto"}}/>
                    <View style={{flexDirection:"row"}}>
                    <Text style={{fontSize:16,fontWeight:"bold"}}>
                        {`${"크리스마스 특별 이벤트 ㄴ어리ㅏㅁㅇ너리ㅏㄴㅇ머라ㅣ"}`}
                    </Text>
                    <Text style={{fontSize:12,marginTop:16,fontWeight:"300",marginLeft:"auto",textAlign:"right"}}>
                        {`${moment(new Date()).format("YYYY.M.DD")}`}
                    </Text>
                    </View>
                    <View>
                        <Text style={{marginTop:5}}>
                            {`${"item.content"}`}
                        </Text>
                    </View>
                </View>
      </Modal>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    }
});