25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

448 lines
20 KiB

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