import * as React from 'react';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TablePagination from '@mui/material/TablePagination';
import TableRow from '@mui/material/TableRow';
import { Box, Collapse, IconButton, Typography } from '@mui/material';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
const columns = [
{id: '_', label: '',},
{ id: '_id', label: 'Номер заказа', minWidth: 170 },
{
id: 'createdAt',
label: 'Дата',
minWidth: 100,
format: (value) => {
const createdAtFormat = new Date(+value)
const year = createdAtFormat.getFullYear()
const month = createdAtFormat.getMonth() < 9 ? "0" + (createdAtFormat.getMonth() + 1) : createdAtFormat.getMonth() + 1
const day = createdAtFormat.getDate() < 10 ? "0" + (createdAtFormat.getDate()) : createdAtFormat.getDate()
const hours = createdAtFormat.getHours() < 10 ? "0" + (createdAtFormat.getHours()) : createdAtFormat.getHours()
const minutes = createdAtFormat.getMinutes() < 10 ? "0" + (createdAtFormat.getMinutes()) : createdAtFormat.getMinutes()
const createdAtForTable = `${year}.${month}.${day} ${hours}:${minutes} `
return createdAtForTable
}
},
{
id: 'total',
label: 'Сумма',
minWidth: 170,
align: 'right',
format: (value) => value.toLocaleString('en-US'),
},
{
id: 'orderGoods',
label: 'Количество товаров',
minWidth: 170,
align: 'right',
format: (value) => {
return Array.isArray(value) ? value?.length : value
// на момент написания на сайте были битые заказы с orderGoods: null
},
},
];
export default function StickyHeadTable({rows = []}) {
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(10);
const handleChangePage = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = (event) => {
setRowsPerPage(+event.target.value);
setPage(0);
};
return (
{columns.map((column) => (
{column.label}
))}
{rows
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row) => {
return (
);
})}
);
}
// єто біло в табе боди стр 83
//
// {columns.map((column) => {
// const value = row[column.id]
// {/* console.log('value', value) */}
// return (
//
// {column.format ? column.format(value) : value}
//
// );
// })}
//
function Row(props) {
const { row } = props;
const [open, setOpen] = React.useState(false);
return (
*': { borderBottom: 'unset' } }}>
setOpen(!open)}
>
{open ? : }
{row._id}
{row. createdAt}
{row.total}
Подробности заказа
ID товара
Название
Количество (шт)
Цена (грн.)
Сумма (грн.)
{row.orderGoods ?
row.orderGoods.map((orderGood) => {
console.log('orderGood true', orderGood)
if(orderGood){
return (
{orderGood?._id}
{orderGood?.goodName || ''}
{orderGood?.count}
{orderGood?.price}
{orderGood?.total}
)
}
} )
:
null
}
);
}