вывод скидок в ДГ
This commit is contained in:
parent
a815229da0
commit
0572d31178
@ -12,12 +12,12 @@ const BoxButton = styled("div")(({ theme }) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const columns: GridColDef[] = [
|
const columns: GridColDef[] = [
|
||||||
{
|
// {
|
||||||
field: "id",
|
// field: "id",
|
||||||
headerName: "ID",
|
// headerName: "ID",
|
||||||
width: 70,
|
// width: 70,
|
||||||
sortable: false,
|
// sortable: false,
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
field: "name",
|
field: "name",
|
||||||
headerName: "Название скидки",
|
headerName: "Название скидки",
|
||||||
@ -56,6 +56,21 @@ const columns: GridColDef[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const layerTranslate = [
|
||||||
|
"",
|
||||||
|
"Товар",
|
||||||
|
"Сервис",
|
||||||
|
"корзина",
|
||||||
|
"лояльность",
|
||||||
|
]
|
||||||
|
const layerValue = [
|
||||||
|
"",
|
||||||
|
"Term",
|
||||||
|
"PriceFrom",
|
||||||
|
"CartPurchasesAmount",
|
||||||
|
"PurchasesAmount",
|
||||||
|
]
|
||||||
|
|
||||||
export default function DiscountDataGrid() {
|
export default function DiscountDataGrid() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const exampleDiscounts = useMockDiscountStore((state) => state.discounts);
|
const exampleDiscounts = useMockDiscountStore((state) => state.discounts);
|
||||||
@ -63,8 +78,23 @@ export default function DiscountDataGrid() {
|
|||||||
const realDiscounts = useDiscountStore(state => state.discounts);
|
const realDiscounts = useDiscountStore(state => state.discounts);
|
||||||
|
|
||||||
useDiscounts({ onNewDiscounts: addDiscounts });
|
useDiscounts({ onNewDiscounts: addDiscounts });
|
||||||
|
console.log(realDiscounts)
|
||||||
|
|
||||||
const discountsGridData: GridRowsProp = exampleDiscounts.map((discount) => {
|
const rowBackDicounts: any = realDiscounts.filter(e => e.Layer > 0).map((discount:any) => {
|
||||||
|
return {
|
||||||
|
id: discount.ID,
|
||||||
|
name: discount.Name,
|
||||||
|
description: discount.Description,
|
||||||
|
conditionType: layerTranslate[discount.Layer],
|
||||||
|
factor: Math.floor(Number((1-discount.Target.Factor)*100)),
|
||||||
|
value: layerValue[discount.Layer],
|
||||||
|
active: discount.Deprecated ? "🚫" : "✅"
|
||||||
|
};
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const discountsGridData: any = exampleDiscounts.map((discount) => {
|
||||||
const value =
|
const value =
|
||||||
(discount.condition as any).purchasesAmount ??
|
(discount.condition as any).purchasesAmount ??
|
||||||
(discount.condition as any).cartPurchasesAmount ??
|
(discount.condition as any).cartPurchasesAmount ??
|
||||||
@ -82,13 +112,14 @@ export default function DiscountDataGrid() {
|
|||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const mix = [...rowBackDicounts, ...discountsGridData]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: "100%", marginTop: "55px", p: "16px", maxWidth: "1000px" }}>
|
<Box sx={{ width: "100%", marginTop: "55px", p: "16px", maxWidth: "1000px" }}>
|
||||||
<Box sx={{ height: 600 }}>
|
<Box sx={{ height: 600 }}>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
checkboxSelection={true}
|
checkboxSelection={true}
|
||||||
rows={discountsGridData}
|
rows={mix}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectionModel={selectedDiscountIds}
|
selectionModel={selectedDiscountIds}
|
||||||
onSelectionModelChange={setMockSelectedDiscountIds}
|
onSelectionModelChange={setMockSelectedDiscountIds}
|
||||||
|
@ -24,7 +24,12 @@ export const useDiscountStore = create<DiscountStore>()(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
export const addDiscounts = (newDiscounts: DiscountStore["discounts"]) => useDiscountStore.setState(state => ({ discounts: [...state.discounts, ...newDiscounts] }));
|
export const addDiscounts = (newDiscounts: DiscountStore["discounts"]) => {
|
||||||
|
console.log(useDiscountStore.getState())
|
||||||
|
console.log(newDiscounts)
|
||||||
|
useDiscountStore.setState(state => ({ discounts: [...state.discounts, ...newDiscounts] }));
|
||||||
|
console.log(useDiscountStore.getState())
|
||||||
|
}
|
||||||
|
|
||||||
export const setSelectedDiscountIds = (selectedDiscountIds: DiscountStore["selectedDiscountIds"]) => useDiscountStore.setState({ selectedDiscountIds });
|
export const setSelectedDiscountIds = (selectedDiscountIds: DiscountStore["selectedDiscountIds"]) => useDiscountStore.setState({ selectedDiscountIds });
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user