Commit f4001def authored by 皮倩雯's avatar 皮倩雯

fix: '巡检反馈搜索'

parent 37bbc3ba
Pipeline #77021 waiting for manual action with stages
/* eslint-disable react-hooks/rules-of-hooks */ /* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Space, Table, Popconfirm, Tooltip, Button, notification, Spin, Card, Input } from 'antd'; import { Space, Table, Popconfirm, Tooltip, Button, notification, Spin, Card, Input } from 'antd';
import { import {
CM_Feedback_LoadPatrolFeedbacks, CM_Feedback_LoadPatrolFeedbacks,
...@@ -36,7 +36,10 @@ const patrolFeedback = () => { ...@@ -36,7 +36,10 @@ const patrolFeedback = () => {
const [treeVisible, setTreeVisible] = useState(true); // 左边列表是否可见 const [treeVisible, setTreeVisible] = useState(true); // 左边列表是否可见
const [pickItem, setPickItem] = useState('区域巡检'); const [pickItem, setPickItem] = useState('区域巡检');
const [hoverItemIndex, setHoverItemIndex] = useState(''); const [hoverItemIndex, setHoverItemIndex] = useState('');
const [searchValue, setSearchValue] = useState(''); // const [searchValue, setSearchValue] = useState('');
const searchValue = useRef(null);
const [keepSearch, setKeepSearch] = useState([]);
const [newTableData, setNewTableData] = useState([]);
const columns = [ const columns = [
{ {
...@@ -203,50 +206,61 @@ const patrolFeedback = () => { ...@@ -203,50 +206,61 @@ const patrolFeedback = () => {
]; ];
useEffect(() => { useEffect(() => {
getTableList();
}, []);
const getTableList = val => {
setTreeLoading(true); setTreeLoading(true);
CM_Feedback_LoadPatrolFeedbacks({ pageIndex: 1, pageSize: 20, keyword: searchValue }).then( CM_Feedback_LoadPatrolFeedbacks({
res => { pageIndex: 1,
setTreeLoading(false); pageSize: 20,
if (res.code === 0) { keyword: val ? val : searchValue.current,
let data = {}; }).then(res => {
if (res.data.list.length > 0) { setTreeLoading(false);
let area = []; if (res.code === 0) {
let dma = []; let data = {};
let other = []; if (res.data.list.length > 0) {
res.data.list.map(i => { let area = [];
if (i.businessGroup === '区域巡检') { let dma = [];
area.push(i); let other = [];
} else if (i.businessGroup === 'DMA巡检') { res.data.list.map(i => {
dma.push(i); if (i.businessGroup === '区域巡检') {
} else if ( area.push(i);
i.businessGroup === '区域巡检,DMA巡检' || } else if (i.businessGroup === 'DMA巡检') {
i.businessGroup === 'DMA巡检,区域巡检' dma.push(i);
) { } else if (
area.push(i); i.businessGroup === '区域巡检,DMA巡检' ||
dma.push(i); i.businessGroup === 'DMA巡检,区域巡检'
} else { ) {
other.push(i); area.push(i);
} dma.push(i);
});
data.区域巡检 = area;
data.DMA巡检 = dma;
if (other.length > 0) {
data.未分组 = other;
setGroupName(['区域巡检', 'DMA巡检', '未分组']);
} else { } else {
setGroupName(['区域巡检', 'DMA巡检']); other.push(i);
} }
}
setTableData(data);
let list = [];
res.data.list.map(i => {
list.push(i.layerName);
}); });
setKeepTableData(list); data.区域巡检 = area;
data.DMA巡检 = dma;
if (other.length > 0) {
data.未分组 = other;
setGroupName(['区域巡检', 'DMA巡检', '未分组']);
} else {
setGroupName(['区域巡检', 'DMA巡检']);
}
} }
}, if (searchValue.current) {
); setNewTableData(res.data.list);
}, [flag]); } else {
setNewTableData(data[pickItem]);
}
setTableData(data);
let list = [];
res.data.list.map(i => {
list.push(i.layerName);
});
setKeepTableData(list);
}
});
};
const add = () => { const add = () => {
setAddVisible(true); setAddVisible(true);
...@@ -265,7 +279,7 @@ const patrolFeedback = () => { ...@@ -265,7 +279,7 @@ const patrolFeedback = () => {
duration: 3, duration: 3,
description: '删除成功', description: '删除成功',
}); });
setFlag(flag + 1); getTableList();
} else { } else {
notification.error({ notification.error({
message: '提示', message: '提示',
...@@ -277,7 +291,7 @@ const patrolFeedback = () => { ...@@ -277,7 +291,7 @@ const patrolFeedback = () => {
}; };
const onOK = () => { const onOK = () => {
setFlag(flag + 1); getTableList();
}; };
const sort = () => { const sort = () => {
...@@ -303,7 +317,7 @@ const patrolFeedback = () => { ...@@ -303,7 +317,7 @@ const patrolFeedback = () => {
description: '批量删除成功', description: '批量删除成功',
}); });
setSelectedRowKeys([]); setSelectedRowKeys([]);
setFlag(flag + 1); getTableList();
} else { } else {
notification.error({ notification.error({
message: '提示', message: '提示',
...@@ -320,12 +334,9 @@ const patrolFeedback = () => { ...@@ -320,12 +334,9 @@ const patrolFeedback = () => {
}; };
// 搜索 // 搜索
const handleSearch = text => { const handleSearch = e => {
setFlag(flag + 1); searchValue.current = e;
}; getTableList(e);
// 搜索框改变时存储输入的值
const handleChange = e => {
setSearchValue(e.target.value);
}; };
return ( return (
...@@ -426,8 +437,6 @@ const patrolFeedback = () => { ...@@ -426,8 +437,6 @@ const patrolFeedback = () => {
allowClear allowClear
placeholder="请输入巡检对象名称" placeholder="请输入巡检对象名称"
onSearch={handleSearch} onSearch={handleSearch}
onChange={handleChange}
value={searchValue}
enterButton enterButton
style={{ width: '300px' }} style={{ width: '300px' }}
/> />
...@@ -485,7 +494,7 @@ const patrolFeedback = () => { ...@@ -485,7 +494,7 @@ const patrolFeedback = () => {
}, // 双击 }, // 双击
})} })}
columns={columns} columns={columns}
dataSource={tableData[pickItem]} dataSource={newTableData}
scroll={{ y: 'calc(100% - 40px)', x: 'max-content' }} scroll={{ y: 'calc(100% - 40px)', x: 'max-content' }}
pagination={{ pagination={{
showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`, showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment