// material-ui import { Dialog, DialogTitle, DialogContent, DialogActions, Typography, Grid, Stack, TextField, FormLabel, Button, RadioGroup, Radio, FormControlLabel } from '@mui/material'; import * as UrlUtils from "utils/ApiPathConst"; import * as HttpUtils from "utils/HttpUtils"; import FileList from "components/FileList" import MainCard from "components/MainCard"; import * as React from "react"; import * as yup from 'yup'; import { useParams } from "react-router-dom"; import { useFormik } from 'formik'; import { useNavigate } from "react-router-dom"; import * as DateUtils from "utils/DateUtils" import Loadable from 'components/Loadable'; import { notifyActionSuccess } from 'utils/CommonFunction'; const UploadFileTable = Loadable(React.lazy(() => import('./UploadFileTable'))); // ==============================|| DASHBOARD - DEFAULT ||============================== // const FormPanel = ({ formData }) => { const [data, setData] = React.useState({}); const [attachments, setAttachments] = React.useState([]); const [actionValue, setActionValue] = React.useState(true); const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); const [warningText, setWarningText] = React.useState(""); const navigate = useNavigate() const params = useParams(); React.useEffect(() => { if (formData) { setData(formData); } }, [formData]); const formik = useFormik({ enableReinitialize: true, initialValues: data, validationSchema: yup.object().shape({ vaild: yup.string().max(255, "請輸入你的登入密碼").required('請輸入你的登入密碼'), }), onSubmit: values => { if (!actionValue) { if (!attachments || attachments.length <= 0) { setWarningText("請選擇上傳檔案"); setIsWarningPopUp(true); return; } } if (isOverTime()) { setWarningText("回覆逾時,請重新申請。"); setIsWarningPopUp(true); return; } // console.log(values); HttpUtils.postWithFiles({ url: UrlUtils.REPLY_PROOF, params: { id: data.id, action: actionValue, vaild: values.vaild, }, files: attachments ? attachments : [], onSuccess: function () { if (actionValue) { notifyActionSuccess("提交成功!") navigate("/proof/pay/"+params.id); } else { notifyActionSuccess("提交成功!") navigate("/proof/search"); } }, onFail: function (response) { setWarningText("行動失敗: 請檢查內容並再次提交回覆"); setIsWarningPopUp(true); console.log(response); }, onError: function (error) { setWarningText("行動失敗: 請檢查內容並再次提交回覆"); setIsWarningPopUp(true); console.log(error); } }); } }); const readFile = (event) => { let file = event.target.files[0]; if (file) { if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) { setWarningText("請上傳有效檔案 (檔案格式: .pdf)"); setIsWarningPopUp(true); document.getElementById("uploadFileBtn").value = ""; return; } if (file.size >= (10 * 1024 * 1034)) { setWarningText("上傳檔案大小應<10MB"); setIsWarningPopUp(true); return; } file['id'] = attachments.length; setAttachments([ ...attachments, file ]); document.getElementById("uploadFileBtn").value = ""; } } const isOverTime = () => { let returnBeforeDate = DateUtils.convertToDate(formik.values?.returnBeforeDate); if (!returnBeforeDate) return true; returnBeforeDate = returnBeforeDate.setHours(14, 0, 0, 0); let current = new Date(); return current.getTime() > returnBeforeDate; } return ( 公共啟事:校對回覆
{ formik.values.replyDate ? 校對回覆日期: {DateUtils.datetimeStr_Cht(formik.values.replyDate)} 校對回覆: {formik.values.action ? (可以付印(稿件正確)): (未能付印(需要修改))} { formik.values.action ? null : } : ( isOverTime() ? 回覆逾時,請重新申請。 : { setActionValue(event.target.value == "true" ? true : false); }} > } label="可以付印(稿件正確)" /> } label="未能付印(需要修改)" /> { actionValue ? null : <> 請上載稿件修改的檔案: = (formik.values.groupType == "A" ? 2 : 1)} onChange={(event) => { readFile(event) }} /> } 簽署: ) }
setIsWarningPopUp(false)} > 注意 {warningText}
); }; export default FormPanel;