Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CmsPetrolPay
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
11
Issues
11
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Giang Tran
CmsPetrolPay
Commits
5acc8772
Commit
5acc8772
authored
Jan 24, 2024
by
tdgiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code
parent
e108ebbb
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1027 additions
and
59 deletions
+1027
-59
merchant.js
src/app/apis/Functions/merchant.js
+10
-0
url.js
src/app/apis/url.js
+3
-0
CreateFountain.jsx
src/app/components/dialog/CreateFountain.jsx
+19
-7
UpdateFountain.jsx
src/app/components/dialog/UpdateFountain.jsx
+242
-0
Create.js
src/app/views/GasStation/Create.js
+135
-12
Index.js
src/app/views/GasStation/Index.js
+1
-1
Table.js
src/app/views/GasStation/Table.js
+1
-1
Update.js
src/app/views/GasStation/Update.js
+616
-37
Create.js
src/app/views/product/product/Create.js
+0
-1
No files found.
src/app/apis/Functions/merchant.js
View file @
5acc8772
...
...
@@ -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
)
src/app/apis/url.js
View file @
5acc8772
...
...
@@ -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`
,
...
...
src/app/components/dialog/CreateFountain.jsx
View file @
5acc8772
...
...
@@ -99,10 +99,21 @@ export default function FormDialog({ onCreate }) {
}
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
)
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
)
=>
{
...
...
@@ -137,12 +148,12 @@ export default function FormDialog({ onCreate }) {
<
Grid
item
lg=
{
12
}
md=
{
12
}
sm=
{
12
}
xs=
{
12
}
>
<
TextValidator
className=
"mb-4 w-full"
label=
"
Tên
vòi xăng *"
label=
"
Mã
vòi xăng *"
onChange=
{
handleChange
}
variant=
"outlined"
type=
"text"
name=
"
nam
e"
value=
{
nam
e
||
''
}
name=
"
cod
e"
value=
{
cod
e
||
''
}
validators=
{
[
'required'
]
}
errorMessages=
{
[
'Không được để trống trường này'
,
...
...
@@ -152,12 +163,12 @@ export default function FormDialog({ onCreate }) {
<
Grid
item
lg=
{
12
}
md=
{
12
}
sm=
{
12
}
xs=
{
12
}
>
<
TextValidator
className=
"mb-4 w-full"
label=
"
Mã
vòi xăng *"
label=
"
Tên
vòi xăng *"
onChange=
{
handleChange
}
variant=
"outlined"
type=
"text"
name=
"
cod
e"
value=
{
cod
e
||
''
}
name=
"
nam
e"
value=
{
nam
e
||
''
}
validators=
{
[
'required'
]
}
errorMessages=
{
[
'Không được để trống trường này'
,
...
...
@@ -165,6 +176,7 @@ export default function FormDialog({ onCreate }) {
/>
</
Grid
>
<
Grid
item
lg=
{
12
}
md=
{
12
}
sm=
{
12
}
xs=
{
12
}
>
<
SelectValidator
variant=
{
'outlined'
}
...
...
src/app/components/dialog/UpdateFountain.jsx
0 → 100644
View file @
5acc8772
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
>
)
}
src/app/views/GasStation/Create.js
View file @
5acc8772
...
...
@@ -14,7 +14,7 @@ import {
Tooltip
,
}
from
'@material-ui/core'
import
_
from
'lodash'
import
{
create
Function
}
from
'app/apis/Functions/function
'
import
{
create
GasStation
}
from
'app/apis/Functions/merchant
'
import
{
showLoading
,
hideLoading
}
from
'app/redux/actions/loadingAction'
import
{
toast
}
from
'react-toastify'
import
{
Breadcrumb
,
SimpleCard
}
from
'app/components'
...
...
@@ -31,6 +31,7 @@ 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'
const
SimpleForm
=
(
props
)
=>
{
const
[
state
,
setState
]
=
useState
({})
...
...
@@ -38,6 +39,8 @@ const SimpleForm = (props) => {
const
[
listDrop
,
setListDrop
]
=
useState
([])
const
[
openCreate
,
setOpenCreate
]
=
useState
(
false
)
const
[
listField
,
setListField
]
=
useState
([])
const
[
fountainSelected
,
setFountainSelected
]
=
useState
()
const
[
openUpdate
,
setOpenUpdate
]
=
useState
()
useEffect
(()
=>
{
getData
()
...
...
@@ -65,22 +68,25 @@ const SimpleForm = (props) => {
const
handleSubmit
=
async
(
event
)
=>
{
const
newValue
=
trimObject
(
state
)
console
.
log
(
'newValue'
,
newValue
)
console
.
log
(
'listField'
,
listField
)
props
.
showLoading
()
const
res
=
await
create
Func
tion
({
const
res
=
await
create
GasSta
tion
({
...
newValue
,
status
:
1
,
is_default
:
true
,
gas_fields
:
listField
,
})
props
.
hideLoading
()
if
(
res
.
data
.
code
==
200
)
{
history
.
push
(
'/gas-station'
)
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'
,
})
}
}
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'
,
})
}
...
...
@@ -140,6 +146,13 @@ const SimpleForm = (props) => {
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
:
[
...
...
@@ -149,6 +162,15 @@ const SimpleForm = (props) => {
].
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
:
[
...
...
@@ -164,14 +186,85 @@ const SimpleForm = (props) => {
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
)
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
{
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
(
<
div
className
=
"m-sm-30"
>
...
...
@@ -294,7 +387,7 @@ const SimpleForm = (props) => {
{
listField
.
length
}
<
/Typography
>
<
Typography
variant
=
"subtitle1"
>
S
ố
l
ượ
ng
tr
ụ
:
3
S
ố
l
ượ
ng
tr
ụ
:
{
countFountain
()}
<
/Typography
>
<
/div
>
<
Button
...
...
@@ -503,9 +596,24 @@ const SimpleForm = (props) => {
</TableCell> */
}
<
TableCell
>
<
Tooltip
title
=
"
Xoá
"
>
<
Tooltip
title
=
"
Cập nhật
"
>
<
IconButton
onClick
=
{()
=>
{}}
onClick
=
{()
=>
{
setOpenUpdate
(
true
)
setFountainSelected
(
{
...
row
,
index
,
}
)
console
.
log
(
'heelo'
,
index
)
}}
//className={classes.button}
aria
-
label
=
"Delete"
>
...
...
@@ -516,7 +624,16 @@ const SimpleForm = (props) => {
<
/Tooltip
>
<
Tooltip
title
=
"Xoá"
>
<
IconButton
onClick
=
{()
=>
{}}
onClick
=
{()
=>
{
deleteFountain
(
item
,
index
)
console
.
log
(
'heelo'
,
index
)
}}
//className={classes.button}
aria
-
label
=
"Delete"
>
...
...
@@ -574,6 +691,12 @@ const SimpleForm = (props) => {
handleClose
=
{
handleCloseCreate
}
onAgree
=
{
onCreateField
}
/
>
<
UpdateFountain
open
=
{
openUpdate
}
handleClose
=
{
handleCloseUpdate
}
onAgree
=
{
onUpdateField
}
data
=
{
fountainSelected
}
/
>
<
/ValidatorForm
>
<
/SimpleCard
>
<
/div
>
...
...
src/app/views/GasStation/Index.js
View file @
5acc8772
...
...
@@ -92,7 +92,7 @@ const ToolNotificate = (props) => {
const
removeItem
=
async
(
id
)
=>
{
props
.
showLoading
()
const
res
=
await
deleteGasStation
({
id
})
const
res
=
await
deleteGasStation
({
id
Guid
:
id
})
props
.
hideLoading
()
if
(
res
.
data
.
code
==
200
)
{
getData
()
...
...
src/app/views/GasStation/Table.js
View file @
5acc8772
...
...
@@ -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
)
}}
...
...
src/app/views/GasStation/Update.js
View file @
5acc8772
import
React
,
{
useState
,
useEffect
}
from
'react'
import
{
ValidatorForm
,
TextValidator
}
from
'react-material-ui-form-validator'
import
{
Button
,
Grid
}
from
'@material-ui/core'
import
{
detailFunction
,
updateFunction
}
from
'app/apis/Functions/function'
import
{
ValidatorForm
,
TextValidator
,
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
{
toast
}
from
'react-toastify'
import
{
Breadcrumb
,
SimpleCard
}
from
'app/components'
import
{
Link
,
useHistory
,
useLocation
}
from
'react-router-dom'
import
{
trimObject
}
from
'app/config/Function'
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
[
state
,
setState
]
=
useState
({})
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
{
t
}
=
useTranslation
()
useEffect
(()
=>
{
getDateDetail
()
getData
()
},
[])
const
getDat
a
=
async
()
=>
{
const
getDat
eDetail
=
async
()
=>
{
props
.
showLoading
()
const
res
=
await
detail
Func
tion
(
location
.
state
,
{})
const
res
=
await
detail
GasSta
tion
(
location
.
state
,
{})
props
.
hideLoading
()
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
)
}
else
if
(
res
.
data
.
code
==
401
)
{
localStorageService
.
removeToken
()
setTimeout
(()
=>
{
history
.
push
(
'/'
)
},
100
)
...
...
@@ -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
newValue
=
trimObject
(
state
)
console
.
log
(
'newValue'
,
newValue
)
console
.
log
(
'listField'
,
listField
)
props
.
showLoading
()
const
res
=
await
updateFunction
({
...
newValue
,
status
:
1
,
is_default
:
true
,
const
res
=
await
createGasStation
({
id
:
newValue
?.
id
,
merchant_id
:
newValue
?.
merchant_id
,
store_name
:
newValue
?.
store_name
,
address
:
newValue
?.
address
,
gas_fields
:
listField
,
})
props
.
hideLoading
()
if
(
res
.
data
.
code
==
200
)
{
history
.
push
(
'/gas-station'
)
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'
,
})
}
}
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'
,
})
}
...
...
@@ -72,7 +138,184 @@ const SimpleForm = (props) => {
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
(
<
div
className
=
"m-sm-30"
>
...
...
@@ -89,71 +332,396 @@ const SimpleForm = (props) => {
/
>
<
/div
>
<
SimpleCard
>
<
ValidatorForm
onSubmit
=
{
handleSubmit
}
onError
=
{()
=>
null
}
>
<
ValidatorForm
id
=
"form-create"
onSubmit
=
{
handleSubmit
}
onError
=
{()
=>
null
}
>
<
Grid
container
spacing
=
{
3
}
>
<
Grid
item
lg
=
{
6
}
md
=
{
6
}
sm
=
{
12
}
xs
=
{
12
}
>
<
TextValidator
variant
=
"outlined"
{
merchant_id
&&
(
<
Grid
xs
=
{
6
}
sm
=
{
6
}
item
>
<
SelectValidator
variant
=
{
'outlined'
}
label
=
{
'Thuộc pháp nhân *'
}
disabled
=
{
true
}
className
=
"mb-4 w-full"
label
=
"Tên cây xăng *"
value
=
{
merchant_id
||
''
}
displayEmpty
name
=
"merchant_id"
onChange
=
{
handleChange
}
type
=
"text"
name
=
"name"
value
=
{
name
||
''
}
validators
=
{[
'required'
]}
errorMessages
=
{[
'Không được để trống trường này'
,
]}
/
>
>
{
listDrop
.
map
((
e
)
=>
(
<
MenuItem
value
=
{
e
.
id
}
>
{
e
.
name
}
<
/MenuItem
>
))}
<
/SelectValidator
>
<
/Grid
>
)}
<
Grid
item
lg
=
{
6
}
md
=
{
6
}
sm
=
{
12
}
xs
=
{
12
}
>
<
TextValidator
variant
=
"outlined"
className
=
"mb-4 w-full"
label
=
"
Mã code
*"
label
=
"
Tên cây xăng
*"
onChange
=
{
handleChange
}
type
=
"text"
name
=
"
cod
e"
value
=
{
cod
e
||
''
}
name
=
"
store_nam
e"
value
=
{
store_nam
e
||
''
}
validators
=
{[
'required'
]}
errorMessages
=
{[
'Không được để trống trường này'
,
]}
/
>
<
/Grid
>
<
Grid
item
lg
=
{
6
}
md
=
{
6
}
sm
=
{
12
}
xs
=
{
12
}
>
<
TextValidator
variant
=
"outlined"
className
=
"mb-4 w-full"
label
=
"Đ
ường dẫn
*"
label
=
"Đ
ịa chỉ
*"
onChange
=
{
handleChange
}
type
=
"text"
name
=
"
url
"
value
=
{
url
||
''
}
name
=
"
address
"
value
=
{
address
||
''
}
validators
=
{[
'required'
]}
errorMessages
=
{[
'Không được để trống trường này'
,
]}
/
>
<
/Grid
>
<
Grid
item
lg
=
{
6
}
md
=
{
6
}
sm
=
{
12
}
xs
=
{
12
}
>
{
/*
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label
=
"
Mô tả
"
label="
Tên cây xăng *
"
onChange={handleChange}
type="text"
name
=
"
description
"
value
=
{
description
||
''
}
//
validators={['required']}
name="
store_name
"
value={
store_name
|| ''}
validators={['required']}
errorMessages={[
'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
m
ỗ
i
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
m
ớ
i
tr
ụ
<
/span
>
<
/Button
>
<
/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"
>
Lo
ạ
i
nhi
ê
n
li
ệ
u
<
/TableCell
>
<
TableCell
style
=
{{
borderRight
:
'0.05px solid #e0e0e0'
,
}}
align
=
"center"
>
S
ả
n
ph
ẩ
m
<
/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
container
justify
=
{
'flex-end'
}
>
<
/Grid
>
<
Grid
style
=
{{
marginTop
:
40
,
}}
container
justify
=
{
'flex-end'
}
>
<
Link
to
=
"gas-station"
>
<
Button
style
=
{{
...
...
@@ -174,6 +742,17 @@ const SimpleForm = (props) => {
<
span
className
=
"capitalize"
>
C
ậ
p
nh
ậ
t
<
/span
>
<
/Button
>
<
/Grid
>
<
CreateField
open
=
{
openCreate
}
handleClose
=
{
handleCloseCreate
}
onAgree
=
{
onCreateField
}
/
>
<
UpdateFountain
open
=
{
openUpdate
}
handleClose
=
{
handleCloseUpdate
}
onAgree
=
{
onUpdateField
}
data
=
{
fountainSelected
}
/
>
<
/ValidatorForm
>
<
/SimpleCard
>
<
/div
>
...
...
src/app/views/product/product/Create.js
View file @
5acc8772
...
...
@@ -60,7 +60,6 @@ const SimpleForm = (props) => {
props
.
showLoading
()
const
res
=
await
createProduct
({
...
newValue
,
type_id
:
2
,
})
props
.
hideLoading
()
if
(
res
.
data
.
code
==
200
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment