|
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
useState,
|
|
|
} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
-import { Button, Input, Popconfirm, Select, Table } from "antd";
|
|
|
+import { Button, Cascader, Input, Popconfirm, Select, Table } from "antd";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import { A2FromDataType, options1 } from "./data";
|
|
|
import {
|
|
|
@@ -26,19 +26,42 @@ import ExportJsonExcel from "js-export-excel";
|
|
|
function A2Psychz() {
|
|
|
// 站址地区的数据-下拉框
|
|
|
|
|
|
- const [optionsCity, setOptionsCity] = useState<
|
|
|
- { value: string; label: string }[]
|
|
|
- >([]);
|
|
|
+ const [optionsCity, setOptionsCity] = useState<any>([]);
|
|
|
|
|
|
const getCityFu = useCallback(async () => {
|
|
|
const res = await A2_APIgetCity();
|
|
|
if (res.code === 0) {
|
|
|
- const data: string[] = res.data;
|
|
|
- const arr = data.map((v) => ({
|
|
|
- value: v,
|
|
|
- label: v,
|
|
|
- }));
|
|
|
- setOptionsCity([{ value: "", label: "全部" }, ...arr]);
|
|
|
+ const obj = res.data;
|
|
|
+
|
|
|
+ const arr = [];
|
|
|
+
|
|
|
+ for (const k in obj) {
|
|
|
+ const temp1: any = {
|
|
|
+ value: k,
|
|
|
+ label: k,
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+
|
|
|
+ const children1Obj = Reflect.get(obj, k);
|
|
|
+
|
|
|
+ for (const k2 in children1Obj) {
|
|
|
+ const children2Arr = Reflect.get(children1Obj, k2);
|
|
|
+
|
|
|
+ const objTemp = {
|
|
|
+ value: k2,
|
|
|
+ label: k2,
|
|
|
+ children: children2Arr.map((v2: any) => ({
|
|
|
+ value: v2.region,
|
|
|
+ label: v2.region,
|
|
|
+ })),
|
|
|
+ };
|
|
|
+ temp1.children.push(objTemp);
|
|
|
+ }
|
|
|
+
|
|
|
+ arr.push(temp1);
|
|
|
+ }
|
|
|
+
|
|
|
+ setOptionsCity(arr);
|
|
|
// console.log(123, res);
|
|
|
}
|
|
|
}, []);
|
|
|
@@ -51,8 +74,10 @@ function A2Psychz() {
|
|
|
|
|
|
// 筛选和分页
|
|
|
const [tableSelect, setTableSelect] = useState<A2FromDataType>({
|
|
|
- siteLevel: 2,
|
|
|
- site: "",
|
|
|
+ siteArr: undefined,
|
|
|
+ province: "",
|
|
|
+ city: "",
|
|
|
+ region: "",
|
|
|
searchKey: "",
|
|
|
pmUser: "",
|
|
|
typeIn: "",
|
|
|
@@ -60,27 +85,41 @@ function A2Psychz() {
|
|
|
pageNum: 1,
|
|
|
});
|
|
|
|
|
|
+ const tableSelectRef = useRef({} as A2FromDataType);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ tableSelectRef.current = { ...tableSelect };
|
|
|
+ }, [tableSelect]);
|
|
|
+
|
|
|
+ // 点击搜索的 时间戳
|
|
|
+ const [timeKey, setTimeKey] = useState(-1);
|
|
|
+
|
|
|
// 发送接口的函数
|
|
|
const getListFu = useCallback(() => {
|
|
|
+ const objTemp: any = {};
|
|
|
+
|
|
|
+ if (tableSelectRef.current.siteArr) {
|
|
|
+ const temp = tableSelectRef.current.siteArr;
|
|
|
+ objTemp.province = temp[0];
|
|
|
+ objTemp.city = temp[1];
|
|
|
+ objTemp.region = temp[2];
|
|
|
+ }
|
|
|
+
|
|
|
const obj = {
|
|
|
- ...tableSelect,
|
|
|
- site: tableSelect.site ? tableSelect.site : null,
|
|
|
+ ...tableSelectRef.current,
|
|
|
+ ...objTemp,
|
|
|
};
|
|
|
dispatch(A2_APIgetlist(obj));
|
|
|
- }, [dispatch, tableSelect]);
|
|
|
+ }, [dispatch]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
getListFu();
|
|
|
- }, [getListFu]);
|
|
|
+ }, [getListFu, timeKey]);
|
|
|
|
|
|
// 输入框的改变
|
|
|
- const txtTimeRef = useRef(-1);
|
|
|
const txtChangeFu = useCallback(
|
|
|
(txt: string, key: "pmUser" | "searchKey") => {
|
|
|
- clearTimeout(txtTimeRef.current);
|
|
|
- txtTimeRef.current = window.setTimeout(() => {
|
|
|
- setTableSelect({ ...tableSelect, [key]: txt, pageNum: 1 });
|
|
|
- }, 500);
|
|
|
+ setTableSelect({ ...tableSelect, [key]: txt, pageNum: 1 });
|
|
|
},
|
|
|
[tableSelect]
|
|
|
);
|
|
|
@@ -91,14 +130,20 @@ function A2Psychz() {
|
|
|
// 把2个输入框和时间选择器清空
|
|
|
setInputKey(Date.now());
|
|
|
setTableSelect({
|
|
|
- siteLevel: 2,
|
|
|
- site: "",
|
|
|
+ siteArr: undefined,
|
|
|
+ province: "",
|
|
|
+ city: "",
|
|
|
+ region: "",
|
|
|
searchKey: "",
|
|
|
pmUser: "",
|
|
|
typeIn: "",
|
|
|
pageSize: 10,
|
|
|
pageNum: 1,
|
|
|
});
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now());
|
|
|
+ }, 50);
|
|
|
}, []);
|
|
|
|
|
|
// 从仓库获取列表
|
|
|
@@ -109,6 +154,9 @@ function A2Psychz() {
|
|
|
const paginationChange = useCallback(
|
|
|
() => (pageNum: number, pageSize: number) => {
|
|
|
setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
+ setTimeout(() => {
|
|
|
+ setTimeKey(Date.now());
|
|
|
+ }, 50);
|
|
|
},
|
|
|
[tableSelect]
|
|
|
);
|
|
|
@@ -120,7 +168,7 @@ function A2Psychz() {
|
|
|
if (res.code === 0) {
|
|
|
MessageFu.success("删除成功!");
|
|
|
getListFu();
|
|
|
- getCityFu()
|
|
|
+ getCityFu();
|
|
|
}
|
|
|
},
|
|
|
[getCityFu, getListFu]
|
|
|
@@ -131,9 +179,9 @@ function A2Psychz() {
|
|
|
{
|
|
|
title: "站址地区",
|
|
|
render: (item: A2tableType) =>
|
|
|
- !item.province && !item.city
|
|
|
+ !item.province && !item.city && !item.region
|
|
|
? "(空)"
|
|
|
- : `${item.province} - ${item.city}`,
|
|
|
+ : `${item.province}-${item.city}-${item.region}`,
|
|
|
},
|
|
|
{
|
|
|
title: "详细地址",
|
|
|
@@ -221,14 +269,26 @@ function A2Psychz() {
|
|
|
return MessageFu.warning("当前搜索条件没有数据!");
|
|
|
const name = "机房管理" + dayjs(new Date()).format("YYYY-MM-DD HH:mm");
|
|
|
|
|
|
+ const objTemp: any = {};
|
|
|
+
|
|
|
+ if (tableSelectRef.current.siteArr) {
|
|
|
+ const temp = tableSelectRef.current.siteArr;
|
|
|
+ objTemp.province = temp[0];
|
|
|
+ objTemp.city = temp[1];
|
|
|
+ objTemp.region = temp[2];
|
|
|
+ }
|
|
|
+
|
|
|
const res = await A2_APIgetlistDerive({
|
|
|
- ...tableSelect,
|
|
|
- site: tableSelect.site ? tableSelect.site : null,
|
|
|
+ ...tableSelectRef.current,
|
|
|
+ ...objTemp,
|
|
|
pageNum: 1,
|
|
|
pageSize: 99999,
|
|
|
});
|
|
|
|
|
|
if (res.code === 0) {
|
|
|
+ if (res.data.records.length <= 0)
|
|
|
+ return MessageFu.warning("当前搜索条件没有数据!");
|
|
|
+
|
|
|
const option = {
|
|
|
fileName: name,
|
|
|
datas: [
|
|
|
@@ -236,7 +296,9 @@ function A2Psychz() {
|
|
|
sheetData: res.data.records.map((v: A2tableType) => ({
|
|
|
...v,
|
|
|
myCity:
|
|
|
- !v.province && !v.city ? "(空)" : `${v.province} - ${v.city}`,
|
|
|
+ !v.province && !v.city && !v.region
|
|
|
+ ? "(空)"
|
|
|
+ : `${v.province}-${v.city}-${v.region}`,
|
|
|
address: v.address || "(空)",
|
|
|
name: v.name || "(空)",
|
|
|
siteNum: v.siteNum || "(空)",
|
|
|
@@ -277,7 +339,7 @@ function A2Psychz() {
|
|
|
const toExcel = new ExportJsonExcel(option); //new
|
|
|
toExcel.saveExcel(); //保存
|
|
|
}
|
|
|
- }, [A2TableList.list.length, tableSelect]);
|
|
|
+ }, [A2TableList.list.length]);
|
|
|
|
|
|
return (
|
|
|
<div className={styles.A2Psychz}>
|
|
|
@@ -294,13 +356,19 @@ function A2Psychz() {
|
|
|
<div className="A2top1">
|
|
|
<div className="A2topRow">
|
|
|
<span>站址地区:</span>
|
|
|
- <Select
|
|
|
- style={{ width: 130 }}
|
|
|
- value={tableSelect.site}
|
|
|
+
|
|
|
+ <Cascader
|
|
|
+ style={{ width: 240 }}
|
|
|
+ options={optionsCity}
|
|
|
+ value={tableSelect.siteArr}
|
|
|
+ placeholder="全部"
|
|
|
onChange={(e) =>
|
|
|
- setTableSelect({ ...tableSelect, site: e, pageNum: 1 })
|
|
|
+ setTableSelect({
|
|
|
+ ...tableSelect,
|
|
|
+ siteArr: e as string[],
|
|
|
+ pageNum: 1,
|
|
|
+ })
|
|
|
}
|
|
|
- options={optionsCity}
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
@@ -309,57 +377,64 @@ function A2Psychz() {
|
|
|
<Input
|
|
|
key={inputKey}
|
|
|
maxLength={24}
|
|
|
- style={{ width: 323 }}
|
|
|
+ style={{ width: 322 }}
|
|
|
placeholder="请输入站址名称/站置编号/机房编码,最多24字"
|
|
|
allowClear
|
|
|
onChange={(e) => txtChangeFu(e.target.value, "searchKey")}
|
|
|
/>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
|
|
|
- <div className="A2topRow">
|
|
|
- <span>项目经理:</span>
|
|
|
- <Input
|
|
|
- key={inputKey}
|
|
|
- maxLength={10}
|
|
|
- style={{ width: 174 }}
|
|
|
- placeholder="请输入姓名,最多10字"
|
|
|
- allowClear
|
|
|
- onChange={(e) => txtChangeFu(e.target.value, "pmUser")}
|
|
|
- />
|
|
|
+ <div className="A2top2">
|
|
|
+ <div>
|
|
|
+ <div className="A2topRow">
|
|
|
+ <span>项目经理:</span>
|
|
|
+ <Input
|
|
|
+ key={inputKey}
|
|
|
+ maxLength={10}
|
|
|
+ style={{ width: 240 }}
|
|
|
+ placeholder="请输入姓名,最多10字"
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => txtChangeFu(e.target.value, "pmUser")}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div className="A2topRow">
|
|
|
+ <span>录入方式:</span>
|
|
|
+ <Select
|
|
|
+ style={{ width: 150 }}
|
|
|
+ value={tableSelect.typeIn}
|
|
|
+ onChange={(e) =>
|
|
|
+ setTableSelect({ ...tableSelect, typeIn: e, pageNum: 1 })
|
|
|
+ }
|
|
|
+ options={options1}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</div>
|
|
|
-
|
|
|
- <div className="A2topRow">
|
|
|
- <span>录入方式:</span>
|
|
|
- <Select
|
|
|
- style={{ width: 116 }}
|
|
|
- value={tableSelect.typeIn}
|
|
|
- onChange={(e) =>
|
|
|
- setTableSelect({ ...tableSelect, typeIn: e, pageNum: 1 })
|
|
|
- }
|
|
|
- options={options1}
|
|
|
- />
|
|
|
+ {/* 按钮 */}
|
|
|
+ <div>
|
|
|
+ <Button onClick={resetSelectFu}>重置</Button> 
|
|
|
+ <Button type="primary" onClick={() => setTimeKey(Date.now())}>
|
|
|
+ 查询
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() => setOpenInfo({ id: -1, txt: "新增" })}
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </Button>
|
|
|
+  
|
|
|
+ <Button type="primary" onClick={deriveFu}>
|
|
|
+ 导出表格
|
|
|
+ </Button>
|
|
|
</div>
|
|
|
</div>
|
|
|
- {/* 右侧按钮 */}
|
|
|
- <div className="A2top2">
|
|
|
- <Button onClick={resetSelectFu}>重置</Button> 
|
|
|
- <Button
|
|
|
- type="primary"
|
|
|
- onClick={() => setOpenInfo({ id: -1, txt: "新增" })}
|
|
|
- >
|
|
|
- 新增
|
|
|
- </Button>
|
|
|
-  
|
|
|
- <Button type="primary" onClick={deriveFu}>
|
|
|
- 导出表格
|
|
|
- </Button>
|
|
|
- </div>
|
|
|
</div>
|
|
|
|
|
|
{/* 表格主体 */}
|
|
|
<div className="tableMain">
|
|
|
<Table
|
|
|
- scroll={{ y: 625 }}
|
|
|
+ scroll={{ y: 578 }}
|
|
|
dataSource={A2TableList.list}
|
|
|
columns={columns}
|
|
|
rowKey="id"
|
|
|
@@ -390,6 +465,11 @@ function A2Psychz() {
|
|
|
}}
|
|
|
/>
|
|
|
) : null}
|
|
|
+
|
|
|
+ {/* 右下角的列表数量 */}
|
|
|
+ <div className="tableNumBox">
|
|
|
+ 共 <span>{A2TableList.total}</span> 条数据
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
}
|