AccordionItem.jsx 12 KB

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