2024-12-30 06:24:34 -05:00
|
|
|
import {Tag,} from "antd-mobile";
|
2025-01-08 06:28:29 -05:00
|
|
|
import React, {Fragment, useEffect, useState} from "react";
|
2024-12-30 06:24:34 -05:00
|
|
|
import {useLocation, useNavigate} from 'react-router-dom';
|
2025-01-08 06:28:29 -05:00
|
|
|
import {AddOutline, CloseOutline, SearchOutline} from "antd-mobile-icons";
|
2024-12-30 06:24:34 -05:00
|
|
|
import "./index.css"
|
2024-12-31 08:53:20 -05:00
|
|
|
import {getDictionary} from "../../utils/dictUtil";
|
2025-01-08 06:28:29 -05:00
|
|
|
import dayjs from "dayjs";
|
2024-12-30 06:24:34 -05:00
|
|
|
|
2024-12-31 08:53:20 -05:00
|
|
|
const DetailSearchBar = (props) => {
|
|
|
|
// 从搜索设置中传来的search
|
|
|
|
// const location = useLocation();
|
|
|
|
// const searchUpdate = location.state?.search;
|
|
|
|
// 父子传值从搜索框传来的search
|
2025-01-08 06:28:29 -05:00
|
|
|
const {search, updateSearch, pName} = props;
|
2025-01-05 05:04:52 -05:00
|
|
|
console.log("DetailSearchBar.search", search)
|
2024-12-31 08:53:20 -05:00
|
|
|
const [tags, setTags] = useState([]);
|
2025-01-08 06:28:29 -05:00
|
|
|
const showCloseOutline = search && search.data &&
|
|
|
|
(search.data.andList?.length > 0 || search.data.orList?.length > 0)
|
2024-12-31 08:53:20 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (search && search.data) {
|
2025-01-08 06:28:29 -05:00
|
|
|
Promise.all([
|
|
|
|
...search.data.andList.map(async (searchObj) => {
|
2025-01-01 08:16:32 -05:00
|
|
|
console.log("DetailSearchContext.search", searchObj)
|
|
|
|
if (searchObj.name === "pid") {
|
|
|
|
return <Tag>{pName}</Tag>
|
2025-01-08 06:28:29 -05:00
|
|
|
} else if (searchObj.name === "state") {
|
2024-12-31 08:53:20 -05:00
|
|
|
const dictionary = await getDictionary("2");
|
|
|
|
const items = searchObj.value.split(',');
|
|
|
|
const itemPromises = items.map((item) => {
|
|
|
|
const dict = dictionary.get(item);
|
|
|
|
return dict ? <Tag key={dict.id} color={dict.jsonValue?.color}>{dict.itemName}</Tag> : null;
|
|
|
|
});
|
|
|
|
return Promise.all(itemPromises);
|
2025-01-08 06:28:29 -05:00
|
|
|
} else if (searchObj.name === "priority") {
|
2025-01-01 08:16:32 -05:00
|
|
|
const dictionary = await getDictionary("1");
|
|
|
|
const items = searchObj.value.split(',');
|
|
|
|
const itemPromises = items.map((item) => {
|
|
|
|
const dict = dictionary.get(item);
|
|
|
|
return dict ? <Tag key={dict.id} color={dict.jsonValue?.color}>{dict.itemName}</Tag> : null;
|
|
|
|
});
|
|
|
|
return Promise.all(itemPromises);
|
2025-01-08 06:28:29 -05:00
|
|
|
} else if (searchObj.name === "expectedEndTime") {
|
|
|
|
console.log("searchObj.value" + searchObj.value, dayjs(searchObj.value).format("YYYY-MM-DD"))
|
|
|
|
return <Tag>{dayjs(searchObj.value).format("YYYY-MM-DD")}</Tag>;
|
|
|
|
} else if (searchObj.name === "name") {
|
|
|
|
return <Tag>{searchObj.value}</Tag>;
|
2024-12-31 08:53:20 -05:00
|
|
|
}
|
2025-01-08 06:28:29 -05:00
|
|
|
}),
|
|
|
|
...search.data.orList.map(async (searchObj) => {
|
|
|
|
console.log("DetailSearchContext.search", searchObj)
|
|
|
|
if (searchObj.name === "state" && searchObj.value === "10") {
|
|
|
|
const dictionary = await getDictionary("2");
|
|
|
|
const dict = dictionary.get(searchObj.value);
|
|
|
|
return dict ?
|
|
|
|
<Fragment><AddOutline/>
|
|
|
|
<Tag key={dict.id} color={dict.jsonValue?.color}>
|
|
|
|
{dict.itemName}
|
|
|
|
</Tag>
|
|
|
|
</Fragment> : null;
|
|
|
|
}
|
|
|
|
})]
|
2024-12-31 08:53:20 -05:00
|
|
|
).then((results) => {
|
|
|
|
// Flatten the results and filter out null values
|
|
|
|
const flattenedResults = results.flat().filter(Boolean);
|
|
|
|
console.log("flattenedResults", flattenedResults);
|
|
|
|
setTags(flattenedResults);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
2024-12-30 06:24:34 -05:00
|
|
|
return (
|
|
|
|
<div className="detailSearchBar">
|
2025-01-08 06:28:29 -05:00
|
|
|
<div className={"onSearchItem " + (showCloseOutline ? "onSearchItemWidth" : "onSearchItemOnlyWidth")} onClick={() => {
|
|
|
|
navigate("/detail/searchTask", {state: {"search": search}});
|
2024-12-30 06:24:34 -05:00
|
|
|
}}>
|
2024-12-31 08:53:20 -05:00
|
|
|
<SearchOutline/>
|
|
|
|
{/*根据search处理搜素框展示内容*/}
|
|
|
|
{tags}
|
2024-12-30 06:24:34 -05:00
|
|
|
</div>
|
2025-01-08 06:28:29 -05:00
|
|
|
{showCloseOutline && <div className="CloseOutline-CloseOutline" onClick={() => {
|
2025-01-05 05:04:52 -05:00
|
|
|
updateSearch({
|
|
|
|
"pageSize": 20,
|
|
|
|
"pageNumber": 1,
|
2025-01-08 06:28:29 -05:00
|
|
|
"data": {
|
|
|
|
"andList": [],
|
|
|
|
"orList": []
|
|
|
|
}
|
2025-01-05 05:04:52 -05:00
|
|
|
});
|
2024-12-31 08:53:20 -05:00
|
|
|
setTags([]);
|
2024-12-30 06:24:34 -05:00
|
|
|
}}>
|
|
|
|
<CloseOutline style={{float: "right"}}/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{/*<SearchBar placeholder='请输入内容' onFocus={() => {*/}
|
|
|
|
{/* navigate("/detail/searchTask")*/}
|
|
|
|
{/*}}*/}
|
|
|
|
|
|
|
|
{/*>*/}
|
|
|
|
{/* */}
|
|
|
|
{/*</SearchBar>*/}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default DetailSearchBar;
|