|
@@ -1,57 +1,167 @@
|
|
|
-import { FC, useState } from "react";
|
|
|
+import { FC, useEffect, useMemo, useState } from "react";
|
|
|
import classNames from "classnames";
|
|
|
-import { Col, Form, Input, InputNumber, Radio, Row, Select } from "antd";
|
|
|
-import { useNavigate } from "react-router-dom";
|
|
|
+import {
|
|
|
+ Col,
|
|
|
+ Form,
|
|
|
+ Input,
|
|
|
+ InputNumber,
|
|
|
+ Radio,
|
|
|
+ Row,
|
|
|
+ Select,
|
|
|
+ TreeSelect,
|
|
|
+} from "antd";
|
|
|
+import { useLocation, useNavigate, useParams } from "react-router-dom";
|
|
|
import { FileTemplateTable, FormPageFooter, PageContainer } from "@/components";
|
|
|
import style from "./index.module.scss";
|
|
|
+import {
|
|
|
+ AssIndexTreeItemType,
|
|
|
+ ASS_INDEX_TYPE,
|
|
|
+ IAssIndexDetail,
|
|
|
+ YES_OR_NO,
|
|
|
+} from "@/types";
|
|
|
+import {
|
|
|
+ getAssIndexDetailApi,
|
|
|
+ getAssIndexTreeApi,
|
|
|
+ saveAssIndexApi,
|
|
|
+} from "@/api";
|
|
|
+import { CONNECT_WITH_SYMBOL_OPTIONS, SYMBOL_OPTIONS } from "../constants";
|
|
|
+import { isNull } from "lodash";
|
|
|
+import { DageLoading } from "@dage/pc-components";
|
|
|
|
|
|
const { TextArea } = Input;
|
|
|
const CONFIRM_OPTIONS = [
|
|
|
{
|
|
|
label: "是",
|
|
|
- value: 1,
|
|
|
+ value: YES_OR_NO.YES,
|
|
|
},
|
|
|
{
|
|
|
label: "否",
|
|
|
- value: 0,
|
|
|
+ value: YES_OR_NO.NO,
|
|
|
},
|
|
|
];
|
|
|
|
|
|
const CreateOrEditIndex: FC = () => {
|
|
|
+ const location = useLocation();
|
|
|
const navigate = useNavigate();
|
|
|
+ const query = new URLSearchParams(location.search);
|
|
|
+ const params = useParams();
|
|
|
const [form] = Form.useForm();
|
|
|
- const [fields, setFields] = useState<any[]>([
|
|
|
- {
|
|
|
- name: "dfd",
|
|
|
- value: 1,
|
|
|
- },
|
|
|
- {
|
|
|
- name: "gjqz",
|
|
|
- value: 1,
|
|
|
- },
|
|
|
- ]);
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
+ const [values, setValues] = useState<any>({
|
|
|
+ isPoint: YES_OR_NO.YES,
|
|
|
+ isWarn: YES_OR_NO.YES,
|
|
|
+ });
|
|
|
+ const [treeData, setTreeData] = useState<AssIndexTreeItemType[]>([]);
|
|
|
+ const isEdit = useMemo(
|
|
|
+ () => location.pathname.indexOf("edit") > -1,
|
|
|
+ [location]
|
|
|
+ );
|
|
|
+ const [detail, setDetail] = useState<null | IAssIndexDetail>(null);
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
if (!(await form.validateFields())) return;
|
|
|
|
|
|
- console.log(form.getFieldsValue());
|
|
|
+ const { materialIds, api, isAdd, score, warnData, ...rest } =
|
|
|
+ form.getFieldsValue();
|
|
|
+
|
|
|
+ if (materialIds)
|
|
|
+ rest.materialIds = materialIds.map((i: any) => i.id).join(",");
|
|
|
+ if (rest.isPoint === YES_OR_NO.YES) {
|
|
|
+ // 打分点
|
|
|
+ rest.jsonPoint = {
|
|
|
+ api,
|
|
|
+ isAdd,
|
|
|
+ score,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (rest.isWarn === YES_OR_NO.YES) {
|
|
|
+ // 告警阈值
|
|
|
+ rest.jsonWarn = JSON.stringify(warnData);
|
|
|
+ }
|
|
|
+
|
|
|
+ await saveAssIndexApi({
|
|
|
+ ...rest,
|
|
|
+ level: 1,
|
|
|
+ type: params.type,
|
|
|
+ id: detail?.id,
|
|
|
+ });
|
|
|
+ navigate(-1);
|
|
|
+ };
|
|
|
+
|
|
|
+ const getAssIndexTree = async () => {
|
|
|
+ const data = await getAssIndexTreeApi(params.type as ASS_INDEX_TYPE);
|
|
|
+ setTreeData(data);
|
|
|
+ };
|
|
|
+
|
|
|
+ const getDetail = async () => {
|
|
|
+ try {
|
|
|
+ setLoading(true);
|
|
|
+ const data = await getAssIndexDetailApi(Number(params.id));
|
|
|
+ const pointData =
|
|
|
+ data.isPoint === YES_OR_NO.YES ? JSON.parse(data.jsonPoint) : null;
|
|
|
+ const warnData =
|
|
|
+ data.isWarn === YES_OR_NO.YES ? JSON.parse(data.jsonWarn) : null;
|
|
|
+ setDetail(data);
|
|
|
+ form.setFieldsValue({
|
|
|
+ parentId: data.parentId,
|
|
|
+ name: data.name,
|
|
|
+ remark: data.remark,
|
|
|
+ num: data.num,
|
|
|
+ isPoint: data.isPoint,
|
|
|
+ isWarn: data.isWarn,
|
|
|
+ score: pointData?.score,
|
|
|
+ api: pointData?.api,
|
|
|
+ isAdd: pointData?.isAdd,
|
|
|
+ warnData,
|
|
|
+ materialIds: data.materials,
|
|
|
+ sort: data.sort,
|
|
|
+ });
|
|
|
+ setValues({
|
|
|
+ isPoint: data.isPoint,
|
|
|
+ isWarn: data.isWarn,
|
|
|
+ });
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ getAssIndexTree();
|
|
|
+
|
|
|
+ const parentId = query.get("parentId");
|
|
|
+ if (!isNull(parentId)) {
|
|
|
+ form.setFieldValue("parentId", parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isEdit) getDetail();
|
|
|
+ }, []);
|
|
|
+
|
|
|
return (
|
|
|
<PageContainer title="新增指标">
|
|
|
<Form
|
|
|
- fields={fields}
|
|
|
labelCol={{ span: 4 }}
|
|
|
form={form}
|
|
|
- onFieldsChange={(_, newFields) => {
|
|
|
- setFields(newFields);
|
|
|
- }}
|
|
|
onFinish={handleSubmit}
|
|
|
+ onValuesChange={(v, allValue) => {
|
|
|
+ setValues(allValue);
|
|
|
+ }}
|
|
|
>
|
|
|
- <Form.Item label="父级指标">
|
|
|
- <Select className="mw650" placeholder="请选择" options={[]} />
|
|
|
+ <Form.Item label="父级指标" name="parentId">
|
|
|
+ <TreeSelect
|
|
|
+ disabled={isEdit}
|
|
|
+ allowClear
|
|
|
+ className="mw650"
|
|
|
+ placeholder="请选择"
|
|
|
+ treeData={treeData}
|
|
|
+ fieldNames={{ label: "name", value: "id" }}
|
|
|
+ />
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="指标名称" required>
|
|
|
+ <Form.Item
|
|
|
+ label="指标名称"
|
|
|
+ required
|
|
|
+ name="name"
|
|
|
+ rules={[{ required: true, message: "请输入指标名称" }]}
|
|
|
+ >
|
|
|
<Input
|
|
|
className="mw650"
|
|
|
placeholder="请输入内容,最多20字"
|
|
@@ -59,7 +169,7 @@ const CreateOrEditIndex: FC = () => {
|
|
|
maxLength={20}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="指标编号">
|
|
|
+ <Form.Item label="指标编号" name="num">
|
|
|
<Input
|
|
|
className="mw650"
|
|
|
placeholder="请输入内容,最多20字"
|
|
@@ -67,7 +177,7 @@ const CreateOrEditIndex: FC = () => {
|
|
|
maxLength={20}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="指标说明">
|
|
|
+ <Form.Item label="指标说明" name="reamrk">
|
|
|
<TextArea
|
|
|
className="mw650"
|
|
|
showCount
|
|
@@ -77,7 +187,7 @@ const CreateOrEditIndex: FC = () => {
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|
|
|
- <Form.Item label="打分点" name="dfd">
|
|
|
+ <Form.Item label="打分点" name="isPoint" initialValue={values.isPoint}>
|
|
|
<Radio.Group
|
|
|
options={CONFIRM_OPTIONS}
|
|
|
optionType="button"
|
|
@@ -86,19 +196,31 @@ const CreateOrEditIndex: FC = () => {
|
|
|
</Form.Item>
|
|
|
<Form.Item label=" " colon={false} style={{ marginTop: -14 }}>
|
|
|
<div className={classNames("mw650", style.panel)}>
|
|
|
- {fields[0].value ? (
|
|
|
+ {Boolean(values.isPoint) ? (
|
|
|
<>
|
|
|
- <Form.Item required label="指标分值" labelCol={{ span: 4 }}>
|
|
|
+ <Form.Item
|
|
|
+ required
|
|
|
+ label="指标分值"
|
|
|
+ labelCol={{ span: 4 }}
|
|
|
+ name="score"
|
|
|
+ rules={[{ required: true, message: "请输入指标分值" }]}
|
|
|
+ >
|
|
|
<InputNumber
|
|
|
precision={0}
|
|
|
placeholder="请输入正整数"
|
|
|
className="w160"
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- <Form.Item label="数据API" labelCol={{ span: 4 }}>
|
|
|
+ <Form.Item label="数据API" labelCol={{ span: 4 }} name="api">
|
|
|
<Input placeholder="请输入地址" style={{ width: 427 }} />
|
|
|
</Form.Item>
|
|
|
<Form.Item label="加分项" labelCol={{ span: 4 }} colon={false}>
|
|
|
+ <Form.Item noStyle name="isAdd">
|
|
|
+ <Radio.Group>
|
|
|
+ <Radio value={1}>是</Radio>
|
|
|
+ <Radio value={0}>否</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ </Form.Item>
|
|
|
<span className={style.tips}>
|
|
|
注:设为加分项后,该指标的分值不会参与父级指标的计算
|
|
|
</span>
|
|
@@ -114,14 +236,14 @@ const CreateOrEditIndex: FC = () => {
|
|
|
</div>
|
|
|
</Form.Item>
|
|
|
|
|
|
- <Form.Item label="告警阈值" name="gjqz">
|
|
|
+ <Form.Item label="告警阈值" name="isWarn" initialValue={values.isWarn}>
|
|
|
<Radio.Group
|
|
|
options={CONFIRM_OPTIONS}
|
|
|
optionType="button"
|
|
|
buttonStyle="solid"
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
- {fields[1].value ? (
|
|
|
+ {Boolean(values.isWarn) ? (
|
|
|
<Form.Item label=" " colon={false} style={{ marginTop: -14 }}>
|
|
|
<div
|
|
|
className={classNames("mw650", style.panel)}
|
|
@@ -129,44 +251,57 @@ const CreateOrEditIndex: FC = () => {
|
|
|
>
|
|
|
<Row gutter={10}>
|
|
|
<Col span={8}>
|
|
|
- <Select placeholder="请选择" options={[]} />
|
|
|
+ <Form.Item
|
|
|
+ noStyle
|
|
|
+ name={["warnData", "symbol"]}
|
|
|
+ rules={[{ required: true, message: "" }]}
|
|
|
+ >
|
|
|
+ <Select placeholder="请选择" options={SYMBOL_OPTIONS} />
|
|
|
+ </Form.Item>
|
|
|
</Col>
|
|
|
<Col span={12}>
|
|
|
- <InputNumber
|
|
|
- precision={0}
|
|
|
- placeholder="请输入正整数"
|
|
|
- className="w100"
|
|
|
- />
|
|
|
+ <Form.Item
|
|
|
+ noStyle
|
|
|
+ name={["warnData", "num"]}
|
|
|
+ rules={[{ required: true, message: "" }]}
|
|
|
+ >
|
|
|
+ <InputNumber
|
|
|
+ precision={0}
|
|
|
+ placeholder="请输入正整数"
|
|
|
+ className="w100"
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
</Col>
|
|
|
<Col span={4}>
|
|
|
<span className={style.required}>(必填)</span>
|
|
|
</Col>
|
|
|
</Row>
|
|
|
|
|
|
- <Radio.Group
|
|
|
- options={[
|
|
|
- {
|
|
|
- label: "与",
|
|
|
- value: 0,
|
|
|
- },
|
|
|
- {
|
|
|
- label: "否",
|
|
|
- value: 1,
|
|
|
- },
|
|
|
- ]}
|
|
|
- style={{ margin: "3px 0" }}
|
|
|
- />
|
|
|
+ <Form.Item noStyle name={["warnData", "and"]}>
|
|
|
+ <Radio.Group
|
|
|
+ options={CONNECT_WITH_SYMBOL_OPTIONS}
|
|
|
+ style={{ margin: "3px 0" }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
|
|
|
<Row gutter={10}>
|
|
|
<Col span={8}>
|
|
|
- <Select placeholder="请选择" options={[]} />
|
|
|
+ <Form.Item noStyle name={["warnData", "symbol2"]}>
|
|
|
+ <Select
|
|
|
+ allowClear
|
|
|
+ placeholder="请选择"
|
|
|
+ options={SYMBOL_OPTIONS}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
</Col>
|
|
|
<Col span={12}>
|
|
|
- <InputNumber
|
|
|
- precision={0}
|
|
|
- placeholder="请输入正整数"
|
|
|
- className="w100"
|
|
|
- />
|
|
|
+ <Form.Item noStyle name={["warnData", "num2"]}>
|
|
|
+ <InputNumber
|
|
|
+ precision={0}
|
|
|
+ placeholder="请输入正整数"
|
|
|
+ className="w100"
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
</Col>
|
|
|
<Col span={4}></Col>
|
|
|
</Row>
|
|
@@ -176,11 +311,11 @@ const CreateOrEditIndex: FC = () => {
|
|
|
""
|
|
|
)}
|
|
|
|
|
|
- <Form.Item label="需上传资料">
|
|
|
+ <Form.Item label="需上传资料" name="materialIds">
|
|
|
<FileTemplateTable />
|
|
|
</Form.Item>
|
|
|
|
|
|
- <Form.Item required label="排序值">
|
|
|
+ <Form.Item required label="排序值" name="sort" initialValue={999}>
|
|
|
<InputNumber
|
|
|
precision={0}
|
|
|
min={1}
|
|
@@ -192,6 +327,8 @@ const CreateOrEditIndex: FC = () => {
|
|
|
|
|
|
<FormPageFooter onSubmit={handleSubmit} onCancel={() => navigate(-1)} />
|
|
|
</Form>
|
|
|
+
|
|
|
+ {loading && <DageLoading />}
|
|
|
</PageContainer>
|
|
|
);
|
|
|
};
|