Commit 5acc8772 by tdgiang

update code

parent e108ebbb
......@@ -60,3 +60,13 @@ export const changeStatusGasStation = async (body) =>
PostData(url.changeStatusGasStation, body)
.then((res) => res)
.catch((err) => null)
export const deleteGasOnline = async (body) =>
PostData(url.deleteGasOnline, body)
.then((res) => res)
.catch((err) => null)
export const deleteGasField = async (body) =>
PostData(url.deleteGasField, body)
.then((res) => res)
.catch((err) => null)
......@@ -80,6 +80,9 @@ export default {
urlDetailGasStation: `${root}/merchantstore`,
changeStatusGasStation: `${root}/merchantstore/changeStatus`,
deleteGasOnline: `${root}/gasoline/delete`,
deleteGasField: `${root}/gasfield/delete`,
//Log
logAuth: `${root}/logging/listLogin`,
logApi: `${root}/logging/listCallApi`,
......
......@@ -99,10 +99,21 @@ export default function FormDialog({ onCreate }) {
}
const handleSubmit = async (value) => {
console.log('state', state)
let index=listProduct.findIndex(e=>e.id==state.product_id)
if(index!=-1){
console.log(listProduct[index])
console.log("listProduct",listProduct)
console.log('state', state)
onCreate({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name})
setOpen(false)
setState({})
setType()
}
onCreate({...state,type})
}
const handleChange = (event) => {
......@@ -134,15 +145,15 @@ export default function FormDialog({ onCreate }) {
<DialogContent>
<Grid container spacing={2}>
<Grid item lg={12} md={12} sm={12} xs={12}>
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Tên vòi xăng *"
label=" vòi xăng *"
onChange={handleChange}
variant="outlined"
type="text"
name="name"
value={name || ''}
name="code"
value={code || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
......@@ -152,18 +163,19 @@ export default function FormDialog({ onCreate }) {
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label=" vòi xăng *"
label="Tên vòi xăng *"
onChange={handleChange}
variant="outlined"
type="text"
name="code"
value={code || ''}
name="name"
value={name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={12} md={12} sm={12} xs={12}>
<SelectValidator
......
import React, { useState, useEffect } from 'react'
import {
Button,
FormControl,
Grid,
InputLabel,
Select,
TextField,
Typography,
Radio,
FormControlLabel,
DialogActions,
Dialog,
DialogContent,
DialogContentText,
DialogTitle,
IconButton,
Icon,
Tooltip,
RadioGroup,
MenuItem,
} from '@material-ui/core'
import { toast } from 'react-toastify'
import { useTranslation } from 'react-i18next'
import { KeyboardDatePicker } from '@material-ui/pickers'
import {
convertDate,
toPriceVndInput,
convertViToEn,
} from 'app/config/Function'
import {
TextValidator,
ValidatorForm,
SelectValidator,
} from 'react-material-ui-form-validator'
import {dropdownProductType,dropdownProcutByType} from 'app/apis/Functions/dropdown'
export default function FormDialog( props) {
const { t } = useTranslation()
const { open, handleClose, data, onAgree } = props
const [state, setState] = useState({})
const [listType, setListType] = useState([])
const [listProduct, setListProduct] = useState([])
const [product,setProduct]=useState()
const [type, setType] = useState()
useEffect(()=>{
if(data){
setState({...data})
setType(data.type)
setProduct(data.product_id)
}
},[data])
useEffect(()=>{
setState({...state})
if(type){
getDropdownProduct(type)
}
},[type])
useEffect(() => {
getData()
}, [])
const getData = async () => {
const res = await dropdownProductType({})
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.map((e) => {
return { ...e,name: e.type_name, value: e.id}
})
setListType(newList)
}
else {
toast.error('Lấy giữ liệu thất bại !', {
theme: 'colored',
})
}
}
const getDropdownProduct= async (type) => {
const res = await dropdownProcutByType(type)
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.map((e) => {
return { ...e,name: e.product_name, value: e.id}
})
setListProduct(newList)
}
else {
toast.error('Lấy giữ liệu thất bại !', {
theme: 'colored',
})
}
}
const handleSubmit = async (value) => {
let index=listProduct.findIndex(e=>e.id==state.product_id)
if(index!=-1){
console.log(listProduct[index])
console.log("listProduct",listProduct)
console.log('state', state)
onAgree({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name})}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const { product_id, name, code } = state
console.log("product_id",product_id)
return (
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">
Thêm vòi xăng
</DialogTitle>
<DialogContent>
<Grid container spacing={2}>
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
defaultValue={true}
label="Mã vòi xăng *"
onChange={handleChange}
variant="outlined"
disabled={true}
type="text"
name="code"
value={code || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Tên vòi xăng *"
onChange={handleChange}
variant="outlined"
type="text"
name="name"
value={name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
{type && <Grid item lg={12} md={12} sm={12} xs={12}>
<SelectValidator
variant={'outlined'}
label={'Loại nguyên liệu *'}
className="mb-4 w-full"
value={type || ''}
displayEmpty
name="merchan_id"
onChange={(event) => {
setType(event.target.value)
}}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
>
{listType.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid>}
{product_id && <Grid item lg={12} md={12} sm={12} xs={12}>
<SelectValidator
variant={'outlined'}
label={'Loại xăng *'}
className="mb-4 w-full"
value={product_id || ''}
displayEmpty
name="product_id"
onChange={handleChange}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
>
{listProduct.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid>}
</Grid>
</DialogContent>
<DialogActions>
<Button color="secondary" onClick={handleClose}>
Thoát
</Button>
<Button onClick={handleSubmit} color="primary">
Đồng ý
</Button>
</DialogActions>
</Dialog>
)
}
......@@ -92,7 +92,7 @@ const ToolNotificate = (props) => {
const removeItem = async (id) => {
props.showLoading()
const res = await deleteGasStation({ id })
const res = await deleteGasStation({ idGuid: id })
props.hideLoading()
if (res.data.code == 200) {
getData()
......
......@@ -211,7 +211,7 @@ function TableList(props) {
setSelected({
...row,
title: 'Xóa cây xăng',
content: `Bạn có muốn xóa cây xăng ${row.name} hay không?`,
content: `Bạn có muốn xóa cây xăng ${row.store_name} hay không?`,
})
setOpen(true)
}}
......
......@@ -60,7 +60,6 @@ const SimpleForm = (props) => {
props.showLoading()
const res = await createProduct({
...newValue,
type_id: 2,
})
props.hideLoading()
if (res.data.code == 200) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment