AccordionItem.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import React from 'react';
  2. import {useState} from "react";
  3. import {Accordion, AccordionDetails, AccordionSummary, Box, Divider, Grid, Typography} from "@mui/material";
  4. import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
  5. import {backURL} from "../../actions/PathDB";
  6. import imgNotFound from "../../img/catalog/imgNotFound.png";
  7. import Link from "react-router-dom/es/Link";
  8. import {AccordionHeaderText} from "./AccordionHeaderText";
  9. import {timeCalc} from "../ProductPage/timeCalc";
  10. export const AccordionItem = ({data}) => {
  11. const time = timeCalc(+data['createdAt'])
  12. const [status, setStatus] = useState(false);
  13. return (
  14. <Accordion onChange={() => setStatus(!status)}>
  15. <AccordionSummary
  16. expandIcon={<ExpandMoreIcon />}
  17. >
  18. <Divider
  19. orientation="vertical"
  20. flexItem
  21. sx={{
  22. backgroundColor: data['total'] ? '#7cd545': '#ad2222',
  23. width:'5px',
  24. borderRadius: '3px',
  25. boxShadow: 'none'
  26. }}
  27. />
  28. <Box
  29. sx={{
  30. display: 'flex',
  31. justifyContent: 'space-between',
  32. alignItems: 'center',
  33. width: '100%',
  34. padding: '10px 20px'
  35. }}
  36. >
  37. <AccordionHeaderText
  38. columnText={`№ ${data['_id']} from ${time}`}
  39. content={data['total'] ? 'Completed' : 'Canceled'}
  40. />
  41. {!status &&
  42. <AccordionHeaderText
  43. columnText={'Order price'}
  44. content={data['total'] ? `$${data['total']}` : 'null'}
  45. />
  46. }
  47. {!status &&
  48. <Box
  49. sx={{
  50. display: 'flex',
  51. justifyContent: 'space-between',
  52. alignItems: 'center',
  53. width: '200px'
  54. }}
  55. >
  56. {data['orderGoods'] && data['orderGoods'].map((item, index, array) => {
  57. if (index < 2) {
  58. return (
  59. <Box
  60. key={index}
  61. maxWidth='60px'
  62. height='60px'
  63. borderRadius='10px'
  64. overflow='hidden'
  65. marginRight='20px'
  66. >
  67. <img style={{width: '100%', height: '100%', objectFit: 'cover'}}
  68. src={item?.good?.images && item.good.images[0].url ?
  69. backURL + '/' + item.good.images[0].url : imgNotFound}
  70. alt={'image'}/>
  71. </Box>
  72. )
  73. }
  74. else if (index === 2) {
  75. return (
  76. <Box
  77. key={index}
  78. sx={{
  79. width:'60px',
  80. height:'60px',
  81. border:'1px solid #616161',
  82. display: 'flex',
  83. justifyContent: 'center',
  84. alignItems: 'center',
  85. color: '#616161',
  86. borderRadius: '10px'}}
  87. >
  88. +{array.length - 2}
  89. </Box>
  90. )
  91. }})
  92. }
  93. </Box>}
  94. </Box>
  95. </AccordionSummary>
  96. <AccordionDetails sx={{padding: '20px'}}>
  97. {data['orderGoods'] && data['orderGoods'].length > 0 ?
  98. <>
  99. <Grid container>
  100. <Grid item md={7}>
  101. <Typography
  102. color='#616161'
  103. variant='body1'
  104. letterSpacing='1px'
  105. textAlign='left'
  106. >
  107. Product
  108. </Typography>
  109. </Grid>
  110. <Grid item md={2}>
  111. <Typography
  112. color='#616161'
  113. variant='body1'
  114. letterSpacing='1px'
  115. textAlign='center'
  116. >
  117. Price
  118. </Typography>
  119. </Grid>
  120. <Grid item md={1}>
  121. <Typography
  122. color='#616161'
  123. variant='body1'
  124. letterSpacing='1px'
  125. textAlign='center'
  126. >
  127. Count
  128. </Typography>
  129. </Grid>
  130. <Grid item md={2}>
  131. <Typography
  132. color='#616161'
  133. variant='body1'
  134. letterSpacing='1px'
  135. textAlign='right'
  136. >
  137. Sum
  138. </Typography>
  139. </Grid>
  140. </Grid>
  141. <Divider sx={{margin: '10px 0'}}/>
  142. {data['orderGoods'].map((item, index) => {
  143. return (
  144. <Grid
  145. key={index}
  146. container
  147. alignItems='center'
  148. marginBottom='20px'
  149. >
  150. <Grid item md={7}>
  151. <Link
  152. style={{
  153. textDecoration: 'none',
  154. display: 'flex',
  155. alignItems: 'center',
  156. color: '#616161'
  157. }}
  158. to={`/good/${item?.good?._id}`}
  159. >
  160. <Box
  161. minWidth='60px'
  162. maxWidth='60px'
  163. height='60px'
  164. borderRadius='10px'
  165. overflow='hidden'
  166. marginRight='20px'
  167. >
  168. <img style={{width: '100%', height: '100%', objectFit: 'cover'}}
  169. src={item?.good?.images && item.good.images[0].url ?
  170. backURL + '/' + item.good.images[0].url : imgNotFound}
  171. alt={'image'}/>
  172. </Box>
  173. <Typography
  174. variant='body1'
  175. >
  176. {item.good?.name || 'product name'}
  177. </Typography>
  178. </Link>
  179. </Grid>
  180. <Grid item md={2}>
  181. <Typography
  182. color='#616161'
  183. variant='body1'
  184. letterSpacing='1px'
  185. textAlign='center'
  186. >
  187. {item?.price ? '$' + parseFloat(item.price).toFixed(2) : 'NaN'}
  188. </Typography>
  189. </Grid>
  190. <Grid item md={1}>
  191. <Typography
  192. color='#616161'
  193. variant='body1'
  194. letterSpacing='1px'
  195. textAlign='center'
  196. >
  197. {item?.count || '1'}
  198. </Typography>
  199. </Grid>
  200. <Grid item md={2}>
  201. <Typography
  202. color='#616161'
  203. variant='body1'
  204. letterSpacing='1px'
  205. textAlign='right'
  206. >
  207. {item?.price && item?.count ? '$'+parseFloat(item.price * item.count)
  208. .toFixed(2) : 'NaN'
  209. }
  210. </Typography>
  211. </Grid>
  212. </Grid>
  213. )
  214. })}
  215. <Divider sx={{margin: '-10px 0 10px 0'}}/>
  216. <Box
  217. display='flex'
  218. justifyContent='space-between'
  219. >
  220. <Typography
  221. variant='body1'
  222. color='#616161'
  223. >
  224. Total
  225. </Typography>
  226. <Typography
  227. variant='body1'
  228. color='#616161'
  229. >
  230. {data?.total ? '$'+parseFloat(data.total).toFixed(2) : 'NaN'}
  231. </Typography>
  232. </Box>
  233. </> :
  234. <Typography>Error</Typography>
  235. }
  236. </AccordionDetails>
  237. </Accordion>
  238. )
  239. }