diff --git a/src/pages/shared/MyApproval.jsx b/src/pages/shared/MyApproval.jsx index 6ae629b..7e2acec 100644 --- a/src/pages/shared/MyApproval.jsx +++ b/src/pages/shared/MyApproval.jsx @@ -1,10 +1,11 @@ -import { Button, Form, Input, Table, Tag } from "antd"; +import { Button, DatePicker, Form, Input, message, Table, Tag } from "antd"; import { useForm } from "antd/es/form/Form"; import Column from "antd/es/table/Column"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; import axiosInstance from "../../api/axios"; -import { selectUserId } from "../../features/auth/authSlice"; +import { selectUserId, selectUserRole } from "../../features/auth/authSlice"; +import dayjs from "dayjs"; export default function MyApproval() { const [approvals, setApprovals] = useState([]); @@ -14,8 +15,11 @@ export default function MyApproval() { pageSize: 10, total: 0, }); + const [editingRow, setEditingRow] = useState(null); + const [tempEndTime, setTempEndTime] = useState(null); const userId = useSelector(selectUserId); + const userRole = useSelector(selectUserRole); const fetchData = async (pagination, searchParam) => { const data = await axiosInstance.get(`/approval/${userId}`, { @@ -53,6 +57,20 @@ export default function MyApproval() { await fetchData(newPagination, values); }; + const handleSubmit = async (record) => { + try { + await axiosInstance.post(`/reservation/endTime/${record.reservationId}`, { + endTime: dayjs(tempEndTime).format("YYYY-MM-DD"), + }); + const values = await form.validateFields(); + await fetchData(pagination, values); + setEditingRow(null); + message.success("修改成功"); + } catch (error) { + message.error("修改失败"); + } + }; + return (
@@ -88,7 +106,57 @@ export default function MyApproval() { /> - + { + const isEditable = + record.decision === 1 && userRole.includes("DEVICE_ADMIN"); + + if (editingRow === record.approvalId) { + return ( +
+ setTempEndTime(date)} + disabledDate={(current) => + current && + current.isBefore(dayjs(record.startTime), "day") + } + size="small" + /> + + +
+ ); + } + + return isEditable ? ( + + {record.endTime} + + + ) : ( + {record.endTime} + ); + }} + />