Commit 1be034e5 by tdgiang

update code

parent 7d28f6b0
...@@ -61,4 +61,5 @@ p.MuiFormHelperText-root.MuiFormHelperText-contained.Mui-error.MuiFormHelperText ...@@ -61,4 +61,5 @@ p.MuiFormHelperText-root.MuiFormHelperText-contained.Mui-error.MuiFormHelperText
.MuiInputBase-input.Mui-disabled { .MuiInputBase-input.Mui-disabled {
color: black !important; color: black !important;
background-color: #f6f6f6 !important;
} }
...@@ -147,6 +147,14 @@ export const convertTimeApi = (date) => { ...@@ -147,6 +147,14 @@ export const convertTimeApi = (date) => {
const time = moment(temp).format('YYYY-MM-DD') const time = moment(temp).format('YYYY-MM-DD')
return time return time
} }
export function replaceItemInArray(array, index, newValue) {
if (index >= 0 && index < array.length) {
array[index] = newValue
} else {
console.log('Index out of bounds')
}
return array
}
export const convertDate = (date) => { export const convertDate = (date) => {
const time = moment(date).format('DD/MM/YYYY') const time = moment(date).format('DD/MM/YYYY')
......
...@@ -11,6 +11,12 @@ import { ...@@ -11,6 +11,12 @@ import {
FormControlLabel, FormControlLabel,
Checkbox, Checkbox,
Typography, Typography,
RadioGroup,
Radio,
IconButton,
TextField,
Icon,
InputAdornment,
} from '@material-ui/core' } from '@material-ui/core'
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'
...@@ -21,6 +27,7 @@ import { ...@@ -21,6 +27,7 @@ import {
encryString, encryString,
convertDate, convertDate,
convertTimeApi, convertTimeApi,
replaceItemInArray,
} from 'app/config/Function' } from 'app/config/Function'
import { connect } from 'react-redux' import { connect } from 'react-redux'
...@@ -32,6 +39,13 @@ const SimpleForm = (props) => { ...@@ -32,6 +39,13 @@ const SimpleForm = (props) => {
const location = useLocation() const location = useLocation()
const [image, setImage] = useState() const [image, setImage] = useState()
const { user } = useAuth() const { user } = useAuth()
const [type, setType] = useState('percent')
const [listMoney, setListMoney] = useState([
{
condition: 0,
money: 0,
},
])
const [date, setDate] = useState(null) const [date, setDate] = useState(null)
const { t } = useTranslation() const { t } = useTranslation()
...@@ -83,8 +97,69 @@ const SimpleForm = (props) => { ...@@ -83,8 +97,69 @@ const SimpleForm = (props) => {
[event.target.name]: event.target.value, [event.target.name]: event.target.value,
}) })
} }
const handleChangeList = (event, index) => {
event.persist()
if (
event.target.name == 'condition' ||
event.target.name == 'money' ||
event.target.name == 'length'
) {
console.log('hêlo', event.target.name)
console.log('value', event.target.value)
const inputValue = event.target.value
// Kiểm tra nếu input là số nguyên hoặc số thập phân
const regex = /^-?\d*\.?\d*$/
if (regex.test(inputValue)) {
console.log('run', inputValue)
let newList = [...listMoney]
const temp = {
...listMoney[index],
[event.target.name]: event.target.value,
}
newList = replaceItemInArray(newList, index, temp)
setListMoney(newList)
} else {
let newList = [...listMoney]
setListMoney(newList)
}
} else {
let newList = [...listMoney]
const temp = {
...listMoney[index],
[event.target.name]: event.target.value,
}
newList = replaceItemInArray(newList, index, temp)
setListMoney(newList)
}
}
const onAdd = () => {
setListMoney(
listMoney.concat([
{
condition: 0,
money: 0,
},
])
)
}
const { provider_code, provider_name, phone, email, address } = state const deleteTank = (index) => {
if (listMoney.length > 1) {
let arr = [...listMoney]
arr.splice(index, 1)
setListMoney(arr)
toast.success('Xoá điều kiện thành công!', {
theme: 'colored',
})
} else {
toast.warning('Phải có ít nhất một điều kiện!', {
theme: 'colored',
})
}
}
const { provider_code, provider_name, phone, email, merchant_id } = state
return ( return (
<div className="m-sm-30"> <div className="m-sm-30">
<div className="mb-sm-30"> <div className="mb-sm-30">
...@@ -106,7 +181,7 @@ const SimpleForm = (props) => { ...@@ -106,7 +181,7 @@ const SimpleForm = (props) => {
<TextValidator <TextValidator
variant="outlined" variant="outlined"
className="mb-4 w-full" className="mb-4 w-full"
label="Mã nhà cung cấp *" label="Đối tác"
onChange={handleChange} onChange={handleChange}
type="text" type="text"
name="provider_code" name="provider_code"
...@@ -118,71 +193,211 @@ const SimpleForm = (props) => { ...@@ -118,71 +193,211 @@ const SimpleForm = (props) => {
]} ]}
/> />
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> <Grid
<TextValidator style={{ alignItems: 'center' }}
variant="outlined" row
className="mb-4 w-full" item
label="Tên nhà cung cấp *" lg={6}
onChange={handleChange} md={6}
type="text" sm={12}
name="provider_name" xs={12}
value={provider_name || ''} >
validators={['required']} <RadioGroup
errorMessages={[ row
'Không được để trống trường này', value={type}
]} onChange={(event) => {
/> setType(event.target.value)
}}
>
<FormControlLabel
value={'percent'}
control={<Radio />}
label="Theo %"
style={{
marginRight: 100,
}}
/>
<FormControlLabel
value={'cost'}
control={<Radio />}
label="Số tiền cố định"
/>
</RadioGroup>
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator {type == 'percent' ? (
variant="outlined" <Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Giá trị (%)"
onChange={handleChange}
type="text"
name="provider_code"
value={provider_code || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
) : (
<Grid item lg={12} md={12} sm={12} xs={12}>
{listMoney.map((item, index) => (
<Grid
lg={12}
md={12}
sm={12}
xs={12}
container
spacing={3}
>
<Grid
item
lg={5}
md={5}
sm={5}
xs={5}
>
<TextField
label="Điều kiện"
fullWidth
disabled={
index == 0
? true
: false
}
InputProps={{
style: {
backgroundColor:
index == 0
? '#f6f6f6'
: '#fff',
},
startAdornment: (
<InputAdornment position="start">
>=
</InputAdornment>
),
}}
variant="outlined"
name="condition"
value={
listMoney[index]
.condition
}
onChange={(event) =>
handleChangeList(
event,
index
)
}
/>
</Grid>
<Grid
item
lg={5}
md={5}
sm={5}
xs={5}
>
<TextField
label="Hoa hồng *"
fullWidth
name="money"
value={
listMoney[index].money
}
variant="outlined"
InputProps={{
endAdornment: (
<InputAdornment position="end">
VND
</InputAdornment>
),
}}
onChange={(event) =>
handleChangeList(
event,
index
)
}
/>
</Grid>
<Grid
item
lg={2}
md={2}
sm={2}
xs={2}
>
<IconButton
onClick={() => {
deleteTank(index)
}}
color="error"
>
<Icon color="error">
cancel
</Icon>
</IconButton>
</Grid>
</Grid>
))}
<Button
onClick={onAdd}
variant="contained"
color="primary"
>
<Icon style={{ color: 'white' }}>
add_circle
</Icon>
</Button>
</Grid>
)}
<Grid xs={6} sm={6} item>
<SelectValidator
variant={'outlined'}
label={'Chu kỳ đối soát *'}
className="mb-4 w-full" className="mb-4 w-full"
label="Số điện thoại *" value={merchant_id || ''}
displayEmpty
name="merchant_id"
onChange={handleChange} onChange={handleChange}
type="text" validators={['required']}
name="phone"
value={phone || ''}
validators={[
'required',
'isNumber',
'minStringLength:10',
'maxStringLength:15',
]}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
'Trường này phải nhập số ',
'Số điện thoại phải có ít nhất 10 chữ số',
'Số điện thoại nhiều nhất chỉ có 15 chữ số',
]} ]}
/> >
{[].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator <Grid xs={6} sm={6} item>
variant="outlined" <SelectValidator
variant={'outlined'}
label={'Thời điểm đối soát *'}
className="mb-4 w-full" className="mb-4 w-full"
label="Email *" value={merchant_id || ''}
displayEmpty
name="merchant_id"
onChange={handleChange} onChange={handleChange}
type="text" validators={['required']}
name="email"
value={email || ''}
validators={['required', 'isEmail']}
errorMessages={[ errorMessages={[
'Không được để trống trường này', 'Không được để trống trường này',
'Email không hợp lệ',
]} ]}
/> >
</Grid> {[].map((e) => (
<MenuItem value={e.id}>
<Grid item lg={6} md={6} sm={12} xs={12}> {e.name}
<TextValidator </MenuItem>
variant="outlined" ))}
className="mb-4 w-full" </SelectValidator>
label="Địa chỉ"
onChange={handleChange}
type="text"
name="address"
value={address || ''}
/>
</Grid> </Grid>
</Grid> </Grid>
<Grid <Grid
......
...@@ -128,7 +128,7 @@ function CustomerView(props) { ...@@ -128,7 +128,7 @@ function CustomerView(props) {
</FormControl> </FormControl>
</Grid> </Grid>
</Grid> </Grid>
{checkRole(user, '/reconciliation/setting/create') ? ( {/* {checkRole(user, '/reconciliation/setting/create') ? (
<Link to="/reconciliation/setting/create"> <Link to="/reconciliation/setting/create">
<Button <Button
variant="contained" variant="contained"
...@@ -137,7 +137,7 @@ function CustomerView(props) { ...@@ -137,7 +137,7 @@ function CustomerView(props) {
<span className={'text-primary'}>Thêm mới</span> <span className={'text-primary'}>Thêm mới</span>
</Button> </Button>
</Link> </Link>
) : null} ) : null} */}
</Grid> </Grid>
<Table <Table
......
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