|
@@ -1,12 +1,366 @@
|
|
|
-import React from "react";
|
|
|
|
|
|
|
+import React, {
|
|
|
|
|
+ useCallback,
|
|
|
|
|
+ useEffect,
|
|
|
|
|
+ useMemo,
|
|
|
|
|
+ useRef,
|
|
|
|
|
+ useState,
|
|
|
|
|
+} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
import styles from "./index.module.scss";
|
|
|
- function A2Psychz() {
|
|
|
|
|
-
|
|
|
|
|
|
|
+import { Button, Cascader, Input, Popconfirm, Select, Table } from "antd";
|
|
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
+import { A2FromDataType, options1 } from "./data";
|
|
|
|
|
+import mapDataAll from "../C1User/AddUser/city";
|
|
|
|
|
+import {
|
|
|
|
|
+ A2_APIgetlist,
|
|
|
|
|
+ A2_APIgetlistDerive,
|
|
|
|
|
+ A2_APIremoves,
|
|
|
|
|
+} from "@/store/action/A2Psychz";
|
|
|
|
|
+import { RootState } from "@/store";
|
|
|
|
|
+import { A2tableType } from "@/types";
|
|
|
|
|
+import { MessageFu } from "@/utils/message";
|
|
|
|
|
+import { A1addType } from "../A1Camera/data";
|
|
|
|
|
+import AddPsychz from "./AddPsychz";
|
|
|
|
|
+import dayjs from "dayjs";
|
|
|
|
|
+import ExportJsonExcel from "js-export-excel";
|
|
|
|
|
+
|
|
|
|
|
+function A2Psychz() {
|
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
|
|
+
|
|
|
|
|
+ // 筛选和分页
|
|
|
|
|
+ const [tableSelect, setTableSelect] = useState<A2FromDataType>({
|
|
|
|
|
+ siteLevel: 2,
|
|
|
|
|
+ site: undefined,
|
|
|
|
|
+ searchKey: "",
|
|
|
|
|
+ pmUser: "",
|
|
|
|
|
+ typeIn: "",
|
|
|
|
|
+ pageSize: 10,
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 发送接口的函数
|
|
|
|
|
+ const getListFu = useCallback(() => {
|
|
|
|
|
+ const obj = {
|
|
|
|
|
+ ...tableSelect,
|
|
|
|
|
+ site: tableSelect.site ? tableSelect.site[1] : null,
|
|
|
|
|
+ };
|
|
|
|
|
+ dispatch(A2_APIgetlist(obj));
|
|
|
|
|
+ }, [dispatch, tableSelect]);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ getListFu();
|
|
|
|
|
+ }, [getListFu]);
|
|
|
|
|
+
|
|
|
|
|
+ // 输入框的改变
|
|
|
|
|
+ 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);
|
|
|
|
|
+ },
|
|
|
|
|
+ [tableSelect]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 点击重置
|
|
|
|
|
+ const [inputKey, setInputKey] = useState(1);
|
|
|
|
|
+ const resetSelectFu = useCallback(() => {
|
|
|
|
|
+ // 把2个输入框和时间选择器清空
|
|
|
|
|
+ setInputKey(Date.now());
|
|
|
|
|
+ setTableSelect({
|
|
|
|
|
+ siteLevel: 2,
|
|
|
|
|
+ site: undefined,
|
|
|
|
|
+ searchKey: "",
|
|
|
|
|
+ pmUser: "",
|
|
|
|
|
+ typeIn: "",
|
|
|
|
|
+ pageSize: 10,
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ });
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
|
|
+ // 从仓库获取列表
|
|
|
|
|
+ const A2TableList = useSelector(
|
|
|
|
|
+ (state: RootState) => state.A2Psychz.A2TableList
|
|
|
|
|
+ );
|
|
|
|
|
+ // 页码变化
|
|
|
|
|
+ const paginationChange = useCallback(
|
|
|
|
|
+ () => (pageNum: number, pageSize: number) => {
|
|
|
|
|
+ setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
|
|
+ },
|
|
|
|
|
+ [tableSelect]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 点击删除
|
|
|
|
|
+ const delByIdFu = useCallback(
|
|
|
|
|
+ async (id: number) => {
|
|
|
|
|
+ const res = await A2_APIremoves(id);
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
|
|
+ getListFu();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ [getListFu]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const columns = useMemo(() => {
|
|
|
|
|
+ return [
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "站址地区",
|
|
|
|
|
+ render: (item: A2tableType) =>
|
|
|
|
|
+ !item.province && !item.city
|
|
|
|
|
+ ? "(空)"
|
|
|
|
|
+ : `${item.province} - ${item.city}`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "详细地址",
|
|
|
|
|
+ render: (item: A2tableType) =>
|
|
|
|
|
+ item.address ? (
|
|
|
|
|
+ item.address.length >= 25 ? (
|
|
|
|
|
+ <span style={{ cursor: "pointer" }} title={item.address}>
|
|
|
|
|
+ {item.address.substring(0, 25) + "..."}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ item.address
|
|
|
|
|
+ )
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ "(空)"
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "站址名称",
|
|
|
|
|
+ dataIndex: "name",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "站址编号",
|
|
|
|
|
+ dataIndex: "siteNum",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "机房编码",
|
|
|
|
|
+ dataIndex: "roomNum",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "项目经理",
|
|
|
|
|
+ render: (item: A2tableType) => {
|
|
|
|
|
+ if (item.pmUserId === 1) return "管理员";
|
|
|
|
|
+ else {
|
|
|
|
|
+ return item.pmName || "匿名";
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "最近编辑时间",
|
|
|
|
|
+ dataIndex: "updateTime",
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "录入方式",
|
|
|
|
|
+ render: (item: A2tableType) =>
|
|
|
|
|
+ item.typeIn === "pc"
|
|
|
|
|
+ ? "系统"
|
|
|
|
|
+ : item.typeIn === "app-scan"
|
|
|
|
|
+ ? "移动端扫码"
|
|
|
|
|
+ : "移动端手工",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: "操作",
|
|
|
|
|
+ render: (item: A2tableType) => (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ size="small"
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ onClick={() => setOpenInfo({ id: item.id, txt: "编辑" })}
|
|
|
|
|
+ >
|
|
|
|
|
+ 编辑
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ <Popconfirm
|
|
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
|
|
+ okText="删除"
|
|
|
|
|
+ cancelText="取消"
|
|
|
|
|
+ onConfirm={() => delByIdFu(item.id)}
|
|
|
|
|
+ okButtonProps={{ loading: false }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
|
|
+ 删除
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Popconfirm>
|
|
|
|
|
+ </>
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
|
|
+ }, [delByIdFu]);
|
|
|
|
|
+
|
|
|
|
|
+ const [openInfo, setOpenInfo] = useState<A1addType>({ id: 0, txt: "" });
|
|
|
|
|
+
|
|
|
|
|
+ // 点击导出
|
|
|
|
|
+ const deriveFu = useCallback(async () => {
|
|
|
|
|
+ if (A2TableList.list.length === 0)
|
|
|
|
|
+ return MessageFu.warning("当前搜索条件没有数据!");
|
|
|
|
|
+ const name = "机房管理" + dayjs(new Date()).format("YYYY-MM-DD HH:mm");
|
|
|
|
|
+
|
|
|
|
|
+ const res = await A2_APIgetlistDerive({
|
|
|
|
|
+ ...tableSelect,
|
|
|
|
|
+ site: tableSelect.site ? tableSelect.site[1] : null,
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 99999,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ const option = {
|
|
|
|
|
+ fileName: name,
|
|
|
|
|
+ datas: [
|
|
|
|
|
+ {
|
|
|
|
|
+ sheetData: res.data.records.map((v: A2tableType) => ({
|
|
|
|
|
+ ...v,
|
|
|
|
|
+ myCity:
|
|
|
|
|
+ !v.province && !v.city ? "(空)" : `${v.province} - ${v.city}`,
|
|
|
|
|
+ address: v.address ? v.address : "(空)",
|
|
|
|
|
+ pmName: v.pmUserId === 1 ? "管理员" : v.pmName || "匿名",
|
|
|
|
|
+ typeIn:
|
|
|
|
|
+ v.typeIn === "pc"
|
|
|
|
|
+ ? "系统"
|
|
|
|
|
+ : v.typeIn === "app-scan"
|
|
|
|
|
+ ? "移动端扫码"
|
|
|
|
|
+ : "移动端手工",
|
|
|
|
|
+ })),
|
|
|
|
|
+ sheetName: name,
|
|
|
|
|
+ sheetFilter: [
|
|
|
|
|
+ "myCity",
|
|
|
|
|
+ "address",
|
|
|
|
|
+ "name",
|
|
|
|
|
+ "siteNum",
|
|
|
|
|
+ "roomNum",
|
|
|
|
|
+ "pmName",
|
|
|
|
|
+ "updateTime",
|
|
|
|
|
+ "typeIn",
|
|
|
|
|
+ ],
|
|
|
|
|
+ sheetHeader: [
|
|
|
|
|
+ "站址地区",
|
|
|
|
|
+ "详细地址",
|
|
|
|
|
+ "站址名称",
|
|
|
|
|
+ "站址编号",
|
|
|
|
|
+ "机房编码",
|
|
|
|
|
+ "项目经理",
|
|
|
|
|
+ "最近编辑时间",
|
|
|
|
|
+ "录入方式",
|
|
|
|
|
+ ],
|
|
|
|
|
+ columnWidths: [10, 10, 10, 10, 10, 10, 10, 10],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const toExcel = new ExportJsonExcel(option); //new
|
|
|
|
|
+ toExcel.saveExcel(); //保存
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [A2TableList.list.length, tableSelect]);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className={styles.A2Psychz}>
|
|
<div className={styles.A2Psychz}>
|
|
|
- <h1>A2Psychz</h1>
|
|
|
|
|
|
|
+ <div className="pageTitle">
|
|
|
|
|
+ {openInfo.txt === "新增"
|
|
|
|
|
+ ? "新增机房"
|
|
|
|
|
+ : openInfo.txt === "编辑"
|
|
|
|
|
+ ? "编辑机房"
|
|
|
|
|
+ : "机房管理"}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {/* 顶部筛选 */}
|
|
|
|
|
+ <div className="A2top">
|
|
|
|
|
+ {/* 左侧输入框 */}
|
|
|
|
|
+ <div className="A2top1">
|
|
|
|
|
+ <div className="A2topRow">
|
|
|
|
|
+ <span>站址地区:</span>
|
|
|
|
|
+ <Cascader
|
|
|
|
|
+ value={tableSelect.site}
|
|
|
|
|
+ style={{ width: 160 }}
|
|
|
|
|
+ options={mapDataAll}
|
|
|
|
|
+ placeholder="全部"
|
|
|
|
|
+ onChange={(e) =>
|
|
|
|
|
+ setTableSelect({ ...tableSelect, site: e as string[] })
|
|
|
|
|
+ }
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="A2topRow">
|
|
|
|
|
+ <span>搜索项:</span>
|
|
|
|
|
+ <Input
|
|
|
|
|
+ key={inputKey}
|
|
|
|
|
+ maxLength={10}
|
|
|
|
|
+ style={{ width: 323 }}
|
|
|
|
|
+ placeholder="请输入站址名称/站置编号/机房编码,最多10字"
|
|
|
|
|
+ allowClear
|
|
|
|
|
+ onChange={(e) => txtChangeFu(e.target.value, "searchKey")}
|
|
|
|
|
+ />
|
|
|
|
|
+ </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>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="A2topRow">
|
|
|
|
|
+ <span>录入方式:</span>
|
|
|
|
|
+ <Select
|
|
|
|
|
+ style={{ width: 116 }}
|
|
|
|
|
+ value={tableSelect.typeIn}
|
|
|
|
|
+ onChange={(e) =>
|
|
|
|
|
+ setTableSelect({ ...tableSelect, typeIn: e, pageNum: 1 })
|
|
|
|
|
+ }
|
|
|
|
|
+ options={options1}
|
|
|
|
|
+ />
|
|
|
|
|
+ </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 }}
|
|
|
|
|
+ dataSource={A2TableList.list}
|
|
|
|
|
+ columns={columns}
|
|
|
|
|
+ rowKey="id"
|
|
|
|
|
+ pagination={{
|
|
|
|
|
+ showQuickJumper: true,
|
|
|
|
|
+ position: ["bottomCenter"],
|
|
|
|
|
+ showSizeChanger: true,
|
|
|
|
|
+ current: tableSelect.pageNum,
|
|
|
|
|
+ pageSize: tableSelect.pageSize,
|
|
|
|
|
+ total: A2TableList.total,
|
|
|
|
|
+ onChange: paginationChange(),
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ {/* 新增和编辑出来的页面 */}
|
|
|
|
|
+ {openInfo.id ? (
|
|
|
|
|
+ <AddPsychz
|
|
|
|
|
+ openInfo={openInfo}
|
|
|
|
|
+ closeFu={() => setOpenInfo({ id: 0, txt: "" })}
|
|
|
|
|
+ upTableFu={getListFu}
|
|
|
|
|
+ addTableFu={resetSelectFu}
|
|
|
|
|
+ />
|
|
|
|
|
+ ) : null}
|
|
|
</div>
|
|
</div>
|
|
|
- )
|
|
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const MemoA2Psychz = React.memo(A2Psychz);
|
|
const MemoA2Psychz = React.memo(A2Psychz);
|