assistant-todo-mobile/src/components/ParentTask/index.js

106 lines
3.5 KiB
JavaScript
Raw Normal View History

2025-01-27 09:47:46 -05:00
import {Cascader, SearchBar} from "antd-mobile";
import React, {useEffect, useState} from "react";
2024-12-27 06:06:20 -05:00
import {
Form,
} from 'antd-mobile'
2025-01-24 05:56:31 -05:00
import "./index.css"
import {CloseCircleFill} from "antd-mobile-icons";
2025-01-27 09:47:46 -05:00
import {useChildList} from "../../hooks/useChildList";
2024-12-27 06:06:20 -05:00
2025-01-23 06:32:24 -05:00
const ParentTask = (props) => {
2025-01-27 09:47:46 -05:00
const {form, disabled, pName, pidArray, addEditPName, removePid} = props;
2025-01-23 06:32:24 -05:00
const [parentValue, setParentValue] = useState(pidArray ?? [])
2024-12-27 06:06:20 -05:00
const [visible, setVisible] = useState(false)
2025-01-27 09:47:46 -05:00
const {
options, removeTaskId, changeInitPidArray, changeSearchValue,
changeSelectValue, changeCurrentLab, changeTaskId
} = useChildList();
2024-12-29 03:54:01 -05:00
useEffect(() => {
2025-01-23 06:32:24 -05:00
initDate()
}, [props])
2025-01-27 09:47:46 -05:00
function initDate() {
if (removePid) {
removeTaskId(removePid)
}
2025-01-23 06:32:24 -05:00
if (pidArray && pidArray.length > 0) {
setParentValue(pidArray)
2025-01-27 09:47:46 -05:00
changeInitPidArray(pidArray)
2025-01-23 06:32:24 -05:00
}
}
2024-12-29 03:54:01 -05:00
2024-12-27 06:06:20 -05:00
return <Form.Item
2024-12-29 03:54:01 -05:00
name='pidArray'
2024-12-27 06:06:20 -05:00
label='主线任务'
2025-01-24 05:56:31 -05:00
value={parentValue}
disabled={disabled}
arrow={
(form.getFieldValue('pidArray') && form.getFieldValue('pidArray').length > 0) ? (
<CloseCircleFill
style={{
color: 'var(--adm-color-light)',
fontSize: 14,
}}
onClick={e => {
form.setFieldsValue({pidArray: []})
setParentValue([])
// 阻止冒泡
e.stopPropagation()
// 阻止所有后续事件处理程序
// e.nativeEvent.stopImmediatePropagation();
}}
/>) : true
}
2024-12-27 06:06:20 -05:00
onClick={() => {
setVisible(true)
}}
>
<Cascader
2025-01-24 05:56:31 -05:00
title={<SearchBar placeholder='搜索当前层相关标题' onChange={
// 获取当前选卡,过滤当前选项
(value) => {
2025-01-27 09:47:46 -05:00
changeSearchValue(value);
2025-01-24 05:56:31 -05:00
}
}/>}
2024-12-27 06:06:20 -05:00
options={options}
visible={visible}
2025-01-23 06:32:24 -05:00
defaultValue={pidArray}
2024-12-27 06:06:20 -05:00
onClose={() => {
setVisible(false)
}}
value={parentValue}
2025-01-23 06:32:24 -05:00
onConfirm={(val) => {
2024-12-29 03:54:01 -05:00
console.log(val)
2025-01-23 06:32:24 -05:00
setParentValue(val[val.length - 1])
form.setFieldValue('pidArray', val)
2024-12-29 03:54:01 -05:00
}}
2025-01-24 05:56:31 -05:00
onTabsChange={index => {
2025-01-27 09:47:46 -05:00
changeCurrentLab(index)
2025-01-24 05:56:31 -05:00
}}
2024-12-29 03:54:01 -05:00
onSelect={value => {
2025-01-27 09:47:46 -05:00
console.log({value})
if (value && value.length > 0) {
changeSelectValue(value)
changeTaskId(value[value.length - 1])
}
2024-12-27 06:06:20 -05:00
}}
>
{items => {
if (items.every(item => item === null)) {
2025-01-24 05:56:31 -05:00
return (pName && form.getFieldValue('pidArray') && form.getFieldValue('pidArray').length > 0) ? (
<span>{pName}</span>) : disabled ?
2025-01-23 06:32:24 -05:00
(<span>主线任务选填</span>) :
2025-01-11 04:53:51 -05:00
(<span style={{color: "#cccccc"}}>主线任务选填</span>)
2025-01-24 05:56:31 -05:00
} else if (items) {
2025-01-23 06:32:24 -05:00
if (addEditPName) {
addEditPName(items[items.length - 1].label)
}
return items[items.length - 1].label
2024-12-27 06:06:20 -05:00
}
}}
</Cascader>
</Form.Item>
}
export default ParentTask;