修复删除
This commit is contained in:
@@ -68,8 +68,6 @@ const orderStatusConfig = {
|
||||
5: { label: '处理中', textColor: '#722ed1' }
|
||||
};
|
||||
|
||||
|
||||
|
||||
const WorkOrderPage = () => {
|
||||
const [activeTab, setActiveTab] = useState('1');
|
||||
const [selectedRowKey, setSelectedRowKey] = useState('');
|
||||
@@ -78,27 +76,25 @@ const WorkOrderPage = () => {
|
||||
const [workOrderList, setWorkOrderList] = useState([]);
|
||||
const [workOrderTotal, setWorkOrderTotal] = useState(0);
|
||||
const [currentDetail, setCurrentDetail] = useState(null);
|
||||
const [userList, setUserList] = useState([]); // 用户列表
|
||||
const [userList, setUserList] = useState([]);
|
||||
|
||||
// 从 redux 获取用户信息
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
|
||||
// 判断是否为管理员 (具有 admin 角色或 roleLevel 为 1)
|
||||
// 判断是否为管理员
|
||||
const isAdmin = true;
|
||||
|
||||
// 弹窗表单
|
||||
const [form] = Form.useForm();
|
||||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||||
const [dispatchModalVisible, setDispatchModalVisible] = useState(false);
|
||||
|
||||
const [completeModalVisible, setCompleteModalVisible] = useState(false);
|
||||
const [completeForm] = Form.useForm(); // 完成工单表单
|
||||
const messageApi = utils.message; // 使用全局 message
|
||||
const [completeForm] = Form.useForm();
|
||||
const messageApi = utils.message;
|
||||
|
||||
// 获取用户列表 (用于负责人选择)
|
||||
// 获取用户列表
|
||||
const fetchUserList = async () => {
|
||||
try {
|
||||
|
||||
const res: any = await getUser({
|
||||
pageNum: 1, pageSize: 10000, orgId: userInfo?.orgId,
|
||||
siteId: userInfo?.siteId,
|
||||
@@ -148,7 +144,7 @@ const WorkOrderPage = () => {
|
||||
if (res.code == 0) {
|
||||
setWorkOrderList(res.rows || []);
|
||||
setWorkOrderTotal(res.total || 0);
|
||||
if (res.rows && res.rows.length > 0) {
|
||||
if (res.rows?.length > 0) {
|
||||
setSelectedRowKey(res.rows[0].id);
|
||||
getWorkOrderDetail(res.rows[0].id);
|
||||
}
|
||||
@@ -172,11 +168,17 @@ const WorkOrderPage = () => {
|
||||
setCompleteModalVisible(true);
|
||||
};
|
||||
|
||||
// 提交完成工单
|
||||
// 提交完成工单(参数完全对齐你的JSON)
|
||||
const submitComplete = async (values) => {
|
||||
try {
|
||||
const now = dayjs().format('YYYY-MM-DDTHH:mm:ss');
|
||||
const params = {
|
||||
...currentDetail,
|
||||
id: values.id,
|
||||
orderNo: currentDetail?.orderNo,
|
||||
orderStatus: 4, // 已完成
|
||||
actualStartTime: currentDetail?.actualStartTime || now,
|
||||
actualEndTime: now,
|
||||
handleResult: values.handleResult,
|
||||
handleRemark: values.handleRemark,
|
||||
};
|
||||
@@ -228,11 +230,10 @@ const WorkOrderPage = () => {
|
||||
if (!selectedRowKey) return messageApi.warning('请先选择一条工单');
|
||||
if (!isAdmin) return messageApi.error('只有管理员才可以派发工单');
|
||||
|
||||
fetchUserList(); // 获取可选负责人列表
|
||||
|
||||
fetchUserList();
|
||||
form.setFieldsValue({
|
||||
orderId: selectedRowKey,
|
||||
assigneeId: currentDetail?.assigneeId || "",
|
||||
assigneeId: currentDetail?.assigneeId ?? '',
|
||||
assigneeName: currentDetail?.assigneeName || '',
|
||||
planStartTime: currentDetail?.planStartTime ? dayjs(currentDetail.planStartTime) : null,
|
||||
planEndTime: currentDetail?.planEndTime ? dayjs(currentDetail.planEndTime) : null,
|
||||
@@ -245,36 +246,12 @@ const WorkOrderPage = () => {
|
||||
const submitEdit = async (values) => {
|
||||
try {
|
||||
const params = {
|
||||
...currentDetail,
|
||||
id: selectedRowKey,
|
||||
orderNo: currentDetail?.orderNo,
|
||||
orderTitle: values.orderTitle,
|
||||
sourceType: currentDetail?.sourceType,
|
||||
orderType: values.orderType,
|
||||
priorityLevel: values.priorityLevel,
|
||||
deviceId: currentDetail?.deviceId,
|
||||
deviceName: currentDetail?.deviceName,
|
||||
deviceType: currentDetail?.deviceType,
|
||||
siteId: currentDetail?.siteId,
|
||||
siteName: currentDetail?.siteName,
|
||||
orgId: currentDetail?.orgId,
|
||||
assigneeId: currentDetail?.assigneeId,
|
||||
assigneeName: currentDetail?.assigneeName,
|
||||
collaboratorIds: currentDetail?.collaboratorIds,
|
||||
collaboratorNames: currentDetail?.collaboratorNames,
|
||||
planStartTime: currentDetail?.planStartTime,
|
||||
planEndTime: currentDetail?.planEndTime,
|
||||
deadlineTime: currentDetail?.deadlineTime,
|
||||
actualStartTime: currentDetail?.actualStartTime,
|
||||
actualEndTime: currentDetail?.actualEndTime,
|
||||
orderStatus: currentDetail?.orderStatus,
|
||||
alarmId: currentDetail?.alarmId,
|
||||
alarmNo: currentDetail?.alarmNo,
|
||||
taskDescription: values.taskDescription,
|
||||
aiSuggestion: currentDetail?.aiSuggestion,
|
||||
requiredEquipment: currentDetail?.requiredEquipment,
|
||||
estimatedImpact: currentDetail?.estimatedImpact,
|
||||
handleResult: currentDetail?.handleResult,
|
||||
handleRemark: currentDetail?.handleRemark,
|
||||
};
|
||||
await updateWorkOrder(params);
|
||||
messageApi.success('修改工单成功');
|
||||
@@ -296,9 +273,9 @@ const WorkOrderPage = () => {
|
||||
assigneeName: values.assigneeName,
|
||||
collaboratorIds: '',
|
||||
collaboratorNames: values.collaboratorNames?.join(',') || '',
|
||||
planStartTime: values.planStartTime ? values.planStartTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
planEndTime: values.planEndTime ? values.planEndTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
deadlineTime: values.deadlineTime ? values.deadlineTime.format('YYYY-MM-DDTHH:mm:ss') : '',
|
||||
planStartTime: values.planStartTime?.format('YYYY-MM-DDTHH:mm:ss') || '',
|
||||
planEndTime: values.planEndTime?.format('YYYY-MM-DDTHH:mm:ss') || '',
|
||||
deadlineTime: values.deadlineTime?.format('YYYY-MM-DDTHH:mm:ss') || '',
|
||||
};
|
||||
await dispatchWorkOrder(params);
|
||||
messageApi.success('工单派发成功');
|
||||
@@ -322,15 +299,16 @@ const WorkOrderPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 删除工单
|
||||
const handleDelete = async () => {
|
||||
if (!selectedRowKey) return messageApi.warning('请选择工单');
|
||||
// 删除工单(修复版:删除当前行)
|
||||
const handleDelete = async (record) => {
|
||||
if (!record?.id) return messageApi.warning('无效工单');
|
||||
try {
|
||||
await deleteWorkOrder(selectedRowKey);
|
||||
await deleteWorkOrder(record.id);
|
||||
messageApi.success('删除成功');
|
||||
getWorkOrderList();
|
||||
} catch (e) {
|
||||
messageApi.error('删除失败');
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -345,7 +323,7 @@ const WorkOrderPage = () => {
|
||||
overflow: 'hidden'
|
||||
};
|
||||
|
||||
// 表格列【已完善】
|
||||
// 表格列
|
||||
const columns = [
|
||||
{ title: '工单编号', dataIndex: 'orderNo', key: 'orderNo', width: 150 },
|
||||
{ title: '工单标题', dataIndex: 'orderTitle', key: 'orderTitle', width: 200, ellipsis: true },
|
||||
@@ -354,10 +332,7 @@ const WorkOrderPage = () => {
|
||||
dataIndex: 'sourceType',
|
||||
key: 'sourceType',
|
||||
width: 90,
|
||||
render: (t) => {
|
||||
const map = { 1: 'AI', 2: '无人机', 3: '清洗', 4: '视频', 5: '装备', 6: '人工', 7: '告警' };
|
||||
return map[t] || t;
|
||||
}
|
||||
render: (t) => sourceTypeMap[t] || t
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
@@ -402,7 +377,8 @@ const WorkOrderPage = () => {
|
||||
<Space size={4}>
|
||||
<Button type="link" size="small" onClick={() => { setSelectedRowKey(record.id); getWorkOrderDetail(record.id); }}>查看</Button>
|
||||
<Button type="link" size="small" onClick={() => { setSelectedRowKey(record.id); getWorkOrderDetail(record.id); openEditModal(); }}>修改</Button>
|
||||
<Popconfirm title="确定删除?" onConfirm={handleDelete}><Button type="link" size="small" danger>删除</Button></Popconfirm>
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record)}
|
||||
><Button type="link" size="small" danger>删除</Button></Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
@@ -584,7 +560,13 @@ const WorkOrderPage = () => {
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>工单类型:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{orderTypeConfig[currentDetail?.orderType] || '--'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>负责人:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.assigneeName || '--'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>协同人员:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.collaboratorNames || '无'}</span></Col>
|
||||
<Col span={24}><span style={{ fontSize: 12 }}>计划时间:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.planStartTime ? `${currentDetail.planStartTime} ~ ${currentDetail.planEndTime}` : '--'}</span></Col>
|
||||
<Col span={24}><span style={{ fontSize: 12 }}>计划时间:</span>
|
||||
<span style={{ fontSize: 12, fontWeight: 500 }}>
|
||||
{currentDetail?.planStartTime && currentDetail?.planEndTime
|
||||
? `${dayjs(currentDetail.planStartTime).format('YYYY-MM-DD HH:mm')} ~ ${dayjs(currentDetail.planEndTime).format('YYYY-MM-DD HH:mm')}`
|
||||
: '--'}
|
||||
</span>
|
||||
</Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>关联设备:</span><span style={{ fontSize: 12, color: '#165DFF', fontWeight: 600 }}>{currentDetail?.deviceName || '无'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>关联区域:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.siteName || '无'}</span></Col>
|
||||
<Col span={24}>
|
||||
|
||||
Reference in New Issue
Block a user