Commit e108ebbb by tdgiang

update code

parent 52744883
......@@ -54,3 +54,13 @@ export const dropdownMerchant = async (body) =>
GetData(url.dropdownMerchant, body)
.then((res) => res)
.catch((err) => null)
export const dropdownProduct = async (body) =>
GetData(url.dropdownProduct, body)
.then((res) => res)
.catch((err) => null)
export const dropdownProcutByType = async (id) =>
GetData(`${url.dropdownProcutByType}/${id}`, {})
.then((res) => res)
.catch((err) => null)
......@@ -100,4 +100,5 @@ export default {
dropdownProduct: `${root}/dropdown/productList`,
dropdownStore: `${root}/dropdown/listStore`,
dropdownMerchant: `${root}/dropdown/listmerchant`,
dropdownProcutByType: `${root}/dropdown/productListByType`,
}
import React, { useState, useEffect,use } from "react";
import React, { useState, useEffect, use } from 'react'
import {
Button,
FormControl,
......@@ -7,75 +7,63 @@ import {
Select,
TextField,
Typography,
DialogActions,Dialog,DialogContent,DialogContentText,DialogTitle,IconButton,Icon,Tooltip
DialogActions,
Dialog,
DialogContent,
DialogContentText,
DialogTitle,
IconButton,
Icon,
Tooltip,
} from '@material-ui/core'
import { toast } from 'react-toastify'
import { useTranslation } from 'react-i18next'
import { hideLoading, showLoading } from 'app/redux/actions/loadingAction'
import { connect } from 'react-redux'
function FormDialog(props) {
import { toast } from 'react-toastify'
import { useTranslation } from 'react-i18next'
import { hideLoading, showLoading } from 'app/redux/actions/loadingAction'
import { connect } from 'react-redux'
function FormDialog(props) {
const { t } = useTranslation()
const { open, handleClose, data, onAgree } = props
const {open,handleClose,data,onAgree}=props
const [amount,setamount]=useState()
const [name, setName] = useState()
return (
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Cập nhật CTV</DialogTitle>
<DialogTitle id="form-dialog-title">Thêm trụ xăng</DialogTitle>
<DialogContent>
<TextField
style={{marginBttom:20,minWidth:400}}
style={{ marginBttom: 20, minWidth: 400 }}
variant="outlined"
autoFocus
margin="dense"
label="Lời nhuận chia sẻ %"
label="Tên trụ *"
fullWidth
value={amount || ''}
onChange={(event)=>setamount(event.target.value)}
value={name || ''}
onChange={(event) => setName(event.target.value)}
/>
</DialogContent>
<DialogActions>
<Button
color="secondary"
onClick={handleClose}
>
<Button color="secondary" onClick={handleClose}>
Thoát
</Button>
<Button onClick={onAgree} color="primary">
<Button onClick={()=>{
onAgree(name)
setName('')
}} color="primary">
Đồng ý
</Button>
</DialogActions>
</Dialog>
)
}
const mapStateToProps = (state) => {
return {}
}
......
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({ onCreate }) {
const [open, setOpen] = React.useState(false)
const { t } = useTranslation()
const [state, setState] = useState({})
const [listType, setListType] = useState([])
const [listProduct, setListProduct] = useState([])
const [product,setProduct]=useState()
const [type, setType] = useState()
useEffect(()=>{
setProduct()
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',
})
}
}
function handleClickOpen() {
setOpen(true)
}
function handleClose() {
setOpen(false)
}
const handleSubmit = async (value) => {
console.log('state', state)
onCreate({...state,type})
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const { product_id, name, code } = state
return (
<>
<Tooltip title="Chuyển tiền đáo hạn">
<IconButton onClick={handleClickOpen}>
<Icon style={{ color: '#4caf50' }}>add_circle</Icon>
</IconButton>
</Tooltip>
<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"
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>
<Grid item lg={12} md={12} sm={12} xs={12}>
<TextValidator
className="mb-4 w-full"
label="Mã vòi xăng *"
onChange={handleChange}
variant="outlined"
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}>
<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>
<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>
</>
)
}
......@@ -13,7 +13,7 @@ import {
Icon,
Tooltip,
} from '@material-ui/core'
import _ from 'lodash'
import { createFunction } from 'app/apis/Functions/function'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
......@@ -30,44 +30,14 @@ 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'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const history = useHistory()
const [listDrop, setListDrop] = useState([])
const [listField, setListField] = useState([
{
field_name: 'Trụ 1',
gas_olines: [
{
product_id: 'BDDD46BC-2264-43EF-21B7-08DC08411423',
name: 'Vòi 1',
code: 'A95',
},
{
product_id: '6D3A81A6-A189-4D83-BA47-08DC0CF4D4C3',
name: 'Vòi 2',
code: 'A99',
},
],
},
{
field_name: 'Trụ 2',
gas_olines: [
{
product_id: 'BDDD46BC-2264-43EF-21B7-08DC08411423',
name: 'Vòi 1',
code: 'A95',
},
{
product_id: '6D3A81A6-A189-4D83-BA47-08DC0CF4D4C3',
name: 'Vòi 2',
code: 'A99',
},
],
},
])
const [openCreate, setOpenCreate] = useState(false)
const [listField, setListField] = useState([])
useEffect(() => {
getData()
......@@ -128,13 +98,81 @@ const SimpleForm = (props) => {
setState({ ...state, date })
}
const onCreateField = () => {}
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) {
return {
...e,
gas_olines: [
{
...data,
},
].concat(e.gas_olines),
}
} else {
return {
...e,
gas_olines: [
{
...data,
},
],
}
}
} else return { ...e }
})
console.log('newList', newList)
setListField(newList)
}
const handleCloseCreate = () => {
setOpenCreate(false)
}
const { store_name, address, merchan_id } = state
console.log('listField', listField)
return (
<div className="m-sm-30">
<div className="mb-sm-30">
......@@ -150,7 +188,11 @@ const SimpleForm = (props) => {
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<ValidatorForm
id="form-create"
onSubmit={handleSubmit}
onError={() => null}
>
<Grid container spacing={3}>
<Grid xs={6} sm={6} item>
<SelectValidator
......@@ -248,7 +290,8 @@ const SimpleForm = (props) => {
>
<div>
<Typography variant="subtitle1">
S lượng vòi mi tr:1
S lượng vòi mi tr:{' '}
{listField.length}
</Typography>
<Typography variant="subtitle1">
S lượng tr:3
......@@ -256,18 +299,21 @@ const SimpleForm = (props) => {
</div>
<Button
style={{
width: 120,
width: 140,
}}
onClick={() => {
setOpenCreate(true)
}}
variant="contained"
className={'bg-light-primary'}
>
<span className={'text-primary'}>
Thêm mi
Thêm mi tr
</span>
</Button>
</Grid>
{listField.map((item) => (
{listField.map((item, index) => (
<Grid
style={{
border: '1px solid #B9B9B9',
......@@ -294,6 +340,9 @@ const SimpleForm = (props) => {
{item.field_name}
</Typography>
<Button
onClick={() => {
deletePillar(index)
}}
variant="contained"
style={{
backgroundColor:
......@@ -360,10 +409,10 @@ const SimpleForm = (props) => {
>
Sn phm
</TableCell>
<TableCell align="center">
{/* <TableCell align="center">
Trạng thái hoạt
động
</TableCell>
</TableCell> */}
<TableCell
style={{
textAlign:
......@@ -441,7 +490,7 @@ const SimpleForm = (props) => {
row?.product_name
}
</TableCell>
<TableCell
{/* <TableCell
style={{
borderRight:
'0.05px solid #e0e0e0',
......@@ -451,7 +500,7 @@ const SimpleForm = (props) => {
{
row?.status
}
</TableCell>
</TableCell> */}
<TableCell>
<Tooltip title="Xoá">
......@@ -483,14 +532,11 @@ const SimpleForm = (props) => {
</TableBody>
</Table>
</TableContainer>
<IconButton
onClick={() => {}}
aria-label="edit"
>
<Icon color="primary">
add_circle
</Icon>
</IconButton>
<CreateFountain
onCreate={(data) => {
createFountain(data, index)
}}
/>
</Grid>
</Grid>
))}
......
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