浏览代码

props values

amenpunk 2 年之前
父节点
当前提交
5e81e88796
共有 1 个文件被更改,包括 116 次插入92 次删除
  1. 116 92
      src/Components/Password/Operation.jsx

+ 116 - 92
src/Components/Password/Operation.jsx

2
 
2
 
3
 import { Edit as EditIcon, Send as SendIcon } from '@mui/icons-material'
3
 import { Edit as EditIcon, Send as SendIcon } from '@mui/icons-material'
4
 import {
4
 import {
5
-    Button, Dialog, DialogActions, DialogContent,
6
-    DialogContentText, DialogTitle
5
+    Button, Dialog, DialogActions, DialogContent, DialogTitle,
6
+    FormControlLabel, Checkbox,
7
+    Autocomplete, TextField, Stack,
7
 } from '@mui/material'
8
 } from '@mui/material'
8
 
9
 
9
 import * as Yup from 'yup';
10
 import * as Yup from 'yup';
14
 
15
 
15
 import { useFormik, Form, FormikProvider } from 'formik';
16
 import { useFormik, Form, FormikProvider } from 'formik';
16
 
17
 
17
-import { Stack, TextField } from '@mui/material';
18
-
19
 import DateFnsUtils from '@date-io/date-fns';
18
 import DateFnsUtils from '@date-io/date-fns';
20
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
19
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
21
 
20
 
47
 function ModalEdit(props) {
46
 function ModalEdit(props) {
48
 
47
 
49
     let { password, open, handleOpen } = props
48
     let { password, open, handleOpen } = props
49
+    const now = React.useRef(new Date());
50
     let { pwd, plz } = password
50
     let { pwd, plz } = password
51
     const auth = useAuth();
51
     const auth = useAuth();
52
     const token = React.useRef(auth.getToken());
52
     const token = React.useRef(auth.getToken());
60
     let initialValues = {
60
     let initialValues = {
61
         id: result?.data?.id,
61
         id: result?.data?.id,
62
         pwd: result?.data?.pwd,
62
         pwd: result?.data?.pwd,
63
-        deadpwd: result?.data?.deadpwd,
63
+        deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
64
         state: result?.data?.state,
64
         state: result?.data?.state,
65
-        dateToActived: result?.data?.dateToActived,
65
+        dateToActived: 
66
+        result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
66
         plaza_id: result?.data?.plaza_id,
67
         plaza_id: result?.data?.plaza_id,
67
     }
68
     }
68
 
69
 
77
                 {pwd}
78
                 {pwd}
78
             </DialogTitle>
79
             </DialogTitle>
79
             <DialogContent>
80
             <DialogContent>
80
-                <DialogContentText id="alert-dialog-description">
81
-                    <ModalForm initialValues={initialValues} />
82
-                </DialogContentText>
81
+                <ModalForm initialValues={initialValues} />
83
             </DialogContent>
82
             </DialogContent>
84
             <DialogActions>
83
             <DialogActions>
85
                 <Button onClick={() => handleOpen(false)} autoFocus>
84
                 <Button onClick={() => handleOpen(false)} autoFocus>
92
 }
91
 }
93
 
92
 
94
 function ModalForm(props) {
93
 function ModalForm(props) {
95
-    console.log("PROPS >> ", props)
94
+
95
+    const auth = useAuth();
96
+    const token = auth.getToken();
97
+
98
+    const getPuestos = async () => {
99
+        let rest = new Service('/plaza/getall')
100
+        return rest.getQuery(token);
101
+    }
102
+
103
+    let { data } = useQuery('puestos', getPuestos)
104
+    let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
105
+    // console.log('puestos: ', puestos)
96
 
106
 
97
     const pwdSchema = Yup.object().shape({
107
     const pwdSchema = Yup.object().shape({
98
         id: Yup.number(),
108
         id: Yup.number(),
113
     })
123
     })
114
 
124
 
115
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
125
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
116
-    console.log('formik values >> ', values )
126
+
127
+    React.useEffect(() =>{
128
+        setValues({ ...props.initialValues})
129
+    },[props, setValues] )
117
 
130
 
118
     return (
131
     return (
119
-        <FormikProvider  value={formik}>
120
-            <Form style={{padding : 15,minWidth:450}} autoComplete="off" noValidate onSubmit={handleSubmit}>
132
+        <FormikProvider value={formik}>
133
+            <Form style={{ padding: 15, minWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
121
                 <Stack spacing={4}>
134
                 <Stack spacing={4}>
122
 
135
 
123
-                    <TextField
124
-                        fullWidth
125
-                        type="text"
126
-                        label="Nombre o identificador"
127
-                        {...getFieldProps('pwd')}
128
-                        error={Boolean(touched.pwd && errors.pwd)}
129
-                        helperText={touched.pwd && errors.pwd}
130
-                    />
131
-                    
132
-
133
-                    <TextField
134
-                        fullWidth
135
-                        type="text"
136
-                        label="Nombre o identificador"
137
-                        {...getFieldProps('pwd')}
138
-                        error={Boolean(touched.pwd && errors.pwd)}
139
-                        helperText={touched.pwd && errors.pwd}
140
-                    />
141
-
142
-                    <TextField
143
-                        fullWidth
144
-                        type="text"
145
-                        label="Nombre o identificador"
146
-                        {...getFieldProps('pwd')}
147
-                        error={Boolean(touched.pwd && errors.pwd)}
148
-                        helperText={touched.pwd && errors.pwd}
149
-                    />
150
-                    
151
-                    <TextField
152
-                        fullWidth
153
-                        type="text"
154
-                        label="Nombre o identificador"
155
-                        {...getFieldProps('pwd')}
156
-                        error={Boolean(touched.pwd && errors.pwd)}
157
-                        helperText={touched.pwd && errors.pwd}
158
-                    />
159
-
160
-                        <LocalizationProvider
161
-                            dateAdapter={DateFnsUtils}>
162
-                            <DesktopDatePicker
163
-                                label="Fecha de Activación"
164
-                                fullWidth
165
-                                inputFormat="dd/MM/yyyy"
166
-                                {...getFieldProps('dateToActived')}
167
-                                value={values.dateToActived}
168
-                                onChange={(val) => setValues({ ...values, dateToActived: new Date(val) })
169
-                                }
170
-                                renderInput={(params) =>
171
-                                    <TextField
172
-                                        error={Boolean(touched.dateToActived && errors.dateToActived)}
173
-                                        helperText={touched.dateToActived && errors.dateToActived}
174
-                                        disabled={true}
175
-                                        label="Fecha de Activación"
176
-                                        fullWidth
177
-                                        {...params}
178
-                                        />}
179
-                                />
180
-                        </LocalizationProvider>
181
-
182
-                        <LocalizationProvider
183
-                            dateAdapter={DateFnsUtils}>
184
-                            <DesktopDatePicker
185
-                                label="Fecha de Vencimiento"
186
-                                fullWidth
187
-                                inputFormat="dd/MM/yyyy"
188
-                                {...getFieldProps('deadpwd')}
189
-                                value={values.deadpwd}
190
-                                onChange={(val) => setValues({ ...values, deadpwd: new Date(val) })
191
-                                }
192
-                                renderInput={(params) =>
193
-                                    <TextField
194
-                                        error={Boolean(touched.deadpwd && errors.deadpwd)}
195
-                                        helperText={touched.deadpwd && errors.deadpwd}
196
-                                        disabled={true}
197
-                                        label="Fecha de Vencimiento"
198
-                                        fullWidth
199
-                                        {...params}
200
-                                        />}
136
+                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
137
+                        <TextField
138
+                            focused
139
+                            fullWidth
140
+                            type="text"
141
+                            label="Contraseña"
142
+                            {...getFieldProps('pwd')}
143
+                            error={Boolean(touched.pwd && errors.pwd)}
144
+                            helperText={touched.pwd && errors.pwd}
145
+                        />
146
+
147
+                        <FormControlLabel
148
+                            control={
149
+                                <Checkbox
150
+                                checked={values.state  === 1 }
151
+                                onChange={(event)=>{
152
+                                    let check = event.target.checked;
153
+                                    setValues({
154
+                                        state : check ? 1:0
155
+                                    })
156
+                                }}
201
                                 />
157
                                 />
202
-                        </LocalizationProvider>
158
+                            }
159
+                            label="Activa"
160
+                        />
161
+
162
+                    </Stack>
163
+
164
+
165
+                    <LocalizationProvider
166
+                        dateAdapter={DateFnsUtils}>
167
+                        <DesktopDatePicker
168
+                            label="Fecha de Activación"
169
+                            fullWidth
170
+                            inputFormat="dd/MM/yyyy"
171
+                            {...getFieldProps('dateToActived')}
172
+                            value={values.dateToActived}
173
+                            onChange={(val) => setValues({ ...values, dateToActived: new Date(val) })
174
+                            }
175
+                            renderInput={(params) =>
176
+                                <TextField
177
+                                    error={Boolean(touched.dateToActived && errors.dateToActived)}
178
+                                    helperText={touched.dateToActived && errors.dateToActived}
179
+                                    disabled={true}
180
+                                    label="Fecha de Activación"
181
+                                    fullWidth
182
+                                    {...params}
183
+                                />}
184
+                        />
185
+                    </LocalizationProvider>
186
+
187
+                    <LocalizationProvider
188
+                        dateAdapter={DateFnsUtils}>
189
+                        <DesktopDatePicker
190
+                            label="Fecha de Vencimiento"
191
+                            fullWidth
192
+                            inputFormat="dd/MM/yyyy"
193
+                            {...getFieldProps('deadpwd')}
194
+                            value={values.deadpwd}
195
+                            onChange={(val) => setValues({ ...values, deadpwd: new Date(val) })
196
+                            }
197
+                            renderInput={(params) =>
198
+                                <TextField
199
+                                    error={Boolean(touched.deadpwd && errors.deadpwd)}
200
+                                    helperText={touched.deadpwd && errors.deadpwd}
201
+                                    disabled={true}
202
+                                    label="Fecha de Vencimiento"
203
+                                    fullWidth
204
+                                    {...params}
205
+                                />}
206
+                        />
207
+                    </LocalizationProvider>
208
+
209
+                    <Autocomplete
210
+                        error={Boolean(touched.plaza_id && errors.plaza_id)}
211
+                        helperText={touched.plaza_id && errors.plaza_id}
212
+                        autoHighlight={true}
213
+                        id="combo-box-demo"
214
+                        options={puestos}
215
+                        isOptionEqualToValue={(option, value) => option.nombrepuesto === value.nombrepuesto}
216
+                        getOptionLabel={(option) => {
217
+                            return option.nombrepuesto
218
+                        }}
219
+                        renderInput={(params) =>
220
+                            <TextField
221
+                                {...params}
222
+                                label="Puesto"
223
+                                {...getFieldProps('plaza_id')}
224
+                            />
225
+                        }
226
+                    />
203
 
227
 
204
 
228
 
205
                 </Stack>
229
                 </Stack>