Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

571 рядки
25 KiB

  1. import React, { Component, Fragment } from 'react';
  2. import { makeStyles } from '@material-ui/core/styles';
  3. import clsx from 'clsx';
  4. import Selects from 'react-select';
  5. import SnackbarContent from "components/Snackbar/SnackbarContent.js";
  6. import Button1 from "components/CustomButtons/Button.js";
  7. import image1 from "../../../assets/img/mail.png"
  8. import GridContainer from "components/Grid/GridContainer.js";
  9. import Carousel from "react-slick";
  10. import GridItem from "components/Grid/GridItem.js";
  11. import classNames from "classnames";
  12. import swal from 'sweetalert';
  13. import Icon from "@material-ui/core/Icon";
  14. import Grid from '@material-ui/core/Grid';
  15. import TextField from '@material-ui/core/TextField';
  16. import Button from '@material-ui/core/Button';
  17. import Dialog from '@material-ui/core/Dialog';
  18. import ListItemText from '@material-ui/core/ListItemText';
  19. import ListItem from '@material-ui/core/ListItem';
  20. import List from '@material-ui/core/List';
  21. import Divider from '@material-ui/core/Divider';
  22. import AppBar from '@material-ui/core/AppBar';
  23. import Toolbar from '@material-ui/core/Toolbar';
  24. import IconButton from '@material-ui/core/IconButton';
  25. import Typography from '@material-ui/core/Typography';
  26. import CloseIcon from '@material-ui/icons/Close';
  27. import Slide from '@material-ui/core/Slide';
  28. import Select from '@material-ui/core/Select';
  29. import MenuItem from '@material-ui/core/MenuItem';
  30. import Card from "components/Card/Card.js";
  31. import CardBody from "components/Card/CardBody.js";
  32. import FormControl from '@material-ui/core/FormControl';
  33. import { Form, FormGroup, ControlLabel, SelectPicker } from "rsuite";
  34. import NumberFormat from 'react-number-format';
  35. const useStyles = makeStyles((theme) => ({
  36. root: {
  37. width: '100%',
  38. },
  39. button: {
  40. marginTop: theme.spacing(1),
  41. marginRight: theme.spacing(1),
  42. },
  43. actionsContainer: {
  44. marginBottom: theme.spacing(2),
  45. },
  46. resetContainer: {
  47. padding: theme.spacing(3),
  48. },
  49. appBar: {
  50. position: 'relative',
  51. },
  52. title: {
  53. marginLeft: theme.spacing(2),
  54. flex: 1,
  55. },
  56. root: {
  57. '&:hover': {
  58. backgroundColor: 'transparent',
  59. },
  60. },
  61. icon: {
  62. borderRadius: '50%',
  63. width: 16,
  64. height: 16,
  65. boxShadow: 'inset 0 0 0 1px rgba(16,22,26,.2), inset 0 -1px 0 rgba(16,22,26,.1)',
  66. backgroundColor: '#f5f8fa',
  67. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.8),hsla(0,0%,100%,0))',
  68. '$root.Mui-focusVisible &': {
  69. outline: '2px auto rgba(19,124,189,.6)',
  70. outlineOffset: 2,
  71. },
  72. 'input:hover ~ &': {
  73. backgroundColor: '#ebf1f5',
  74. },
  75. 'input:disabled ~ &': {
  76. boxShadow: 'none',
  77. background: 'rgba(206,217,224,.5)',
  78. },
  79. },
  80. checkedIcon: {
  81. backgroundColor: '#137cbd',
  82. backgroundImage: 'linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0))',
  83. '&:before': {
  84. display: 'block',
  85. width: 16,
  86. height: 16,
  87. backgroundImage: 'radial-gradient(#fff,#fff 28%,transparent 32%)',
  88. content: '""',
  89. },
  90. 'input:hover ~ &': {
  91. backgroundColor: '#106ba3',
  92. },
  93. },
  94. }));
  95. const Transition = React.forwardRef(function Transition(props, ref) {
  96. return <Slide direction="up" ref={ref} {...props} />;
  97. });
  98. const DataCheckout = function ({ checkoutprofile, province, cities, backend, checkoutproduct, ...props }) {
  99. const settings = {
  100. dots: true,
  101. infinite: true,
  102. speed: 500,
  103. slidesToShow: 1,
  104. slidesToScroll: 1,
  105. autoplay: false,
  106. time: 5
  107. };
  108. const classes = useStyles();
  109. const [open, setOpen] = React.useState(false);
  110. const handleClickOpen = () => {
  111. setOpen(true);
  112. };
  113. const { ...rest } = props;
  114. const imageClasses = classNames(
  115. classes.imgRaised,
  116. classes.imgRoundedCircle,
  117. classes.imgFluid
  118. );
  119. const navImageClasses = classNames(classes.imgRounded, classes.imgGallery);
  120. const [formValue, setFormValue] = React.useState({
  121. order_id: GenerateID(),
  122. cust_name: "",
  123. cust_telp: "",
  124. cust_address: "",
  125. product_img: "",
  126. product_name: "",
  127. product_color: "",
  128. product_quantity: "",
  129. product_price: "",
  130. product_courier: "",
  131. note: "",
  132. // selectPicker: 'Louisa',
  133. status : 1,
  134. });
  135. // const [formValue, setFormValue] = React.useState({
  136. // order_id: "Trx-Ord-9ab8ab88",
  137. // cust_name: "Yusmar",
  138. // cust_telp: "087797315685",
  139. // cust_address: "Thamrin Indrapura Jl.Aipda Karel Satsuit Tubun,17 Ilir, Kec.Ilir Tim.I, Palembang, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114",
  140. // product_img: null,
  141. // product_name: "NMAX 155",
  142. // product_color: "Red",
  143. // product_quantity: "1",
  144. // product_price: "28545000",
  145. // product_courier: "JNE",
  146. // note: "Tes",
  147. // });
  148. function GenerateID(){
  149. var dt = new Date().getTime();
  150. var uuid = 'Trx-Ord-yyyyyyyy'.replace(/[y]/g, function(c) {
  151. var r = (dt + Math.random()*16)%16 | 0;
  152. dt = Math.floor(dt/16);
  153. return (c=='x' ? r :(r&0x3|0x8)).toString(16);
  154. });
  155. return uuid;
  156. }
  157. const CheckoutAlamat = checkoutprofile.map((data) => {
  158. return (
  159. <div align="center">
  160. <div style={{padding:"10px"}}>
  161. <Typography variant="h6" align="center" className={classes.title}>
  162. Informasi Customer
  163. </Typography><br></br>
  164. <GridContainer>
  165. <GridItem className={classes.marginAuto}>
  166. <Carousel>
  167. <img src={image1} style={{width:"1100px"}}/><br></br>
  168. </Carousel>
  169. </GridItem>
  170. </GridContainer>
  171. <FormGroup>
  172. <FormControl name="cust_name" value={data.username} type="text"/>
  173. </FormGroup>
  174. <h5><b>{data.username.toUpperCase()}</b></h5>
  175. <FormGroup>
  176. <FormControl name="cust_telp" value={data.telp} type="text"/>
  177. </FormGroup>
  178. <h5 style={{marginTop:"-20px"}}><b>{data.telp}</b></h5><br/>
  179. {/* <FormGroup>
  180. <FormControl name="cust_telp" value={data.email} type="text"/>
  181. </FormGroup> */}
  182. <h5 style={{marginTop:"-20px"}}><b>{data.email.toUpperCase()}</b></h5>
  183. <FormGroup>
  184. <FormControl name="cust_address" value={data.address} type="text"/>
  185. </FormGroup>
  186. </div>
  187. </div>
  188. );
  189. })
  190. const CheckoutProdukPesanan = checkoutproduct.map((data) => {
  191. const handleChange = (event) => {
  192. setColor(event.target.value);
  193. };
  194. const handleChanges = (event) => {
  195. setPengiriman(event.target.value);
  196. };
  197. const [color, setColor] = React.useState('');
  198. const [pengiriman, setPengiriman] = React.useState('');
  199. const handleClose = () => {
  200. setFormValue({
  201. ...formValue,
  202. product_courier: pengiriman,
  203. })
  204. setOpen(false);
  205. };
  206. return (
  207. <div align="center">
  208. <Card className={classes.textCenter} align="center">
  209. <CardBody>
  210. <div style={{padding:"10px"}}>
  211. <Typography variant="h6" align="left" className={classes.title}>
  212. Pesanan Produk
  213. </Typography><br></br><hr></hr>
  214. <GridContainer>
  215. <Grid item xs>
  216. <FormGroup>
  217. <FormControl name="product_img" value={`${backend}${data.img[0]["url"]}`} type="text"/>
  218. </FormGroup>
  219. <div align="center">
  220. <h4><b>Produk Dipesan</b></h4>
  221. <img className={navImageClasses} width="200px" alt="First slide" src={`${backend}${data.img[0]["url"]}`} />
  222. </div>
  223. </Grid>
  224. <Grid item xs>
  225. <div align="center">
  226. <h4></h4><br></br><br></br><br></br><br></br>
  227. <FormGroup>
  228. <FormControl name="product_name" value={data.name} type="text"/>
  229. </FormGroup>
  230. <h5><b>{data.name}</b></h5>
  231. </div>
  232. </Grid>
  233. <Grid item xs>
  234. <div align="center">
  235. <h4><b>Warna</b></h4><br></br><br></br><br></br>
  236. <FormGroup>
  237. <FormControl className={classes.formControl}>
  238. <Select
  239. labelId="demo-simple-select-label"
  240. id="demo-simple-select"
  241. value={color}
  242. name="product_color"
  243. onChange={(e)=>{
  244. setFormValue({
  245. ...formValue,
  246. product_color: e.target.value.toString()
  247. })
  248. }}
  249. >
  250. <MenuItem value={1}>Hitam</MenuItem>
  251. <MenuItem value={2}>Merah</MenuItem>
  252. <MenuItem value={3}>Biru</MenuItem>
  253. <MenuItem value={4}>Putih</MenuItem>
  254. </Select>
  255. </FormControl>
  256. </FormGroup>
  257. </div>
  258. </Grid>
  259. <Grid item xs>
  260. <div align="center">
  261. <h4><b>Harga Satuan</b></h4><br></br><br></br><br></br>
  262. <h5>
  263. <b>
  264. <NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} />
  265. </b>
  266. </h5>
  267. </div>
  268. </Grid>
  269. <Grid item xs>
  270. <div align="center">
  271. <h4><b>Jumlah Unit</b></h4><br></br><br></br><br></br>
  272. <FormGroup>
  273. <FormControl className={classes.formControl}>
  274. <TextField
  275. id="outlined-number"
  276. type="number"
  277. align="center"
  278. name="quantity"
  279. InputLabelProps={{
  280. shrink: false,
  281. }}
  282. onInput={(e)=>{
  283. setFormValue({
  284. ...formValue,
  285. product_quantity: e.target.value
  286. })
  287. }}
  288. />
  289. </FormControl>
  290. </FormGroup>
  291. </div>
  292. </Grid>
  293. <Grid item xs>
  294. <div align="center">
  295. <h4><b>Sub Total Produk</b></h4><br></br><br></br><br></br>
  296. <h5><b>Total Rp.<NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></b></h5>
  297. </div>
  298. </Grid>
  299. </GridContainer>
  300. <GridContainer style={{padding:"20px"}}>
  301. <Grid item xs style={{padding:"20px"}}>
  302. <TextField
  303. id="outlined-full-width"
  304. label="Pesan"
  305. style={{ margin: 8 }}
  306. placeholder="( Opsional ) Tinggalkan Pesan Kepada Dealer"
  307. fullWidth
  308. margin="normal"
  309. InputLabelProps={{
  310. shrink: true,
  311. }}
  312. variant="outlined"
  313. onInput={(e)=>{
  314. setFormValue({
  315. ...formValue,
  316. note: e.target.value
  317. })
  318. }}
  319. />
  320. </Grid>
  321. <Grid item xs style={{padding:"20px"}}><br></br>
  322. <Button variant="outlined" color="primary" onClick={handleClickOpen}>
  323. Pilih Opsi Pengiriman
  324. </Button>
  325. <span>{formValue.product_courier}</span>
  326. <Dialog fullScreen open={open} onClose={handleClose} TransitionComponent={Transition}>
  327. <AppBar className={classes.appBar}>
  328. <Toolbar>
  329. <IconButton edge="start" color="inherit" onClick={handleClose} aria-label="close">
  330. <CloseIcon />
  331. </IconButton>
  332. <Typography variant="h6" className={classes.title}>
  333. Pilih Opsi Pengiriman
  334. </Typography>
  335. <Button autoFocus color="inherit" onClick={handleClose}>
  336. Pilih
  337. </Button>
  338. </Toolbar>
  339. </AppBar>
  340. <List>
  341. <ListItem button
  342. id="POS"
  343. selected={(pengiriman=="POS")}
  344. onClick={(e)=>{
  345. setPengiriman("POS");
  346. }}
  347. >
  348. <ListItemText primary="POS" secondary="Akan diterima pada tanggal 2 Apr - 6 Apr" />
  349. </ListItem>
  350. <Divider />
  351. <ListItem button
  352. id="JNE"
  353. selected={(pengiriman=="JNE")}
  354. onClick={(e)=>{
  355. setPengiriman("JNE");
  356. }}
  357. >
  358. <ListItemText primary="JNE" secondary="Akan diterima pada tanggal 30 Mar - 2 Apr" />
  359. </ListItem>
  360. <ListItem button
  361. id="TIKI"
  362. selected={(pengiriman=="TIKI")}
  363. onClick={(e)=>{
  364. setPengiriman("TIKI");
  365. }}
  366. >
  367. <ListItemText primary="TIKI" secondary="Akan diterima pada tanggal 1 Apr - 4 Apr, COD (Bayar di Tempat) tidak didukung" />
  368. </ListItem>
  369. </List>
  370. </Dialog>
  371. </Grid>
  372. <Grid item xs align="right" style={{padding:"20px"}}><br></br>
  373. <h5><b>Total Rp.<NumberFormat value={data.price} displayType={'text'} thousandSeparator={true} prefix={'Rp.'} /></b></h5>
  374. <FormGroup>
  375. <FormControl name="product_price" value={data.price} type="text"/>
  376. </FormGroup>
  377. </Grid>
  378. </GridContainer>
  379. </div>
  380. </CardBody>
  381. </Card>
  382. </div>
  383. );
  384. })
  385. return (
  386. <div style={{padding:"50px"}}>
  387. <div align="center" className={classes.section} id="notifications">
  388. <SnackbarContent
  389. message={
  390. <h2><b>Checkout</b></h2>
  391. }
  392. align="center"
  393. color="info"
  394. />
  395. </div>
  396. <Form
  397. onSubmit={async(value) => {
  398. var newformValue = {
  399. ...formValue,
  400. cust_name: checkoutprofile[0].username,
  401. cust_telp: checkoutprofile[0].telp.toString(),
  402. cust_address: checkoutprofile[0].address,
  403. // product_img: checkoutproduct[0].img,
  404. product_name: checkoutproduct[0].name,
  405. product_price: checkoutproduct[0].price,
  406. }
  407. setFormValue(newformValue)
  408. const response = await fetch(
  409. "/api/transaction/create",
  410. {
  411. method: "POST",
  412. headers: {
  413. 'Content-Type': 'application/json'
  414. },
  415. body: JSON.stringify(newformValue),
  416. }
  417. );
  418. if (response.ok) {
  419. var res = await response.json();
  420. if (res["STATUS"] === 1) {
  421. res["DATA"]["transaction"];
  422. swal("Produk Berhasil Ditambah ke Keranjang", "Silahkan Cek Keranjang Belanja Anda", "success");
  423. }
  424. else {
  425. swal("Produk Gagal Ditambah ke Keranjang", "Silahkan Coba Lagi", "error");
  426. }
  427. } else {
  428. swal("Transaksi Gagal", "Silahkan Coba Lagi", "error");
  429. }
  430. }}
  431. >
  432. <div>
  433. <Card className={classes.textCenter} align="center">
  434. <CardBody>
  435. <GridContainer>
  436. <GridItem xs={6}>
  437. {CheckoutAlamat}
  438. </GridItem>
  439. <GridItem xs={6}>
  440. <div style={{padding:"10px"}}>
  441. <Typography variant="h6" align="center" className={classes.title}>
  442. Informasi Pengiriman
  443. </Typography><br></br>
  444. <GridContainer>
  445. <GridItem className={classes.marginAuto}>
  446. <Carousel>
  447. <img src={image1} style={{width:"1100px"}}/><br></br>
  448. </Carousel>
  449. </GridItem>
  450. </GridContainer><br/>
  451. <Fragment>
  452. <Select
  453. className="basic-single"
  454. classNamePrefix="select"
  455. name="provinsi"
  456. fullWidth
  457. placeholder="Provinsi"
  458. />
  459. </Fragment><br/><br/>
  460. <Fragment>
  461. <Select
  462. className="basic-single"
  463. classNamePrefix="select"
  464. name="kabupaten"
  465. fullWidth
  466. placeholder="Kabupaten"
  467. />
  468. </Fragment><br/><br/>
  469. <Fragment>
  470. <Select
  471. className="basic-single"
  472. classNamePrefix="select"
  473. name="kota"
  474. fullWidth
  475. placeholder="Kota"
  476. />
  477. </Fragment><br/><br/>
  478. <TextField
  479. id="outlined-full-width"
  480. label="Alamat Lengkap"
  481. placeholder="Masukan Alamat Lengkap"
  482. fullWidth
  483. height="50px"
  484. margin="normal"
  485. InputLabelProps={{
  486. shrink: true,
  487. }}
  488. variant="outlined"
  489. />
  490. </div>
  491. </GridItem>
  492. </GridContainer>
  493. </CardBody>
  494. </Card>
  495. </div>
  496. <div>
  497. {CheckoutProdukPesanan}
  498. </div>
  499. <div>
  500. <GridContainer>
  501. <Grid item xs={6} style={{padding:"20px"}}>
  502. <Button1 color="info" style={{width:"100%"}}
  503. type="submit"
  504. // onClick={async function (e) {
  505. // // setFormValue({
  506. // // cust_name : data.username,
  507. // // ... formValue
  508. // // });
  509. //
  510. // }}
  511. >
  512. <Icon className={classes.icons}>attach_money</Icon>
  513. Buat Pesanan
  514. </Button1>
  515. </Grid>
  516. <Grid item xs={6} style={{padding:"20px"}}>
  517. <Button1 color="danger" style={{width:"100%"}}
  518. // swal({
  519. // title: "Anda Ingin Menghapus Pesanan ?",
  520. // icon: "warning",
  521. // buttons: true,
  522. // dangerMode: true,
  523. // })
  524. // .then((willDelete) => {
  525. // if (willDelete) {
  526. // swal("Pesanan Anda Berhasil Dihapus", {
  527. // icon: "success",
  528. // });
  529. // } else {
  530. // swal("Selamat Belanja Kembali");
  531. // }
  532. // });
  533. >
  534. <Icon className={classes.icons}>attach_money</Icon>
  535. Batalkan Pesanan
  536. </Button1>
  537. </Grid>
  538. </GridContainer>
  539. {/* <GridContainer>
  540. <Grid item xs={6} style={{padding:"20px"}}>
  541. <Button1 color="info" onClick={(e)=>{snap.pay(transactionToken);}} style={{width:"100%"}}>
  542. <Icon className={classes.icons}>attach_money</Icon>
  543. Bayar Pesanan
  544. </Button1>
  545. </Grid>
  546. </GridContainer> */}
  547. </div>
  548. </Form>
  549. </div>
  550. );
  551. }
  552. export default DataCheckout;