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(() => {
|
2025-01-13 06:33:16 -05:00
|
|
|
initSearch();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const initSearch = async () => {
|
2024-12-31 08:53:20 -05:00
|
|
|
if (search && search.data) {
|
2025-01-13 06:33:16 -05:00
|
|
|
const stateDictionary = await getDictionary("2");
|
|
|
|
const priorityDictionary = await getDictionary("1");
|
|
|
|
// 处理主要条件
|
|
|
|
const tagList = [];
|
|
|
|
console.log("search.data.orSearchModel",search.data.orSearchModel)
|
|
|
|
search.data.orSearchModel?.andList?.forEach((searchObj) => {
|
|
|
|
if (searchObj.name === "pid") {
|
|
|
|
tagList.push(<Tag key={pName}>{pName}</Tag>)
|
|
|
|
} else if (searchObj.name === "state") {
|
|
|
|
const items = searchObj.value.split(',');
|
|
|
|
items.forEach((item) => {
|
|
|
|
const dict = stateDictionary.get(item);
|
|
|
|
if (dict) {
|
|
|
|
tagList.push(<Tag key={dict.id} color={dict.jsonValue?.color}>{dict.itemName}</Tag>)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (searchObj.name === "priority") {
|
|
|
|
const items = searchObj.value.split(',');
|
|
|
|
items.forEach((item) => {
|
|
|
|
const dict = priorityDictionary.get(item);
|
|
|
|
if (dict) {
|
|
|
|
tagList.push(<Tag key={dict.id} color={dict.jsonValue?.color}>{dict.itemName}</Tag>);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (searchObj.name === "name") {
|
|
|
|
tagList.push(<Tag key={searchObj.value}>{searchObj.value}</Tag>);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// 处理日期
|
|
|
|
search.data.orSearchModel?.andSearchModel?.andList?.forEach((searchObj) => {
|
|
|
|
if (searchObj.name === "expectedEndTime") {
|
|
|
|
tagList.push(
|
|
|
|
<Tag
|
|
|
|
key={dayjs(searchObj.value).format("YYYY-MM-DD")}>
|
|
|
|
{dayjs(searchObj.value).format("YYYY-MM-DD")}
|
|
|
|
</Tag>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// 处理逾期
|
|
|
|
search.data.andList?.forEach((searchObj) => {
|
|
|
|
console.log("DetailSearchContext.search", searchObj)
|
|
|
|
if (searchObj.name === "state" && searchObj.value === "10") {
|
|
|
|
const dict = stateDictionary.get(searchObj.value);
|
|
|
|
if (dict && tagList.length > 0) {
|
|
|
|
tagList.push(<AddOutline/>)
|
|
|
|
} if (dict) {
|
|
|
|
tagList.push(<Tag key={dict.id} color={dict.jsonValue?.color}>
|
|
|
|
{dict.itemName}
|
|
|
|
</Tag>);
|
2025-01-08 06:28:29 -05:00
|
|
|
}
|
2025-01-13 06:33:16 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
setTags(tagList);
|
2024-12-31 08:53:20 -05:00
|
|
|
}
|
2025-01-13 06:33:16 -05:00
|
|
|
}
|
2024-12-31 08:53:20 -05:00
|
|
|
|
|
|
|
const navigate = useNavigate();
|
2024-12-30 06:24:34 -05:00
|
|
|
return (
|
|
|
|
<div className="detailSearchBar">
|
2025-01-13 06:33:16 -05:00
|
|
|
<div className={"onSearchItem " + (showCloseOutline ? "onSearchItemWidth" : "onSearchItemOnlyWidth")}
|
|
|
|
onClick={() => {
|
|
|
|
navigate("/detail/searchTask", {state: {"search": search}});
|
|
|
|
}}>
|
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;
|