Payment.js 8.87 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
Kim, Subin's avatar
Kim, Subin committed
2
3
import MainNav from '../Components/MainNav';
import SubNav from '../Components/SubNav';
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import DaumPostcode from "react-daum-postcode";
5
import { Container, Card, Row, Col, Button, Form } from 'react-bootstrap';
Kim, Subin's avatar
Kim, Subin committed
6
7
8

function Payment() {

9
    const [paymentWay, setPaymentWay] = useState([])
Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    const [isAddress, setIsAddress] = useState("");
    const [isZoneCode, setIsZoneCode] = useState();
    const [isPostOpen, setIsPostOpen] = useState();
    const [post, setPost] = useState([])

    function postClick() {
        if (post.length !== 0) {
            setPost([])
        }
        else {
            setPost(
                <div>
                    <DaumPostcode style={postCodeStyle} onComplete={handleComplete} />
                </div>
            )
        }

    }

    const handleComplete = (data) => {
        let fullAddress = data.address;
        let extraAddress = "";

        if (data.addressType === "R") {
            if (data.bname !== "") {
                extraAddress += data.bname;
            }
            if (data.buildingName !== "") {
                extraAddress +=
                    extraAddress !== "" ? `, ${data.buildingName}` : data.buildingName;
            }
            fullAddress += extraAddress !== "" ? ` (${extraAddress})` : "";
        }
        setIsZoneCode(data.zonecode);
        setIsAddress(fullAddress);
        setIsPostOpen(false);
    };
    const postCodeStyle = {
        display: "block",
        position: "absolute",
        // top: "50%",
        width: "400px",
        height: "500px",
        padding: "7px",
    };
55
56
57
58
59
60
61

    function handleClick() {
        if (paymentWay.length !== 0) {
            setPaymentWay([])
        }
        else {
            const a = (
62
63
                <Row className="justify-content-md-center">
                    <Col md={6} className="border m-5 p-5">
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
                    <Form>
                        <Form.Group controlId="exampleForm.ControlSelect1">
                            <Form.Label>입금은행</Form.Label>
                            <Form.Control as="select" placeholder="입금은행을 선택하세요.">
                                <option>농협 / 352-0559-2528-83 / 김수빈</option>
                                <option>우리은행 / 0000-000-000000 / 이재연</option>
                                <option>국민은행 / 111111-11-111111 / 윤대기</option>
                            </Form.Control>
                        </Form.Group>
                        <Form.Group controlId="formName">
                            <Form.Label>입금자</Form.Label>
                            <Form.Control type="email" placeholder="윤지원" />
                        </Form.Group>
                        <Form.Group controlId="formDay">
                            <Form.Label>입금예정일</Form.Label>
                            <Form.Control type="date" />
                        </Form.Group>
                    </Form>
82
83
84
                    </Col>
                    
                </Row>)
85
86
87
88
            setPaymentWay(a)
        }
    }

89
    function handleClick2() {
90
91
92
93
        if (paymentWay.length !== 0) {
            setPaymentWay([])
        }
    }
94
    const [num, setNum] = useState(0)
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    function plusNum() {
        setNum(num + 1)
    }
    function minusNum() {
        if (num === 0) {
            setNum(0)
        }
        else {
            setNum(num - 1)

        }
    }
    function deleteCart() {
        //장바구니 DB에서 해당 항목 삭제 
        console.log('카트에 담긴 항목을 삭제했습니다.')
    }
Kim, Subin's avatar
Kim, Subin committed
112
113
    return (
        <div>
Kim, Subin's avatar
Kim, Subin committed
114
115
            <MainNav />
            <SubNav />
116
            <Container>
Jiwon Yoon's avatar
Jiwon Yoon committed
117
                <h3 className="my-5 font-weight-bold text-center">주문/결제</h3>
118
                <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
119
                    <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문자 정보</h5>
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                    <Row className="justify-content-md-center">
                        <Col md={4}>
                            <Form>
                                <Form.Group controlId="formBasicName">
                                    <Form.Label>이름</Form.Label>
                                    <Form.Control type="text" placeholder="윤지원" />
                                </Form.Group>
                                <Form.Group controlId="formBasicEmail">
                                    <Form.Label>이메일</Form.Label>
                                    <Form.Control type="email" placeholder="jiwon5393@naver.com" />
                                </Form.Group>
                                <Form.Group controlId="formBasicTel">
                                    <Form.Label>휴대전화</Form.Label>
                                    <Form.Control type="tel" placeholder="010-0000-0000" />
                                </Form.Group>
                            </Form>
                        </Col>
                    </Row>

139
140
141
142

                </div>

                <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
143
144
145
146
147
148
149
                    <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>배송지 정보</h5>
                    <Row>

                        <Col>
                            <Button className="my-3" style={{ background: "#91877F", borderColor: '#91877F' }} onClick={postClick}>우편번호</Button>
                        </Col>
                    </Row>
Jiwon Yoon's avatar
Jiwon Yoon committed
150
                    {post}
151
152
153
                </div>

                <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
154
                    <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문상품정보</h5>
155
                    <Card >
156
157
158
                        <Row className="mx-1">
                            <Col xs={2} sm={2} className="text-center my-auto">
                                <input className="" type="checkbox" id="exampleCheck1" />
159
                            </Col>
160
                            <Col className="text-center">
161
162
                                <Card.Img className="img-fluid" variant="top" src="img/asd.jpg" style={{ width: '20rem' }} />
                            </Col>
163
                            <Col md={6} className="p-2">
164
                                <Card.Body>
165
                                    <input type="image" src="https://img.icons8.com/fluent-systems-regular/24/000000/close-window.png" className="float-right" onClick={deleteCart} />
166
167
168
                                    <Card.Title className="font-weight-bold mt-3">제품명</Card.Title>
                                    <Card.Text>가격</Card.Text>
                                    <Card.Text>옵션</Card.Text>
169
170
171
172
173
                                    <Card.Text>수량</Card.Text>
                                    <div>
                                        <input type="image" src="https://img.icons8.com/ios-glyphs/20/000000/minus-math.png" className="align-middle" onClick={minusNum} />
                                        <input type="text" style={{ width: '30px' }} className="text-center align-middle mx-1" placeholder="1" value={num} readOnly></input>
                                        <input type="image" src="https://img.icons8.com/ios-glyphs/20/000000/plus-math.png" className="align-middle" onClick={plusNum} />
174
175
176
177
178
179
180
                                    </div>
                                </Card.Body>
                            </Col>
                        </Row>
                    </Card>
                </div>

Jiwon Yoon's avatar
Jiwon Yoon committed
181
                <div className="p-5 m-5" style={{ background: '#F7F3F3' }}>
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
                    <ul className="pl-0" style={{ listStyle: 'none' }}>
                        <li>
                            <span className="text-secondary"> 상품금액</span>
                            <span className="text-secondary float-right">12,000</span>
                        </li>
                        <li>
                            <span className="text-secondary">배송비</span>
                            <span className="text-secondary float-right">2,500</span>
                        </li>
                    </ul>
                    <div className="my-1 pt-2 border-top font-weight-bold">
                        결제금액<span className="float-right">14,500</span>
                    </div>
                </div>

                <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
198
                    <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>결제수단</h5>
199
                    <div className="text-center mt-5">
200
201
202
203
204
205
206
                        <Button variant="success" onClick={handleClick} >무통장입금</Button>
                        <Button variant="warning" style={{ color: '#ffffff' }} onClick={handleClick2}>카카오페이</Button>
                    </div>
                    {paymentWay}

                </div>
            </Container>
Kim, Subin's avatar
Kim, Subin committed
207
208
209
210
211
        </div>
    )
}

export default Payment