Created
November 4, 2022 13:44
-
-
Save otaciobarbosa/7fd75f7901abf6090d9d8153b0092fee to your computer and use it in GitHub Desktop.
promocaoComponent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState, useEffect } from "react"; | |
| import api from "../services/api"; | |
| import MUIDataTable from "mui-datatables"; | |
| import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles'; | |
| import CircularProgress from '@mui/material/CircularProgress'; | |
| import load from "../../src/assets/img/load.gif"; | |
| const fetch = require('node-fetch'); | |
| export default function Promocao() { | |
| const [loading, setLoading] = useState(""); | |
| const [panel, setPanel] = useState([]); | |
| const [preco, setPreco] = useState([]); | |
| async function getPanel() { | |
| setLoading(true); | |
| const panel = await api.get(`/promocao/promocao`); | |
| if (panel.data.codigo == 1) { | |
| setPanel(panel.data.result); | |
| setLoading(false); | |
| } else { | |
| setPanel([]); | |
| setLoading(false); | |
| } | |
| } | |
| useEffect(() => { | |
| getPanel(); | |
| }, []); | |
| const theme = createMuiTheme({ | |
| overrides: { | |
| MuiTableCell: { | |
| root: { | |
| paddingTop: '0px !important', | |
| paddingBottom: '5px !important', | |
| paddingRight: '5px !important', | |
| fontSize: '12px !important', | |
| border: '1px #ccc solid' | |
| }, | |
| head: { | |
| paddingTop: '0px !important', | |
| paddingBottom: '5px !important', | |
| paddingRight: '5px !important', | |
| backgroundColor: '#ccc !important', | |
| border: '1px #eee solid' | |
| }, | |
| }, | |
| }, | |
| }); | |
| const columns = [ | |
| { | |
| name: "FAROL", | |
| label: "FAROL", | |
| }, { | |
| name: "NROEMPRESA", | |
| label: "FILIAL", | |
| }, { | |
| name: "COMPRADOR", | |
| label: "GLP", | |
| }, { | |
| name: "SEQPRODUTO", | |
| label: "PRODUTO", | |
| }, { | |
| name: "DESCRICAO", | |
| label: "DESCRICAO" | |
| }, { | |
| name: "DATAVALIDADE", | |
| label: "VALIDADE", | |
| }, { | |
| name: "DATACOLETA", | |
| label: "COLETA", | |
| }, { | |
| name: "QUANTIDADE", | |
| label: "QUANT", | |
| }, { | |
| name: "DIAS", | |
| label: "DIAS", | |
| }, { | |
| name: "PRECOPROMOCIONAL", | |
| label: "PRECO", | |
| options: { | |
| filter: true, | |
| sort: true, | |
| customBodyRender: (value) => { | |
| let str = value.split("-") | |
| let loja = str[0]; | |
| let produto = str[1]; | |
| let url = `${api}/promocao/promodados/preco/produto/${produto}/nroempresa/${loja}`; | |
| let options = { method: 'GET' }; | |
| fetch(url, options) | |
| .then(res => res.json()) | |
| .then(json => { | |
| console.log("Preço: " + json.result[0].PRECO) | |
| return(json.result[0].PRECO) | |
| }) | |
| .catch(err => console.error('error:' + err)); | |
| } | |
| } | |
| }, { | |
| name: "PRECOPROMOCIONAL", | |
| label: "MARGEM", | |
| }, { | |
| name: "SUFICIENCIA", | |
| label: "SUFICIENCIA", | |
| }, { | |
| name: "MEDIA", | |
| label: "MEDIA", | |
| } | |
| ]; | |
| const options = { | |
| filter: true, | |
| filterType: 'multiselect', | |
| tableBodyHeight: '450px', | |
| responsive: "stacked", | |
| selectableRows: false, | |
| pagination: true, | |
| viewColumns: false, | |
| textLabels: { | |
| filter: { | |
| all: "TODOS", | |
| title: "FILTROS", | |
| reset: "LIMPAR", | |
| }, | |
| body: { | |
| noMatch: | |
| "Desculpe, nenhuma informação encontrada, por favor tente executar uma nova consulta.", | |
| toolTip: "Sort", | |
| columnHeaderTooltip: (column) => `Sort for ${column.label}`, | |
| }, | |
| pagination: { | |
| next: "Próxima página", | |
| previous: "Página anterior", | |
| rowsPerPage: "Linhas por página:", | |
| displayRows: "de", | |
| }, | |
| }, | |
| }; | |
| return ( | |
| <div> | |
| {loading ? ( | |
| <div style={{ textAlign: 'center', paddingTop: '20%' }}><CircularProgress /></div> | |
| ) : ( | |
| <MuiThemeProvider theme={theme}> | |
| <MUIDataTable | |
| title={"Promoções Ativas"} | |
| data={panel} | |
| columns={columns} | |
| options={options} | |
| /> | |
| </MuiThemeProvider> | |
| )} | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment