import React, { useEffect, useState } from "react"; import { Button, Descriptions, Form, Input, InputNumber, message, Modal, Row, Col, Table, Tag, Select, Space, } from "antd"; import { PlusOutlined } from "@ant-design/icons"; import PageLayout from "@cqsjjb/jjb-react-admin-component/PageLayout"; import TableAction from "@cqsjjb/jjb-react-admin-component/TableAction"; import SearchForm from "@cqsjjb/jjb-react-admin-component/SearchForm"; import ControlWrapper from "@cqsjjb/jjb-react-admin-component/ControlWrapper"; import { AntdTableFuncControl } from "@cqsjjb/jjb-common-decorator/antd"; import { tools } from "@cqsjjb/jjb-common-lib"; import { Connect } from "@cqsjjb/jjb-dva-runtime"; import { NS_EQUIP_INFO } from "~/enumerate/namespace"; import { positiveNumberRule } from "~/utils/validators"; const { router } = tools; const DUAL_CHANNEL_MAP = { 1: "是", 0: "否" }; function EquipInfoPage(props) { const [formModalOpen, setFormModalOpen] = useState(false); const [viewModalOpen, setViewModalOpen] = useState(false); const [currentId, setCurrentId] = useState(""); const [searchForm] = Form.useForm(); const { equipInfo } = props; const { equipInfoList: dataSource, equipInfoTotal: total, equipInfoLoading: loading, } = equipInfo || {}; const handleSearch = () => { props.equipInfoList({ ...router.query, }); }; useEffect(() => { searchForm.setFieldsValue(router.query); handleSearch(); }, []); const onDelete = (id) => { Modal.confirm({ title: "提示", content: "数据将会删除,您是否确认删除?", okText: "是", cancelText: "否", onOk: async () => { const res = await props.equipInfoRemove({ id }); if (res?.success !== false) { message.success("删除成功"); handleSearch(); } }, }); }; const onToggleStatus = (id, record) => { const enabled = record.enableFlag === 1; Modal.confirm({ title: "提示", content: enabled ? "是否停用" : "是否启用", okText: "是", cancelText: "否", onOk: async () => { const nextFlag = enabled ? 2 : 1; const res = await props.equipInfoToggleStatus({ id, enableFlag: nextFlag, }); if (res?.success !== false) { message.success("操作成功"); handleSearch(); } else { message.error(res?.message || "操作失败"); } }, }); }; return ( } onClick={() => { setCurrentId(""); setFormModalOpen(true); }} > 新增装备 } > , 分析仪器 检测仪器 采样设备 物理仪器 , 固定式 便携式 , 启用 禁用 , ]} onReset={(value) => { router.query = { ...value, current: 1, size: 10 }; handleSearch(); }} onFinish={(value) => { router.query = { ...value, current: 1, size: 10 }; handleSearch(); }} /> { const enabled = record.enableFlag === 1; return ( {enabled ? "启用" : "禁用"} ); }, }, { title: "操作", width: 180, fixed: "right", render: (_, record) => ( ), }, ]} dataSource={dataSource} scroll={{ y: props.scrollY, x: 1600 }} loading={loading} pagination={{ total, showSizeChanger: true, showQuickJumper: true, showTotal: (t) => `共 ${t} 条`, current: router.query.current || 1, pageSize: router.query.size || 10, onChange: (page, pageSize) => { router.query = { ...router.query, current: page, size: pageSize }; handleSearch(); }, }} /> {formModalOpen && ( { setFormModalOpen(false); setCurrentId(""); }} onSuccess={handleSearch} /> )} {viewModalOpen && ( { setViewModalOpen(false); setCurrentId(""); }} /> )} ); } function EquipFormModal({ open, currentId, equipInfoGet, equipInfoAdd, equipInfoEdit, onCancel, onSuccess, }) { const [form] = Form.useForm(); const [submitting, setSubmitting] = useState(false); const [detailLoading, setDetailLoading] = useState(false); useEffect(() => { if (!open) return; if (!currentId) { form.resetFields(); return; } let cancelled = false; setDetailLoading(true); equipInfoGet({ id: currentId }) .then((res) => { if (cancelled) return; const data = res?.data || {}; form.setFieldsValue(data); }) .finally(() => { if (!cancelled) setDetailLoading(false); }); return () => { cancelled = true; }; }, [open, currentId]); const handleCancel = () => { form.resetFields(); onCancel(); }; const handleSubmit = async (values) => { try { setSubmitting(true); if (currentId) values.id = currentId; const res = await (currentId ? equipInfoEdit(values) : equipInfoAdd(values)); if (res?.success !== false) { message.success(currentId ? "编辑成功" : "添加成功"); handleCancel(); onSuccess(); } else { message.error(res?.message || "操作失败"); } } finally { setSubmitting(false); } }; return (