Commit 5acc8772 by tdgiang

update code

parent e108ebbb
...@@ -60,3 +60,13 @@ export const changeStatusGasStation = async (body) => ...@@ -60,3 +60,13 @@ export const changeStatusGasStation = async (body) =>
PostData(url.changeStatusGasStation, body) PostData(url.changeStatusGasStation, body)
.then((res) => res) .then((res) => res)
.catch((err) => null) .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 { ...@@ -80,6 +80,9 @@ export default {
urlDetailGasStation: `${root}/merchantstore`, urlDetailGasStation: `${root}/merchantstore`,
changeStatusGasStation: `${root}/merchantstore/changeStatus`, changeStatusGasStation: `${root}/merchantstore/changeStatus`,
deleteGasOnline: `${root}/gasoline/delete`,
deleteGasField: `${root}/gasfield/delete`,
//Log //Log
logAuth: `${root}/logging/listLogin`, logAuth: `${root}/logging/listLogin`,
logApi: `${root}/logging/listCallApi`, logApi: `${root}/logging/listCallApi`,
......
...@@ -99,10 +99,21 @@ export default function FormDialog({ onCreate }) { ...@@ -99,10 +99,21 @@ export default function FormDialog({ onCreate }) {
} }
const handleSubmit = async (value) => { 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) 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) => { const handleChange = (event) => {
...@@ -137,12 +148,12 @@ export default function FormDialog({ onCreate }) { ...@@ -137,12 +148,12 @@ export default function FormDialog({ onCreate }) {
<Grid item lg={12} md={12} sm={12} xs={12}> <Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator <TextValidator
className="mb-4 w-full" className="mb-4 w-full"
label="Tên vòi xăng *" label=" vòi xăng *"
onChange={handleChange} onChange={handleChange}
variant="outlined" variant="outlined"
type="text" type="text"
name="name" name="code"
value={name || ''} value={code || ''}
validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
...@@ -152,12 +163,12 @@ export default function FormDialog({ onCreate }) { ...@@ -152,12 +163,12 @@ export default function FormDialog({ onCreate }) {
<Grid item lg={12} md={12} sm={12} xs={12}> <Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator <TextValidator
className="mb-4 w-full" className="mb-4 w-full"
label=" vòi xăng *" label="Tên vòi xăng *"
onChange={handleChange} onChange={handleChange}
variant="outlined" variant="outlined"
type="text" type="text"
name="code" name="name"
value={code || ''} value={name || ''}
validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
...@@ -165,6 +176,7 @@ export default function FormDialog({ onCreate }) { ...@@ -165,6 +176,7 @@ export default function FormDialog({ onCreate }) {
/> />
</Grid> </Grid>
<Grid item lg={12} md={12} sm={12} xs={12}> <Grid item lg={12} md={12} sm={12} xs={12}>
<SelectValidator <SelectValidator
variant={'outlined'} variant={'outlined'}
......
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>
)
}
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
Tooltip, Tooltip,
} from '@material-ui/core' } from '@material-ui/core'
import _ from 'lodash' import _ from 'lodash'
import { createFunction } from 'app/apis/Functions/function' import { createGasStation } from 'app/apis/Functions/merchant'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction' import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components' import { Breadcrumb, SimpleCard } from 'app/components'
...@@ -31,6 +31,7 @@ import TableRow from '@material-ui/core/TableRow' ...@@ -31,6 +31,7 @@ import TableRow from '@material-ui/core/TableRow'
import Paper from '@material-ui/core/Paper' import Paper from '@material-ui/core/Paper'
import CreateField from 'app/components/dialog/CreateField' import CreateField from 'app/components/dialog/CreateField'
import CreateFountain from 'app/components/dialog/CreateFountain' import CreateFountain from 'app/components/dialog/CreateFountain'
import UpdateFountain from 'app/components/dialog/UpdateFountain'
const SimpleForm = (props) => { const SimpleForm = (props) => {
const [state, setState] = useState({}) const [state, setState] = useState({})
...@@ -38,6 +39,8 @@ const SimpleForm = (props) => { ...@@ -38,6 +39,8 @@ const SimpleForm = (props) => {
const [listDrop, setListDrop] = useState([]) const [listDrop, setListDrop] = useState([])
const [openCreate, setOpenCreate] = useState(false) const [openCreate, setOpenCreate] = useState(false)
const [listField, setListField] = useState([]) const [listField, setListField] = useState([])
const [fountainSelected, setFountainSelected] = useState()
const [openUpdate, setOpenUpdate] = useState()
useEffect(() => { useEffect(() => {
getData() getData()
...@@ -65,22 +68,25 @@ const SimpleForm = (props) => { ...@@ -65,22 +68,25 @@ const SimpleForm = (props) => {
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
const newValue = trimObject(state) const newValue = trimObject(state)
console.log('newValue', newValue)
console.log('listField', listField)
props.showLoading() props.showLoading()
const res = await createFunction({ const res = await createGasStation({
...newValue, ...newValue,
status: 1, gas_fields: listField,
is_default: true,
}) })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { if (res.data.code == 200) {
history.push('/gas-station') history.push('/gas-station')
if (res.data.code == 200) { if (res.data.code == 200) {
toast.success('Tạo hành động thành công!', { toast.success('Tạo cây xăng thành công!', {
theme: 'colored', theme: 'colored',
}) })
} }
} else { } else {
toast.error('Tạo hành động thất bại!', { toast.error('Tạo cây xăng thất bại!', {
theme: 'colored', theme: 'colored',
}) })
} }
...@@ -140,6 +146,13 @@ const SimpleForm = (props) => { ...@@ -140,6 +146,13 @@ const SimpleForm = (props) => {
let newList = arr.map((e, i) => { let newList = arr.map((e, i) => {
if (i == index) { if (i == index) {
if (e.gas_olines) { if (e.gas_olines) {
console.log('data', data)
console.log('e.gas_olines', e.gas_olines)
if (
e.gas_olines.findIndex((e) => e.name == data.name) ==
-1 &&
e.gas_olines.findIndex((e) => e.code == data.code) == -1
) {
return { return {
...e, ...e,
gas_olines: [ gas_olines: [
...@@ -149,6 +162,15 @@ const SimpleForm = (props) => { ...@@ -149,6 +162,15 @@ const SimpleForm = (props) => {
].concat(e.gas_olines), ].concat(e.gas_olines),
} }
} else { } else {
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
return {
...e,
gas_olines: e.gas_olines,
}
}
} else {
return { return {
...e, ...e,
gas_olines: [ gas_olines: [
...@@ -164,14 +186,85 @@ const SimpleForm = (props) => { ...@@ -164,14 +186,85 @@ const SimpleForm = (props) => {
console.log('newList', newList) console.log('newList', newList)
setListField(newList) setListField(newList)
} }
const deleteFountain = (item, index) => {
console.log('item', item)
let arr = [...listField]
console.log('index', index)
let newList = arr.map((e, i) => {
if (item?.field_name == e?.field_name) {
let temp = [...e?.gas_olines]
console.log('temp', temp)
console.log('index', index)
temp.splice(index, 1)
console.log('temp', temp)
return {
...e,
gas_olines: temp,
}
} else return { ...e }
})
console.log('newList', newList)
setListField(newList)
toast.success('Xoá vòi thành công!', {
theme: 'colored',
})
}
const handleCloseCreate = () => { const handleCloseCreate = () => {
setOpenCreate(false) setOpenCreate(false)
} }
const { store_name, address, merchan_id } = state const handleCloseUpdate = () => {
setOpenUpdate(false)
}
const onUpdateField = (data) => {
console.log('hehe', data)
console.log('fountainSelected', fountainSelected)
let arr = [...listField]
console.log('listField', listField) let newList = arr.map((e, i) => {
if (i == fountainSelected.index) {
console.log('data', data)
console.log('e.gas_olines', e.gas_olines)
if (e.gas_olines.findIndex((e) => e.code == data.code) != -1) {
const temp = e.gas_olines.map((item) => {
if (item.code == data.code) return { ...data }
return { ...item }
})
return {
...e,
gas_olines: temp,
}
} else {
return {
...e,
gas_olines: e.gas_olines,
}
}
} else return { ...e }
})
setListField(newList)
setOpenUpdate(false)
}
const countFountain = () => {
let temp = 0
listField.map((e) => {
if (e.gas_olines) {
temp += e.gas_olines.length
}
})
return temp
}
const { store_name, address, merchan_id } = state
return ( return (
<div className="m-sm-30"> <div className="m-sm-30">
...@@ -294,7 +387,7 @@ const SimpleForm = (props) => { ...@@ -294,7 +387,7 @@ const SimpleForm = (props) => {
{listField.length} {listField.length}
</Typography> </Typography>
<Typography variant="subtitle1"> <Typography variant="subtitle1">
S lượng tr:3 S lượng tr: {countFountain()}
</Typography> </Typography>
</div> </div>
<Button <Button
...@@ -503,9 +596,24 @@ const SimpleForm = (props) => { ...@@ -503,9 +596,24 @@ const SimpleForm = (props) => {
</TableCell> */} </TableCell> */}
<TableCell> <TableCell>
<Tooltip title="Xoá"> <Tooltip title="Cập nhật">
<IconButton <IconButton
onClick={() => {}} onClick={() => {
setOpenUpdate(
true
)
setFountainSelected(
{
...row,
index,
}
)
console.log(
'heelo',
index
)
}}
//className={classes.button} //className={classes.button}
aria-label="Delete" aria-label="Delete"
> >
...@@ -516,7 +624,16 @@ const SimpleForm = (props) => { ...@@ -516,7 +624,16 @@ const SimpleForm = (props) => {
</Tooltip> </Tooltip>
<Tooltip title="Xoá"> <Tooltip title="Xoá">
<IconButton <IconButton
onClick={() => {}} onClick={() => {
deleteFountain(
item,
index
)
console.log(
'heelo',
index
)
}}
//className={classes.button} //className={classes.button}
aria-label="Delete" aria-label="Delete"
> >
...@@ -574,6 +691,12 @@ const SimpleForm = (props) => { ...@@ -574,6 +691,12 @@ const SimpleForm = (props) => {
handleClose={handleCloseCreate} handleClose={handleCloseCreate}
onAgree={onCreateField} onAgree={onCreateField}
/> />
<UpdateFountain
open={openUpdate}
handleClose={handleCloseUpdate}
onAgree={onUpdateField}
data={fountainSelected}
/>
</ValidatorForm> </ValidatorForm>
</SimpleCard> </SimpleCard>
</div> </div>
......
...@@ -92,7 +92,7 @@ const ToolNotificate = (props) => { ...@@ -92,7 +92,7 @@ const ToolNotificate = (props) => {
const removeItem = async (id) => { const removeItem = async (id) => {
props.showLoading() props.showLoading()
const res = await deleteGasStation({ id }) const res = await deleteGasStation({ idGuid: id })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { if (res.data.code == 200) {
getData() getData()
......
...@@ -211,7 +211,7 @@ function TableList(props) { ...@@ -211,7 +211,7 @@ function TableList(props) {
setSelected({ setSelected({
...row, ...row,
title: 'Xóa cây xăng', 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) setOpen(true)
}} }}
......
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator' import {
import { Button, Grid } from '@material-ui/core' ValidatorForm,
TextValidator,
import { detailFunction, updateFunction } from 'app/apis/Functions/function' SelectValidator,
} from 'react-material-ui-form-validator'
import {
Button,
Grid,
MenuItem,
Typography,
IconButton,
Icon,
Tooltip,
} from '@material-ui/core'
import _ from 'lodash'
import {
createGasStation,
detailGasStation,
deleteGasField,
deleteGasOnline,
} from 'app/apis/Functions/merchant'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction' import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components' import { Breadcrumb, SimpleCard } from 'app/components'
import { Link, useHistory, useLocation } from 'react-router-dom' import { Link, useHistory, useLocation } from 'react-router-dom'
import { trimObject } from 'app/config/Function' import { trimObject } from 'app/config/Function'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import localStorageService from 'app/services/localStorageService' import { dropdownMerchant } from 'app/apis/Functions/dropdown'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableContainer from '@material-ui/core/TableContainer'
import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow'
import Paper from '@material-ui/core/Paper'
import CreateField from 'app/components/dialog/CreateField'
import CreateFountain from 'app/components/dialog/CreateFountain'
import UpdateFountain from 'app/components/dialog/UpdateFountain'
import { useTranslation } from 'react-i18next'
const SimpleForm = (props) => { const SimpleForm = (props) => {
const [state, setState] = useState({}) const [state, setState] = useState({})
const history = useHistory() const history = useHistory()
const [listDrop, setListDrop] = useState([])
const [openCreate, setOpenCreate] = useState(false)
const [listField, setListField] = useState([])
const [fountainSelected, setFountainSelected] = useState()
const [openUpdate, setOpenUpdate] = useState()
const location = useLocation() const location = useLocation()
const { t } = useTranslation()
useEffect(() => { useEffect(() => {
getDateDetail()
getData() getData()
}, []) }, [])
const getData = async () => { const getDateDetail = async () => {
props.showLoading() props.showLoading()
const res = await detailFunction(location.state, {}) const res = await detailGasStation(location.state, {})
props.hideLoading() props.hideLoading()
if (res.data.code == 200 && res.data.data) { if (res.data.code == 200 && res.data.data) {
console.log(res.data.data.gas_fields)
if (res.data.data.gas_fields) {
setListField(res.data.data?.gas_fields)
}
setState(res.data.data) setState(res.data.data)
} else if (res.data.code == 401) { } else if (res.data.code == 401) {
localStorageService.removeToken()
setTimeout(() => { setTimeout(() => {
history.push('/') history.push('/')
}, 100) }, 100)
...@@ -37,24 +76,51 @@ const SimpleForm = (props) => { ...@@ -37,24 +76,51 @@ const SimpleForm = (props) => {
} }
} }
const getData = async () => {
props.showLoading()
const res = await dropdownMerchant({})
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.map((e) => {
return { ...e, name: e.merchant_name }
})
setListDrop(newList)
} else if (res.data.code == 401) {
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error('Lấy giữ liệu thất bại !', {
theme: 'colored',
})
}
}
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
const newValue = trimObject(state) const newValue = trimObject(state)
console.log('newValue', newValue)
console.log('listField', listField)
props.showLoading() props.showLoading()
const res = await updateFunction({ const res = await createGasStation({
...newValue, id: newValue?.id,
status: 1, merchant_id: newValue?.merchant_id,
is_default: true, store_name: newValue?.store_name,
address: newValue?.address,
gas_fields: listField,
}) })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { if (res.data.code == 200) {
history.push('/gas-station') history.push('/gas-station')
if (res.data.code == 200) { if (res.data.code == 200) {
toast.success('Cập nhật hành động thành công!', { toast.success('Cập nhật cây xăng thành công!', {
theme: 'colored', theme: 'colored',
}) })
} }
} else { } else {
toast.error('Cập nhật hành động thất bại!', { toast.error('Cập nhật cây xăng thất bại!', {
theme: 'colored', theme: 'colored',
}) })
} }
...@@ -72,7 +138,184 @@ const SimpleForm = (props) => { ...@@ -72,7 +138,184 @@ const SimpleForm = (props) => {
setState({ ...state, date }) setState({ ...state, date })
} }
const { description, name, code, url } = state const onCreateField = (value) => {
if (value) {
console.log('value', value)
if (listField.findIndex((e) => e.field_name == value) == -1) {
setListField(
[
{
field_name: value,
gas_olines: [],
},
].concat(listField)
)
setOpenCreate(false)
toast.success('Thêm trụ thành công!', {
theme: 'colored',
})
} else {
toast.warning('Tên trụ xăng đã tồn tại', {
theme: 'colored',
})
}
} else {
toast.warning('Bạn chưa nhập đầy đủ thông tin', {
theme: 'colored',
})
}
}
const deletePillar = (index) => {
let arr = [...listField]
arr.splice(index, 1)
setListField(arr)
toast.success('Xoá trụ thành công!', {
theme: 'colored',
})
}
const createFountain = (data, index) => {
let arr = [...listField]
let newList = arr.map((e, i) => {
if (i == index) {
if (e.gas_olines) {
console.log('data', data)
console.log('e.gas_olines', e.gas_olines)
if (
e.gas_olines.findIndex((e) => e.name == data.name) ==
-1 &&
e.gas_olines.findIndex((e) => e.code == data.code) == -1
) {
return {
...e,
gas_olines: [
{
...data,
},
].concat(e.gas_olines),
}
} else {
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
return {
...e,
gas_olines: e.gas_olines,
}
}
} else {
return {
...e,
gas_olines: [
{
...data,
},
],
}
}
} else return { ...e }
})
console.log('newList', newList)
setListField(newList)
}
const deleteFountain = (item, index) => {
console.log('item', item)
let arr = [...listField]
console.log('index', index)
let newList = arr.map((e, i) => {
if (item?.field_name == e?.field_name) {
let temp = [...e?.gas_olines]
console.log('temp', temp)
console.log('index', index)
if (temp[index].id) {
callApiDeleteFountain(temp[index].id)
}
temp.splice(index, 1)
console.log('temp', temp)
return {
...e,
gas_olines: temp,
}
} else return { ...e }
})
console.log('newList', newList)
setListField(newList)
toast.success('Xoá vòi thành công!', {
theme: 'colored',
})
}
const handleCloseCreate = () => {
setOpenCreate(false)
}
const handleCloseUpdate = () => {
setOpenUpdate(false)
}
const onUpdateField = (data) => {
console.log('hehe', data)
console.log('fountainSelected', fountainSelected)
let arr = [...listField]
let newList = arr.map((e, i) => {
if (i == fountainSelected.index) {
console.log('data', data)
console.log('e.gas_olines', e.gas_olines)
if (e.gas_olines.findIndex((e) => e.code == data.code) != -1) {
const temp = e.gas_olines.map((item) => {
if (item.code == data.code) return { ...data }
return { ...item }
})
return {
...e,
gas_olines: temp,
}
} else {
return {
...e,
gas_olines: e.gas_olines,
}
}
} else return { ...e }
})
setListField(newList)
setOpenUpdate(false)
}
const countFountain = () => {
let temp = 0
listField.map((e) => {
if (e.gas_olines) {
temp += e.gas_olines.length
}
})
return temp
}
const callApiDeleteFountain = async (id) => {
props.showLoading()
const res = await deleteGasOnline({ idGuid: id })
props.hideLoading()
if (res.data.code == 200) {
return true
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
return false
}
}
const { store_name, address, merchant_id } = state
return ( return (
<div className="m-sm-30"> <div className="m-sm-30">
...@@ -89,71 +332,396 @@ const SimpleForm = (props) => { ...@@ -89,71 +332,396 @@ const SimpleForm = (props) => {
/> />
</div> </div>
<SimpleCard> <SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}> <ValidatorForm
id="form-create"
onSubmit={handleSubmit}
onError={() => null}
>
<Grid container spacing={3}> <Grid container spacing={3}>
<Grid item lg={6} md={6} sm={12} xs={12}> {merchant_id && (
<TextValidator <Grid xs={6} sm={6} item>
variant="outlined" <SelectValidator
variant={'outlined'}
label={'Thuộc pháp nhân *'}
disabled={true}
className="mb-4 w-full" className="mb-4 w-full"
label="Tên cây xăng *" value={merchant_id || ''}
displayEmpty
name="merchant_id"
onChange={handleChange} onChange={handleChange}
type="text"
name="name"
value={name || ''}
validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
]} ]}
/> >
{listDrop.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid> </Grid>
)}
<Grid item lg={6} md={6} sm={12} xs={12}> <Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator <TextValidator
variant="outlined" variant="outlined"
className="mb-4 w-full" className="mb-4 w-full"
label="Mã code *" label="Tên cây xăng *"
onChange={handleChange} onChange={handleChange}
type="text" type="text"
name="code" name="store_name"
value={code || ''} value={store_name || ''}
validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
]} ]}
/> />
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> <Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator <TextValidator
variant="outlined" variant="outlined"
className="mb-4 w-full" className="mb-4 w-full"
label=ường dẫn *" label=ịa chỉ *"
onChange={handleChange} onChange={handleChange}
type="text" type="text"
name="url" name="address"
value={url || ''} value={address || ''}
validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
]} ]}
/> />
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> {/* <Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator <TextValidator
variant="outlined" variant="outlined"
className="mb-4 w-full" className="mb-4 w-full"
label="Mô tả " label="Tên cây xăng *"
onChange={handleChange} onChange={handleChange}
type="text" type="text"
name="description" name="store_name"
value={description || ''} value={store_name || ''}
//validators={['required']} validators={['required']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
]} ]}
/> />
</Grid> */}
<Grid
item
container
lg={12}
md={12}
sm={12}
xs={12}
justify="space-between"
style={{
padding: 10,
borderRadius: 5,
}}
>
<Typography variant="h6">
Thông tin tr xăng
</Typography>
<Grid
item
container
lg={12}
md={12}
sm={12}
xs={12}
justify="space-between"
>
<div>
<Typography variant="subtitle1">
S lượng vòi mi tr:{' '}
{listField.length}
</Typography>
<Typography variant="subtitle1">
S lượng tr: {countFountain()}
</Typography>
</div>
<Button
style={{
width: 140,
}}
onClick={() => {
setOpenCreate(true)
}}
variant="contained"
className={'bg-light-primary'}
>
<span className={'text-primary'}>
Thêm mi tr
</span>
</Button>
</Grid> </Grid>
{listField.map((item, index) => (
<Grid
style={{
border: '1px solid #B9B9B9',
borderRadius: 5,
padding: 10,
marginTop: 20,
}}
lg={12}
md={12}
sm={12}
xs={12}
>
<Grid lg={12} md={12} sm={12} xs={12}>
<div
style={{
alignItems: 'center',
justifyContent:
'space-between',
display: 'flex',
marginBottom: 10,
}}
>
<Typography variant="h6">
{item.field_name}
</Typography>
<Button
onClick={() => {
deletePillar(index)
}}
variant="contained"
style={{
backgroundColor:
'#FC2B05',
color: 'white',
}}
>
<span>Xoá tr</span>
</Button>
</div>
<TableContainer component={Paper}>
<Table aria-label="simple table">
<TableHead>
<TableRow
style={{
backgroundColor:
'#F3F3F3',
}}
>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
width: 100,
}}
align="center"
>
STT
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="center"
>
Mã vòi
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="center"
>
Vòi
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="center"
>
Loi nhiên liu
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="center"
>
Sn phm
</TableCell>
{/* <TableCell align="center">
Trạng thái hoạt
động
</TableCell> */}
<TableCell
style={{
textAlign:
'center',
width: 120,
}}
align="center"
>
Hành động
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{item?.gas_olines.map(
(row, index) => (
<TableRow
key={
row.name
}
>
<TableCell
component="th"
scope="row"
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="center"
>
{index +
1}
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="right"
>
{
row?.code
}
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="right"
>
{
row?.name
}
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="right"
>
{
row?.type_name
}
</TableCell>
<TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="right"
>
{
row?.product_name
}
</TableCell>
{/* <TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
}}
align="right"
>
{
row?.status
}
</TableCell> */}
<TableCell>
<Tooltip title="Cập nhật">
<IconButton
onClick={() => {
setOpenUpdate(
true
)
setFountainSelected(
{
...row,
index,
}
)
console.log(
'heelo',
index
)
}}
//className={classes.button}
aria-label="Delete"
>
<Icon color="primary">
edit
</Icon>
</IconButton>
</Tooltip>
<Tooltip title="Xoá">
<IconButton
onClick={() => {
deleteFountain(
item,
index
)
console.log(
'heelo',
index
)
}}
//className={classes.button}
aria-label="Delete"
>
<Icon color="error">
delete
</Icon>
</IconButton>
</Tooltip>
</TableCell>
</TableRow>
)
)}
</TableBody>
</Table>
</TableContainer>
<CreateFountain
onCreate={(data) => {
createFountain(data, index)
}}
/>
</Grid>
</Grid>
))}
</Grid> </Grid>
<Grid container justify={'flex-end'}> </Grid>
<Grid
style={{
marginTop: 40,
}}
container
justify={'flex-end'}
>
<Link to="gas-station"> <Link to="gas-station">
<Button <Button
style={{ style={{
...@@ -174,6 +742,17 @@ const SimpleForm = (props) => { ...@@ -174,6 +742,17 @@ const SimpleForm = (props) => {
<span className="capitalize">Cp nht</span> <span className="capitalize">Cp nht</span>
</Button> </Button>
</Grid> </Grid>
<CreateField
open={openCreate}
handleClose={handleCloseCreate}
onAgree={onCreateField}
/>
<UpdateFountain
open={openUpdate}
handleClose={handleCloseUpdate}
onAgree={onUpdateField}
data={fountainSelected}
/>
</ValidatorForm> </ValidatorForm>
</SimpleCard> </SimpleCard>
</div> </div>
......
...@@ -60,7 +60,6 @@ const SimpleForm = (props) => { ...@@ -60,7 +60,6 @@ const SimpleForm = (props) => {
props.showLoading() props.showLoading()
const res = await createProduct({ const res = await createProduct({
...newValue, ...newValue,
type_id: 2,
}) })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { 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