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 { provider_code, provider_name, phone, email, address } = state const onAdd = () => {
setListMoney(
listMoney.concat([
{
condition: 0,
money: 0,
},
])
)
}
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
style={{ alignItems: 'center' }}
row
item
lg={6}
md={6}
sm={12}
xs={12}
>
<RadioGroup
row
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>
{type == 'percent' ? (
<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="Tên nhà cung cấp *" label="Giá trị (%)"
onChange={handleChange} onChange={handleChange}
type="text" type="text"
name="provider_name" name="provider_code"
value={provider_name || ''} value={provider_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',
]} ]}
/> />
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> ) : (
<TextValidator <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" variant="outlined"
className="mb-4 w-full" name="condition"
label="Số điện thoại *" value={
onChange={handleChange} listMoney[index]
type="text" .condition
name="phone" }
value={phone || ''} onChange={(event) =>
validators={[ handleChangeList(
'required', event,
'isNumber', index
'minStringLength:10', )
'maxStringLength:15', }
]}
errorMessages={[
'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ố',
]}
/> />
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> <Grid
<TextValidator item
lg={5}
md={5}
sm={5}
xs={5}
>
<TextField
label="Hoa hồng *"
fullWidth
name="money"
value={
listMoney[index].money
}
variant="outlined" 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="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ệ',
]} ]}
/> >
{[].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid> </Grid>
<Grid item lg={6} md={6} sm={12} xs={12}> <Grid xs={6} sm={6} item>
<TextValidator <SelectValidator
variant="outlined" variant={'outlined'}
label={'Thời điểm đối soát *'}
className="mb-4 w-full" className="mb-4 w-full"
label="Địa chỉ" value={merchant_id || ''}
displayEmpty
name="merchant_id"
onChange={handleChange} onChange={handleChange}
type="text" validators={['required']}
name="address" errorMessages={[
value={address || ''} 'Không được để trống trường này',
/> ]}
>
{[].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</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