Commit 352ae214 by tdgiang

updaten code

parent abd2af98
{
"name": "matx-react",
"name": "PetroPos",
"version": "2.0.0",
"private": true,
"dependencies": {
......
//const root = 'http://petrolpay.tasvietnam.vn:9985/api'
const root = 'https://apigw.petropos.vn/api'
//const root = 'https://apigw.petropos.vn/api'
//const root = 'http://dcvf.tasvietnam.vn:9986/api'
//const root = 'https://apigw-v2.petropos.vn/api'
const root = 'https://apitest.petropos.vn/api'
export default {
//Dang nhap,thong tin ca nhan
......@@ -105,8 +108,6 @@ export default {
updateStatusRequest: `${root}/customerCare/changeStatus`,
detailCustomerCare: `${root}/customerCare`,
//dropdown
dropdownFuntions: `${root}/dropdown/function`,
dropdownPermission: `${root}/function/getFunctionTree`,
......
......@@ -358,6 +358,8 @@
"ERROR_CODE_IS_EXITS":"Mã code đã tồn tại",
"ERROR_NAME_IS_EXITS":"Tên sản phẩm đã tồn tại",
"ERROR_MERCHAN_STORE_CODE":"Mã cây xăng đã tồn tại",
"ERROR_IMAGE_NOT_VALID":"Ảnh không đúng dịnh dạng"
"ERROR_IMAGE_NOT_VALID":"Ảnh không đúng dịnh dạng",
"ERROR_OTP_IS_EXPIRED":"OTP đã hết hạn",
"ERROR_QUEUE_CODE_EXIST":"Mã Queue đã tồn tại"
}
......@@ -24,6 +24,7 @@ const validateImg = (string) => {
function UploadButtons(props) {
const { image, onFileChange } = props
const upLoadImage = async (event) => {
try {
if (validateImg(event.target.files[0])) {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
......@@ -43,6 +44,11 @@ function UploadButtons(props) {
theme: 'colored',
})
}
} catch (error) {
toast.warn('Upload ảnh thất bại!', {
theme: 'colored',
})
}
}
const createFormData = (photo, body) => {
......
......@@ -29,13 +29,13 @@ function UploadButtons(props) {
const { images, onFileChange, title } = props
const upLoadImage = async (event) => {
try {
if (validateImg(event.target.files[0])) {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
)
console.log('res image', res)
if (res.data.status == 200 && res.data.data) {
console.log(res.data.data[0].url)
onFileChange(res.data.data[0].url)
toast.success('Upload ảnh thành công!', {
theme: 'colored',
......@@ -50,6 +50,11 @@ function UploadButtons(props) {
theme: 'colored',
})
}
} catch (error) {
toast.warn('Upload ảnh thất bại!', {
theme: 'colored',
})
}
}
const createFormData = (photo, body) => {
......
......@@ -18,7 +18,7 @@ import {
Icon,
Tooltip,
RadioGroup,
MenuItem,
MenuItem,Checkbox
} from '@material-ui/core'
import { toast } from 'react-toastify'
import { useTranslation } from 'react-i18next'
......@@ -42,6 +42,7 @@ export default function FormDialog({ onCreate }) {
const [listType, setListType] = useState([])
const [listProduct, setListProduct] = useState([])
const [product,setProduct]=useState()
const [is_api,setIsApi]=useState(false)
const [type, setType] = useState()
......@@ -103,7 +104,7 @@ export default function FormDialog({ onCreate }) {
if(state?.product_id && state?.name?.trim() && state?.code?.trim()){
let index=listProduct.findIndex(e=>e.id==state.product_id)
if(index!=-1){
onCreate({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name})
onCreate({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name,is_api})
setOpen(false)
setState({})
setType()
......@@ -129,7 +130,9 @@ export default function FormDialog({ onCreate }) {
})
}
const { product_id, name, code } = state
const { product_id, name, code,domain,client_id,client_secret ,supplier_main} = state
return (
<>
......@@ -227,10 +230,100 @@ export default function FormDialog({ onCreate }) {
))}
</SelectValidator>
</Grid>
{/* <Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Base url *"
onChange={handleChange}
variant="outlined"
type="text"
name="domain"
value={domain || ''}
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="Mã khách hàng *"
onChange={handleChange}
variant="outlined"
type="text"
name="client_id"
value={client_id || ''}
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="Mật khẩu*"
onChange={handleChange}
variant="outlined"
type="text"
name="client_secret"
value={client_secret || ''}
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="Nhà cung cấp bo mạch *"
onChange={handleChange}
variant="outlined"
type="text"
name="supplier_main"
value={supplier_main || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid lg={12} md={12} sm={12} xs={12} item>
<FormControlLabel
className="min-w-288"
control={
<Checkbox
size="small"
color="primary"
onChange={(event) => {
setIsApi(
event.target.checked
)
}}
value={is_api}
/>
}
label="Sử dụng api truyền nhận"
/>
</Grid> */}
</Grid>
</DialogContent>
<DialogActions>
<Button color="secondary" onClick={handleClose}>
<Button color="secondary" onClick={()=>{
handleClose()
setType()
setProduct()
setState({})
}}>
Thoát
</Button>
<Button onClick={handleSubmit} color="primary">
......
......@@ -18,7 +18,7 @@ import {
Icon,
Tooltip,
RadioGroup,
MenuItem,
MenuItem,Checkbox
} from '@material-ui/core'
import { toast } from 'react-toastify'
import { useTranslation } from 'react-i18next'
......@@ -45,8 +45,8 @@ export default function FormDialog( props) {
const [listProduct, setListProduct] = useState([])
const [product,setProduct]=useState()
const [type, setType] = useState()
const [is_api,setIsApi]=useState(false)
console.log("data",data)
useEffect(()=>{
if(data){
......@@ -60,7 +60,7 @@ export default function FormDialog( props) {
setProduct(data.product_id)
}
},[data])
},[data,open])
useEffect(()=>{
......@@ -112,6 +112,7 @@ export default function FormDialog( props) {
const handleSubmit = async (value) => {
if(state?.product_id && state?.name?.trim() && state?.code?.trim()){
let index=listProduct.findIndex(e=>e.id==state.product_id)
if(index!=-1){
console.log(listProduct[index])
......@@ -119,9 +120,13 @@ export default function FormDialog( props) {
console.log('state', state)
onAgree({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name})}
onAgree({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name,code:state.code,is_api})}
}else{ toast.warning('Bạn chưa nhập đầy đủ thông tin', {
theme: 'colored',
})
}
}
......@@ -133,7 +138,7 @@ export default function FormDialog( props) {
})
}
const { product_id, name, code } = state
const { product_id, name, code ,domain,client_id,client_secret ,supplier_main} = state
console.log("listType",listType)
......@@ -159,7 +164,6 @@ export default function FormDialog( props) {
label="Mã vòi xăng *"
onChange={handleChange}
variant="outlined"
disabled={true}
type="text"
name="code"
value={code || ''}
......@@ -230,6 +234,88 @@ export default function FormDialog( props) {
))}
</SelectValidator>
</Grid>}
{/*
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Base url *"
onChange={handleChange}
variant="outlined"
type="text"
name="domain"
value={domain || ''}
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="Mã khách hàng *"
onChange={handleChange}
variant="outlined"
type="text"
name="client_id"
value={client_id || ''}
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="Mật khẩu*"
onChange={handleChange}
variant="outlined"
type="text"
name="client_secret"
value={client_secret || ''}
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="Nhà cung cấp bo mạch *"
onChange={handleChange}
variant="outlined"
type="text"
name="supplier_main"
value={supplier_main || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid lg={12} md={12} sm={12} xs={12} item>
<FormControlLabel
className="min-w-288"
control={
<Checkbox
size="small"
color="primary"
onChange={(event) => {
setIsApi(
event.target.checked
)
}}
value={is_api}
/>
}
label="Sử dụng api truyền nhận"
/>
</Grid> */}
</Grid>
......
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,Checkbox
} 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()
const [is_api,setIsApi]=useState(false)
console.log("data",data)
useEffect(()=>{
if(data){
setState({...data})
if(data.type){
setType(data.type)
}else{
setType(data.product_type_id)
}
setIsApi(data?.is_api)
setProduct(data.product_id)
}
},[data,open])
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) => {
if(state?.product_id && state?.name?.trim() && state?.code?.trim()){
let index=listProduct.findIndex(e=>e.id==state.product_id)
if(index!=-1){
onAgree({...state,type,type_name:listProduct[index].type_name, product_name: listProduct[index].product_name,code:state.code,is_api})}
}else{ toast.warning('Bạn chưa nhập đầy đủ thông tin', {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const { product_id, name, code,domain,client_id,client_secret ,supplier_main } = state
console.log("listType",listType)
return (
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">
Cập nhật 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"
type="text"
disabled={true}
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 item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Base url *"
onChange={handleChange}
variant="outlined"
type="text"
name="domain"
value={domain || ''}
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="Mã khách hàng *"
onChange={handleChange}
variant="outlined"
type="text"
name="client_id"
value={client_id || ''}
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="Mật khẩu*"
onChange={handleChange}
variant="outlined"
type="text"
name="client_secret"
value={client_secret || ''}
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="Nhà cung cấp bo mạch *"
onChange={handleChange}
variant="outlined"
type="text"
name="supplier_main"
value={supplier_main || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid lg={12} md={12} sm={12} xs={12} item>
<FormControlLabel
className="min-w-288"
control={
<Checkbox
checked={is_api}
size="small"
color="primary"
onChange={(event) => {
setIsApi(
event.target.checked
)
}}
/>
}
label="Sử dụng api truyền nhận"
/>
</Grid> */}
</Grid>
</DialogContent>
<DialogActions>
<Button color="secondary" onClick={handleClose}>
Thoát
</Button>
<Button onClick={handleSubmit} color="primary">
Đồng ý
</Button>
</DialogActions>
</Dialog>
)
}
......@@ -14,6 +14,10 @@ export function objectMap(object, mapFn) {
}, {})
}
export function isNumeric(value) {
return /^-?\d+$/.test(value)
}
export const toPriceVndInput = (str) => {
if (str) {
let stringPrice = str.toString().split('.')
......
......@@ -182,13 +182,13 @@ export const navigationsAdmin = [
hide: false,
},
{
name: 'Quản lý thu phí',
path: '/list-fee',
icon: 'diamond',
id: 'DASHBOARD',
hide: false,
},
// {
// name: 'Quản lý thu phí',
// path: '/list-fee',
// icon: 'diamond',
// id: 'DASHBOARD',
// hide: false,
// },
{
name: 'Yêu cầu tư vấn',
path: '/list-request',
......
......@@ -50,9 +50,16 @@ const SimpleForm = (props) => {
const getListAction = async () => {
if (role) {
const res = await actionByGroup(role, {})
console.log('res.data.data', res.data.data)
if (res.data.code == 200 && res.data.data) {
setListAction(res.data.data.userGroupPermissions)
if (res.data.data.userGroupPermissions) {
let newList = res.data.data.userGroupPermissions
newList.sort((a, b) =>
a.function_name.localeCompare(b.function_name)
)
setListAction(newList)
}
} else if (res.data.code == 401) {
setTimeout(() => {
history.push('/')
......
......@@ -91,7 +91,12 @@ const SimpleForm = (props) => {
const res = await actionByGroup(role, {})
console.log('res.data.data', res.data.data)
if (res.data.code == 200 && res.data.data) {
setListAction(res.data.data.userGroupPermissions)
let newList = res.data.data.userGroupPermissions
newList.sort((a, b) =>
a.function_name.localeCompare(b.function_name)
)
setListAction(newList)
} else if (res.data.code == 401) {
setTimeout(() => {
history.push('/')
......
......@@ -132,18 +132,19 @@ const SimpleForm = (props) => {
</Grid>
</Grid>
<Grid container justify={'flex-end'}>
<Link to="function">
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {}}
onClick={() => {
history.goBack()
}}
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
......
......@@ -156,18 +156,19 @@ const SimpleForm = (props) => {
</Grid>
</Grid>
<Grid container justify={'flex-end'}>
<Link to="function">
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {}}
onClick={() => {
history.goBack()
}}
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
......
......@@ -77,7 +77,7 @@ const SimpleForm = (props) => {
})
}
} else {
toast.error('Cập nhật hành động thất bại!', {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
......
......@@ -72,6 +72,7 @@ const ToolNotificate = (props) => {
}
const getData = async (init) => {
try {
props.showLoading()
let res
......@@ -105,7 +106,7 @@ const ToolNotificate = (props) => {
if (res.data.code == 200 && res.data.data) {
setReport(res.data.data.data)
const newList = res.data.data.data.details.map((e, i) => {
const newList = res.data.data.data.map((e, i) => {
return { ...e, index: i + 1 + pageIndex * pageSize }
})
setData(newList)
......@@ -119,6 +120,11 @@ const ToolNotificate = (props) => {
theme: 'colored',
})
}
} catch (error) {
toast.error('Hệ thống đang bận, vui lòng thử lại sau', {
theme: 'colored',
})
}
}
useEffect(() => {
......
......@@ -31,7 +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'
import UpdateFountain from 'app/components/dialog/UpdateFountainForCreat'
import { useTranslation } from 'react-i18next'
const SimpleForm = (props) => {
const [state, setState] = useState({})
......@@ -69,9 +69,6 @@ const SimpleForm = (props) => {
const handleSubmit = async (event) => {
const newValue = trimObject(state)
console.log('newValue', newValue)
console.log('listField', listField)
props.showLoading()
const res = await createGasStation({
...newValue,
......@@ -152,16 +149,16 @@ const SimpleForm = (props) => {
arr.map((e, i) => {
if (e.gas_olines) {
if (
e.gas_olines.findIndex(
(e) => e.name.toUpperCase() == data.name.toUpperCase()
) != -1
) {
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
flag = false
}
// if (
// e.gas_olines.findIndex(
// (e) => e.name.toUpperCase() == data.name.toUpperCase()
// ) != -1
// ) {
// toast.warning('Tên vòi xăng đã tồn tại', {
// theme: 'colored',
// })
// flag = false
// }
if (
e.gas_olines.findIndex(
(e) => e.code.toUpperCase() == data.code.toUpperCase()
......@@ -196,9 +193,9 @@ const SimpleForm = (props) => {
].concat(e.gas_olines),
}
} else {
// toast.warning('Mã vòi xăng đã tồn tại', {
// theme: 'colored',
// })
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
return {
...e,
gas_olines: e.gas_olines,
......@@ -257,15 +254,14 @@ const SimpleForm = (props) => {
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) {
if (
e.gas_olines.findIndex((e) => e.name == data.name) == -1
) {
const temp = e.gas_olines.map((item) => {
if (item.code == data.code) return { ...data }
return { ...item }
......@@ -275,6 +271,15 @@ const SimpleForm = (props) => {
gas_olines: temp,
}
} 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: e.gas_olines,
......@@ -299,7 +304,7 @@ const SimpleForm = (props) => {
return temp
}
const { store_name, address, merchant_id, store_code } = state
const { store_name, address, merchant_id, store_code, queue_name } = state
return (
<div className="m-sm-30">
......@@ -378,6 +383,21 @@ const SimpleForm = (props) => {
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mã Queue *"
onChange={handleChange}
type="text"
name="queue_name"
value={queue_name || ''}
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="Địa chỉ *"
onChange={handleChange}
type="text"
......@@ -715,7 +735,6 @@ const SimpleForm = (props) => {
container
justify={'flex-end'}
>
<Link to="gas-station">
<Button
style={{
marginRight: 20,
......@@ -728,7 +747,7 @@ const SimpleForm = (props) => {
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
......
......@@ -100,9 +100,6 @@ const SimpleForm = (props) => {
const handleSubmit = async (event) => {
const newValue = trimObject(state)
console.log('newValue', newValue)
console.log('listField', listField)
props.showLoading()
const res = await createGasStation({
id: newValue?.id,
......@@ -111,6 +108,7 @@ const SimpleForm = (props) => {
address: newValue?.address,
gas_fields: listField,
store_code: newValue?.store_code,
queue_name: newValue?.queue_name,
})
props.hideLoading()
if (res.data.code == 200) {
......@@ -189,16 +187,16 @@ const SimpleForm = (props) => {
arr.map((e, i) => {
if (e.gas_olines) {
if (
e.gas_olines.findIndex(
(e) => e.name.toUpperCase() == data.name.toUpperCase()
) != -1
) {
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
flag = false
}
// if (
// e.gas_olines.findIndex(
// (e) => e.name.toUpperCase() == data.name.toUpperCase()
// ) != -1
// ) {
// toast.warning('Tên vòi xăng đã tồn tại', {
// theme: 'colored',
// })
// flag = false
// }
if (
e.gas_olines.findIndex(
(e) => e.code.toUpperCase() == data.code.toUpperCase()
......@@ -234,9 +232,9 @@ const SimpleForm = (props) => {
].concat(e.gas_olines),
}
} else {
// toast.warning('Mã vòi xăng đã tồn tại', {
// theme: 'colored',
// })
toast.warning('Tên vòi xăng đã tồn tại', {
theme: 'colored',
})
return {
...e,
gas_olines: e.gas_olines,
......@@ -298,24 +296,30 @@ const SimpleForm = (props) => {
setOpenUpdate(false)
}
const onUpdateField = (data) => {
console.log('hehe', data)
console.log('fountainSelected', fountainSelected)
let arr = [...listField]
let newList = arr.map((e, i) => {
console.log('data', data)
console.log('e.gas_olines', e.gas_olines)
if (e.gas_olines.findIndex((e) => e.code == data.code) != -1) {
if (e.gas_olines.findIndex((e) => e.id == data.id) != -1) {
// if (e.gas_olines.findIndex((e) => e.name == data.name) == -1) {
console.log('gas_olines', e.gas_olines)
const temp = e.gas_olines.map((item) => {
console.log('Run item', item)
console.log('Run data', data)
if (item.code == data.code) return { ...data }
if (item.id == data.id) return { ...data }
return { ...item }
})
return {
...e,
gas_olines: temp,
}
// } 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,
......@@ -323,7 +327,6 @@ const SimpleForm = (props) => {
}
}
})
console.log('newList', newList)
setListField(newList)
setOpenUpdate(false)
......@@ -369,7 +372,7 @@ const SimpleForm = (props) => {
}
}
const { store_name, address, merchant_id, store_code } = state
const { store_name, address, merchant_id, store_code, queue_name } = state
return (
<div className="m-sm-30">
......@@ -447,6 +450,21 @@ const SimpleForm = (props) => {
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mã Queue *"
onChange={handleChange}
type="text"
name="queue_name"
value={queue_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
......@@ -721,6 +739,7 @@ const SimpleForm = (props) => {
</TableCell> */}
<TableCell>
{row?.id && (
<Tooltip title="Cập nhật">
<IconButton
onClick={() => {
......@@ -747,6 +766,8 @@ const SimpleForm = (props) => {
</Icon>
</IconButton>
</Tooltip>
)}
<Tooltip title="Xoá">
<IconButton
onClick={() => {
......@@ -791,7 +812,6 @@ const SimpleForm = (props) => {
container
justify={'flex-end'}
>
<Link to="gas-station">
<Button
style={{
marginRight: 20,
......@@ -804,7 +824,7 @@ const SimpleForm = (props) => {
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
......
......@@ -28,6 +28,7 @@ const SimpleForm = (props) => {
const [isStore, setIsStore] = useState(false)
const [invoice, setInvoice] = useState(false)
const [payment, setPayment] = useState(false)
const [isAuto, setAuto] = useState(false)
const [listDrop, setListDrop] = useState([])
const { t } = useTranslation()
const location = useLocation()
......@@ -84,6 +85,7 @@ const SimpleForm = (props) => {
is_admin_store: isStore,
is_connect_hddt: invoice,
is_connect_qr: payment,
is_hddt_nomal: isAuto,
})
props.hideLoading()
if (res.data.code == 200) {
......@@ -535,6 +537,27 @@ const SimpleForm = (props) => {
) : null}
{invoice ? (
<Grid lg={6} md={6} sm={12} xs={12} item>
<FormControlLabel
className="min-w-288"
control={
<Checkbox
size="small"
color="primary"
onChange={(event) => {
setAuto(
event.target.checked
)
}}
value={isAuto}
/>
}
label="Tự động phát hoá đơn"
/>
</Grid>
) : null}
{invoice && isAuto ? (
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
......@@ -544,9 +567,10 @@ const SimpleForm = (props) => {
type="text"
name="publish_invoce_time"
value={publish_invoce_time || ''}
validators={['required']}
validators={['required', 'isNumber']}
errorMessages={[
'Không được để trống trường này',
'Trường này bắt buộc phải nhập số',
]}
/>
</Grid>
......
......@@ -29,6 +29,7 @@ const SimpleForm = (props) => {
const [isStore, setIsStore] = useState(false)
const [invoice, setInvoice] = useState(false)
const [payment, setPayment] = useState(false)
const [isAuto, setAuto] = useState(false)
const [listDrop, setListDrop] = useState([])
const { t } = useTranslation()
......@@ -113,6 +114,7 @@ const SimpleForm = (props) => {
is_admin_store: isStore,
is_connect_hddt: invoice,
is_connect_qr: payment,
is_hddt_nomal: isAuto,
})
props.hideLoading()
if (res.data.code == 200) {
......@@ -547,6 +549,27 @@ const SimpleForm = (props) => {
) : null}
{invoice ? (
<Grid lg={6} md={6} sm={12} xs={12} item>
<FormControlLabel
className="min-w-288"
control={
<Checkbox
size="small"
color="primary"
onChange={(event) => {
setAuto(
event.target.checked
)
}}
value={isAuto}
/>
}
label="Tự động phát hoá đơn"
/>
</Grid>
) : null}
{invoice && isAuto ? (
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
......@@ -556,9 +579,10 @@ const SimpleForm = (props) => {
type="text"
name="publish_invoce_time"
value={publish_invoce_time || ''}
validators={['required']}
validators={['required', 'isNumber']}
errorMessages={[
'Không được để trống trường này',
'Trường này bắt buộc phải nhập số',
]}
/>
</Grid>
......@@ -636,7 +660,6 @@ const SimpleForm = (props) => {
) : null}
</Grid>
<Grid container justify={'flex-end'}>
<Link to="merchant">
<Button
style={{
marginRight: 20,
......@@ -649,7 +672,7 @@ const SimpleForm = (props) => {
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
......
......@@ -23,7 +23,7 @@ import { Breadcrumb, SimpleCard } from 'app/components'
import { dropdownProductType } from 'app/apis/Functions/dropdown'
import { Link, useHistory, useLocation } from 'react-router-dom'
import { toast } from 'react-toastify'
import { trimObject, toPriceVndInput } from 'app/config/Function'
import { trimObject, toPriceVndInput, isNumeric } from 'app/config/Function'
import { connect } from 'react-redux'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { createProduct } from 'app/apis/Functions/product'
......@@ -58,6 +58,8 @@ const SimpleForm = (props) => {
const handleSubmit = async (event) => {
const newValue = trimObject(state)
if (isNumeric(newValue.price_default)) {
props.showLoading()
const res = await createProduct({
...newValue,
......@@ -75,6 +77,11 @@ const SimpleForm = (props) => {
theme: 'colored',
})
}
} else {
toast.error('Giá mặc định không đúng định dạng', {
theme: 'colored',
})
}
}
const handleChange = (event) => {
......
......@@ -11,7 +11,7 @@ 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, toPriceVndInput } from 'app/config/Function'
import { trimObject, toPriceVndInput, isNumeric } from 'app/config/Function'
import { connect } from 'react-redux'
import localStorageService from 'app/services/localStorageService'
import { useTranslation } from 'react-i18next'
......@@ -67,6 +67,7 @@ const SimpleForm = (props) => {
const handleSubmit = async (event) => {
const newValue = trimObject(state)
if (isNumeric(newValue.price_default)) {
props.showLoading()
const res = await updateProduct({
...newValue,
......@@ -84,6 +85,11 @@ const SimpleForm = (props) => {
theme: 'colored',
})
}
} else {
toast.warn('Giá mặc định không đúng định dạng', {
theme: 'colored',
})
}
}
const handleChange = (event) => {
......
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