2024-05-30 22:56:18 -04:00
|
|
|
import {PlusOutlined, QuestionCircleOutlined} from '@ant-design/icons';
|
2024-04-19 05:44:44 -04:00
|
|
|
import {
|
|
|
|
ModalForm,
|
|
|
|
ProForm,
|
2024-04-25 04:36:40 -04:00
|
|
|
ProFormDateRangePicker, ProFormDateTimeRangePicker,
|
2024-04-19 05:44:44 -04:00
|
|
|
ProFormSelect,
|
2024-04-24 01:54:59 -04:00
|
|
|
ProFormText, ProFormTextArea, ProFormTreeSelect,
|
2024-04-19 05:44:44 -04:00
|
|
|
} from '@ant-design/pro-components';
|
2024-05-30 22:56:18 -04:00
|
|
|
import {Button, Form, message, Popconfirm} from 'antd';
|
2024-05-29 04:44:23 -04:00
|
|
|
import React, {useEffect, useState} from "react";
|
2024-04-25 04:36:40 -04:00
|
|
|
import {
|
2024-05-30 22:56:18 -04:00
|
|
|
addTask, deleteTask, getTask,
|
2024-04-25 04:36:40 -04:00
|
|
|
getTaskTreeResult,
|
|
|
|
OPERATION_BUTTON_TYPE,
|
|
|
|
taskPriorityList,
|
2024-05-30 22:56:18 -04:00
|
|
|
taskStateList, updateTask
|
2024-05-10 04:00:35 -04:00
|
|
|
} from "@/lib/task/project/data";
|
|
|
|
import {DataType} from "@/lib/definitions";
|
2024-05-29 04:44:23 -04:00
|
|
|
import dayjs, {Dayjs} from "dayjs";
|
2024-04-19 05:44:44 -04:00
|
|
|
|
|
|
|
export type DetailModelFormProps={
|
2024-05-29 04:44:23 -04:00
|
|
|
// 当前内容id
|
2024-04-19 05:44:44 -04:00
|
|
|
itemId?: number,
|
2024-05-30 22:56:18 -04:00
|
|
|
pid?:number,
|
|
|
|
// 祖宗任务id
|
2024-04-19 05:44:44 -04:00
|
|
|
pPid?:number,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 操作id
|
2024-04-19 05:44:44 -04:00
|
|
|
operationId: number,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 标题描述
|
2024-04-19 05:44:44 -04:00
|
|
|
description:string,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 是否打开界面,用于非按钮操作
|
|
|
|
open:boolean,
|
|
|
|
// 使用按钮操作
|
|
|
|
haveButton:boolean,
|
|
|
|
expectedStartTime?:Dayjs,
|
|
|
|
expectedEndTime?:Dayjs,
|
|
|
|
// 重新加载数据
|
2024-04-25 04:36:40 -04:00
|
|
|
reloadData?: () => void
|
2024-04-19 05:44:44 -04:00
|
|
|
}
|
2024-05-30 22:56:18 -04:00
|
|
|
export type PidSelectTree= { label: string; value: number;pid:number; children?: PidSelectTree[] }
|
2024-05-29 04:44:23 -04:00
|
|
|
|
2024-04-19 05:44:44 -04:00
|
|
|
export const DetailModelForm: React.FC<DetailModelFormProps> = (props) => {
|
2024-06-03 06:39:42 -04:00
|
|
|
console.log("DetailModelForm:props:",props)
|
2024-04-24 01:54:59 -04:00
|
|
|
const [form] = Form.useForm<DataType>();
|
2024-05-30 22:56:18 -04:00
|
|
|
const [pid, setPid] = useState<number>(props.pid?props.pid:0);
|
|
|
|
const [editFormDisable, setEditFormDisable] = useState(props.operationId === OPERATION_BUTTON_TYPE.DETAIL)
|
2024-05-29 04:44:23 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (props.itemId!=undefined&&(
|
|
|
|
props.operationId === OPERATION_BUTTON_TYPE.DETAIL || props.operationId === OPERATION_BUTTON_TYPE.UPDATE)) {
|
|
|
|
getTask(props.itemId).then(task => {
|
|
|
|
console.log('DetailModelForm:getTask(props.itemId)', props.itemId, task);
|
|
|
|
if (task.status.success) {
|
|
|
|
// setTaskMessage(task.data)
|
|
|
|
task.data.state = taskStateList.find(taskState => taskState.code === task.data.state?.toString())?.name;
|
|
|
|
task.data.priority = taskPriorityList.find(taskPriority => taskPriority.code === task.data.priority?.toString())?.name;
|
|
|
|
task.data.actualTimeRange = [task.data.actualStartTime ? dayjs(task.data.actualStartTime) : undefined,
|
|
|
|
task.data.actualEndTime ? dayjs(task.data.actualEndTime) : undefined];
|
|
|
|
task.data.expectedTimeRange = [task.data.expectedStartTime ? dayjs(task.data.expectedStartTime) : undefined,
|
|
|
|
task.data.expectedEndTime ? dayjs(task.data.expectedEndTime) : undefined];
|
|
|
|
form.setFieldsValue(task.data)
|
|
|
|
} else {
|
|
|
|
message.error(task.status.message);
|
|
|
|
props.reloadData?.()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}else if(props.operationId === OPERATION_BUTTON_TYPE.ADD|| props.operationId === OPERATION_BUTTON_TYPE.ADD_CHILD){
|
2024-05-30 22:56:18 -04:00
|
|
|
let data={'expectedTimeRange':[props.expectedStartTime?props.expectedStartTime:dayjs(), props.expectedEndTime],'pid':props.pid};
|
2024-05-29 04:44:23 -04:00
|
|
|
form.setFieldsValue(data)
|
|
|
|
}
|
|
|
|
}, [props])
|
2024-04-24 01:54:59 -04:00
|
|
|
function childReduce(child:DataType[]):PidSelectTree[]{
|
|
|
|
const result:PidSelectTree[] = [];
|
|
|
|
child.map(data=> {
|
2024-05-30 22:56:18 -04:00
|
|
|
const resultData:PidSelectTree = {label:data.name,value:data.id,pid:data.pid};
|
2024-04-24 01:54:59 -04:00
|
|
|
if (data.children){
|
|
|
|
resultData.children=childReduce(data.children);
|
|
|
|
}
|
|
|
|
result.push(resultData);
|
|
|
|
})
|
|
|
|
return result;
|
|
|
|
}
|
2024-05-29 04:44:23 -04:00
|
|
|
// 如果不是添加任务需要回显
|
2024-04-19 05:44:44 -04:00
|
|
|
return (
|
2024-04-24 01:54:59 -04:00
|
|
|
<ModalForm<DataType>
|
2024-05-29 04:44:23 -04:00
|
|
|
title={props.description}
|
|
|
|
open={props.open&&!props.haveButton}
|
|
|
|
trigger={props.haveButton?
|
2024-04-19 05:44:44 -04:00
|
|
|
<Button type="primary">
|
|
|
|
<PlusOutlined />
|
|
|
|
{props.description}
|
2024-05-29 04:44:23 -04:00
|
|
|
</Button>:undefined
|
2024-04-19 05:44:44 -04:00
|
|
|
}
|
|
|
|
form={form}
|
|
|
|
autoFocusFirstInput
|
|
|
|
modalProps={{
|
|
|
|
destroyOnClose: true,
|
2024-05-29 04:44:23 -04:00
|
|
|
onCancel: () => {
|
|
|
|
console.log('run');
|
|
|
|
props.reloadData?.();
|
|
|
|
},
|
2024-04-19 05:44:44 -04:00
|
|
|
}}
|
2024-06-03 06:39:42 -04:00
|
|
|
submitter={props.itemId!==undefined&&props.itemId!==-1?{
|
2024-05-30 22:56:18 -04:00
|
|
|
render: (prop, defaultDoms) => {
|
|
|
|
return [
|
2024-06-02 23:19:40 -04:00
|
|
|
editFormDisable?<Button
|
2024-05-30 22:56:18 -04:00
|
|
|
key="edit"
|
|
|
|
onClick={() => {
|
|
|
|
// props.submit();
|
|
|
|
setEditFormDisable(false)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
编辑
|
2024-06-02 23:19:40 -04:00
|
|
|
</Button>:undefined,
|
2024-06-03 06:39:42 -04:00
|
|
|
props.operationId === OPERATION_BUTTON_TYPE.DETAIL||props.operationId === OPERATION_BUTTON_TYPE.UPDATE?<Popconfirm
|
2024-06-02 23:19:40 -04:00
|
|
|
key ='delete'
|
2024-05-30 22:56:18 -04:00
|
|
|
title="删除任务"
|
|
|
|
description="确认要删除任务?"
|
|
|
|
icon={<QuestionCircleOutlined style={{color: 'red'}}/>}
|
|
|
|
okText="确认"
|
|
|
|
cancelText="取消"
|
|
|
|
onConfirm={() => {
|
|
|
|
if (props.itemId!==undefined) {
|
|
|
|
deleteTask(props.itemId).then((response => {
|
|
|
|
console.log('response', response)
|
|
|
|
if (response.status.success) {
|
|
|
|
message.success("删除任务成功:" + response.data)
|
|
|
|
props.reloadData?.()
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
><Button type="primary" danger>
|
|
|
|
删除
|
|
|
|
</Button>
|
2024-06-03 06:39:42 -04:00
|
|
|
</Popconfirm>:undefined
|
2024-05-30 22:56:18 -04:00
|
|
|
,
|
|
|
|
...defaultDoms
|
|
|
|
];
|
|
|
|
},
|
|
|
|
}:undefined}
|
2024-04-19 05:44:44 -04:00
|
|
|
onFinish={async (values) => {
|
2024-04-25 23:17:44 -04:00
|
|
|
console.log('Received values of form: ', values);
|
|
|
|
if (values.pid===undefined){
|
|
|
|
values.pid=0
|
|
|
|
}
|
|
|
|
if (values.expectedTimeRange?.[0]!=undefined) {
|
|
|
|
values.expectedStartTime=dayjs(values.expectedTimeRange[0]).toDate()
|
|
|
|
}
|
|
|
|
if (values.expectedTimeRange?.[1]!=undefined) {
|
|
|
|
values.expectedEndTime=dayjs(values.expectedTimeRange[1]).toDate()
|
|
|
|
}
|
|
|
|
if (values.actualTimeRange?.[0]!=undefined) {
|
|
|
|
values.actualStartTime=dayjs(values.actualTimeRange[0]).toDate()
|
|
|
|
}
|
|
|
|
if (values.actualTimeRange?.[1]!=undefined) {
|
|
|
|
values.actualEndTime=dayjs(values.actualTimeRange[1]).toDate()
|
|
|
|
}
|
2024-05-30 22:56:18 -04:00
|
|
|
values.pid=pid;
|
2024-04-25 23:17:44 -04:00
|
|
|
var result:boolean=false;
|
2024-05-30 22:56:18 -04:00
|
|
|
|
|
|
|
let state = taskStateList.find(taskState => taskState.name === values.state?.toString());
|
|
|
|
if (state) {
|
|
|
|
values.state = state.code
|
|
|
|
}
|
|
|
|
let priority = taskPriorityList.find(taskPriority => taskPriority.name === values.priority?.toString())
|
|
|
|
if (priority) {
|
|
|
|
values.priority = priority.code
|
|
|
|
}
|
2024-05-30 05:55:55 -04:00
|
|
|
// todo 修改
|
2024-05-31 02:36:21 -04:00
|
|
|
if (props.operationId === OPERATION_BUTTON_TYPE.UPDATE||(props.operationId === OPERATION_BUTTON_TYPE.DETAIL&&!editFormDisable)) {
|
2024-05-30 22:56:18 -04:00
|
|
|
await updateTask(values).then(response => {
|
|
|
|
console.log('response', response)
|
|
|
|
if (response.status.success) {
|
|
|
|
message.success("修改任务成功:" + response.data)
|
|
|
|
// 树任务重新刷新
|
|
|
|
// 四象限任务重新刷新
|
|
|
|
// 如果可以直接更新列表而不请求。。。。。。
|
|
|
|
console.log('props.reloadData?.()',props.reloadData)
|
|
|
|
props.reloadData?.()
|
|
|
|
result= true
|
|
|
|
}else {
|
|
|
|
message.error(response.status.message)
|
|
|
|
result= false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}else {
|
|
|
|
await addTask(values).then(response => {
|
|
|
|
console.log('response', response)
|
|
|
|
if (response.status.success) {
|
|
|
|
message.success("添加任务成功:" + response.data)
|
|
|
|
// 树任务重新刷新
|
|
|
|
// 四象限任务重新刷新
|
|
|
|
// 如果可以直接更新列表而不请求。。。。。。
|
|
|
|
console.log('props.reloadData?.()',props.reloadData)
|
|
|
|
props.reloadData?.()
|
|
|
|
result= true
|
|
|
|
}else {
|
|
|
|
message.error(response.status.message)
|
|
|
|
result= false
|
|
|
|
}
|
2024-04-25 04:36:40 -04:00
|
|
|
}
|
2024-05-30 22:56:18 -04:00
|
|
|
);
|
|
|
|
}
|
2024-04-25 23:17:44 -04:00
|
|
|
return result;
|
2024-04-19 05:44:44 -04:00
|
|
|
}}
|
|
|
|
>
|
2024-04-25 04:36:40 -04:00
|
|
|
<ProFormText width="sm" name="id" hidden={true} label="主键" />
|
2024-05-29 04:44:23 -04:00
|
|
|
<ProFormText width="sm" name="code" initialValue={props.itemId} hidden={true} label="任务编码" />
|
2024-04-25 04:36:40 -04:00
|
|
|
<ProFormText width="sm" name="pPid" initialValue={props.pPid} hidden={true} label="祖宗id" />
|
2024-04-19 05:44:44 -04:00
|
|
|
<ProForm.Group>
|
2024-04-24 01:54:59 -04:00
|
|
|
<ProFormTreeSelect
|
2024-04-19 05:44:44 -04:00
|
|
|
width="md"
|
2024-04-24 01:54:59 -04:00
|
|
|
request={() =>{
|
|
|
|
return getTaskTreeResult(JSON.stringify(
|
2024-06-03 20:51:40 -04:00
|
|
|
{pageSize:1000,pageNumber:1,data:[{code:'pid',value:'0',operateType:'='},{code:'state',value:'8,9',operateType:'IN'},{code:'',value:true,operateType: "TREE"}]}
|
2024-04-24 01:54:59 -04:00
|
|
|
)).then(result=> childReduce(result.data.content))
|
|
|
|
}}
|
|
|
|
name="pid"
|
|
|
|
label="父级任务"
|
2024-06-03 06:39:42 -04:00
|
|
|
fieldProps={{onSelect: (e,node) => {console.log('onSelect',e,node);setPid(e)}}}
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-19 05:44:44 -04:00
|
|
|
/>
|
|
|
|
<ProFormText
|
|
|
|
width="md"
|
2024-04-24 01:54:59 -04:00
|
|
|
name="name"
|
|
|
|
label="任务名称"
|
|
|
|
tooltip="最长为 24 位"
|
|
|
|
placeholder="请输入任务名称"
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-19 05:44:44 -04:00
|
|
|
/>
|
|
|
|
</ProForm.Group>
|
2024-04-24 01:54:59 -04:00
|
|
|
<ProFormTextArea
|
|
|
|
// width="md"
|
|
|
|
name="description"
|
|
|
|
label="任务描述"
|
|
|
|
// tooltip="最长为 24 位"
|
|
|
|
placeholder="请输入任务描述"
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-24 01:54:59 -04:00
|
|
|
/>
|
|
|
|
|
2024-04-19 05:44:44 -04:00
|
|
|
<ProForm.Group>
|
2024-04-24 01:54:59 -04:00
|
|
|
<ProFormSelect
|
|
|
|
request={async () => taskPriorityList.map(taskState => {
|
|
|
|
return {
|
|
|
|
'label': taskState.name,
|
|
|
|
'value': taskState.code
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
width="sm"
|
|
|
|
name="priority"
|
|
|
|
label="任务优先级"
|
2024-04-25 04:36:40 -04:00
|
|
|
initialValue='3'
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-24 01:54:59 -04:00
|
|
|
/>
|
|
|
|
<ProFormSelect
|
|
|
|
width="sm"
|
|
|
|
options={taskStateList.map(taskState => {
|
|
|
|
return {
|
|
|
|
'label': taskState.name,
|
|
|
|
'value': taskState.code
|
|
|
|
}
|
|
|
|
})}
|
|
|
|
name="state"
|
|
|
|
label="任务状态"
|
2024-04-25 04:36:40 -04:00
|
|
|
initialValue='8'
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-19 05:44:44 -04:00
|
|
|
/>
|
|
|
|
</ProForm.Group>
|
2024-04-24 01:54:59 -04:00
|
|
|
|
2024-04-19 05:44:44 -04:00
|
|
|
<ProForm.Group>
|
2024-04-25 04:36:40 -04:00
|
|
|
<ProFormDateTimeRangePicker
|
2024-04-25 23:17:44 -04:00
|
|
|
initialValue={[dayjs(), undefined]}
|
2024-04-24 01:54:59 -04:00
|
|
|
name="expectedTimeRange"
|
|
|
|
label="期望时间"
|
2024-04-25 23:17:44 -04:00
|
|
|
fieldProps={{allowEmpty:[true, true],showTime:true,needConfirm:false}}
|
2024-04-25 04:36:40 -04:00
|
|
|
placeholder={['开始时间','结束时间']}
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-19 05:44:44 -04:00
|
|
|
/>
|
2024-04-25 04:36:40 -04:00
|
|
|
<ProFormDateTimeRangePicker
|
2024-04-24 01:54:59 -04:00
|
|
|
name="actualTimeRange"
|
|
|
|
label="实际时间"
|
2024-04-25 23:17:44 -04:00
|
|
|
fieldProps={ {allowEmpty:[true, true],showTime:true,needConfirm:false}}
|
2024-04-25 04:36:40 -04:00
|
|
|
placeholder={['开始时间','结束时间']}
|
2024-05-30 22:56:18 -04:00
|
|
|
disabled ={editFormDisable}
|
2024-04-19 05:44:44 -04:00
|
|
|
/>
|
|
|
|
</ProForm.Group>
|
2024-04-24 01:54:59 -04:00
|
|
|
|
2024-04-19 05:44:44 -04:00
|
|
|
</ModalForm>
|
|
|
|
);
|
|
|
|
};
|