/* eslint-disable no-return-assign */ /* eslint-disable no-return-assign */ import React, { useEffect, useState } from "react"; import { Modal, Form, Select, InputNumber, message, Spin, Radio, Input, Button } from "antd"; import { useStore } from "../index"; import { queryPostIndicatorApi, queryShopIndicatorApi } from "../api"; import _ from "lodash"; import useInitail from "@/hooks/useInitail"; import { EvaGroupSetteing } from "@/pages/performance/EvaGroupSetting/interface"; import { TargetType, TargetTypeEnum } from "@/pages/performance/entity"; const Option = Select.Option; interface Props { addComVisible: boolean; onCancel: Function; postId?: number; shopIds?: string; onOk: (vales: any) => void; comItem: Commission; setItemId: Function; scopeType: number; isOne: number; } type Commission = EvaGroupSetteing.CommissionParams; export default function AddLadderParamsModal(props: Props) { const percent = /^\d\.([1-9]{1,2}|[0-9][1-9])$|^[1-9]\d{0,1}(\.\d{1,2}){0,1}$|^100(\.0{1,2}){0,1}$/; const Momney = /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/; const [form] = Form.useForm(); const { selectedIndicatorsLadderSalShop, setSelectedIndicatorsLadderSalShop, setLadderParamAliasShop, multiStage } = useStore(); const [isTarget, setIsTarget] = useState(false); const [dataType, setDataType] = useState(2); // console.log(form); const { addComVisible, onCancel, postId, shopIds, onOk, comItem, setItemId, scopeType, isOne } = props; const [delay, setDelay] = useState(true); // 保存选中绩效指标需要配置的绩效考核目标值类型 const [targetType, setTargetType] = useState(); // 保存选中指标是否考评类型 const [codeType, setCodeType] = useState(); // 保存过滤后指标列表 const [newIndicators, setNewIndicators] = useState([]); const [name, setIndicatorName] = useState(""); const [id, setId] = useState(0); const { data: indicatorsList, setParams, loading } = useInitail(queryPostIndicatorApi, [], {}, delay); useEffect(() => { setParams({ reward: true, withCombination: true }, true); setDelay(false); setTargetType(1); }, [addComVisible]); // 修改 useEffect(() => { if (indicatorsList && indicatorsList.length > 0 && !comItem.code) { const res = indicatorsList.filter((item) => !selectedIndicatorsLadderSalShop.find((y) => y === item.code)); setNewIndicators([...res]); } if (addComVisible && comItem.code) { const indTar = indicatorsList.find((item: any) => item.code == comItem.code)?.targetType; setTargetType(indTar); setIndicatorName(comItem.name); setCodeType(comItem.codeType); form.setFieldsValue({ ...comItem, ladderParams: { value: comItem.code, label: comItem.name, dataType: comItem.dataType, }, proportion: comItem.proportion !== undefined ? comItem.proportion : isOne == 1 ? 100 : null, }); } if (comItem.targetValue && comItem.targetCalcType) { setIsTarget(true); } if (comItem.extraTargetValue && comItem.extraTargetCalcType) { setIsTarget(true); } }, [indicatorsList]); useEffect(() => { if (targetType === TargetTypeEnum["无"]) { setIsTarget(false); } }, [targetType]); useEffect(() => { setIsTarget(false); }, [id]); // 校验表单数据 function transformDTO(formData: any) { let detail = {}; _.each(formData, (value: any, key: string) => { switch (key) { case "ladderParams": const _options = value || {}; detail.name = _options.label[0]; detail.code = _options.value; break; default: detail[key] = value; break; } }); return detail; } function handSubmit(fieldsValue: any) { const pa: any = transformDTO(fieldsValue); if (pa.targetValue !== undefined) { pa.targetType = targetType; } else { pa.targetType = 1; } pa.codeType = codeType; if (comItem.dataType) { pa.dataType = comItem.dataType; } if (!comItem.dataType) { pa.dataType = dataType; } console.log("100pa", pa); const newItemId = pa.code; // 编辑时,不需要push id if (!comItem.code) { const tmpIds = [...selectedIndicatorsLadderSalShop]; tmpIds.push(newItemId); setSelectedIndicatorsLadderSalShop([...tmpIds]); } else { pa.code = comItem.code; pa.name = comItem.name; } onOk(pa); onCancel && onCancel(); } return ( { form.resetFields(); onCancel(); }} onCancel={() => onCancel()} onOk={form.submit} width={1000} >
{(targetType === TargetTypeEnum["百分比"] || targetType === TargetTypeEnum["金额"] || targetType === TargetTypeEnum["数量"]) && (
{isTarget && ( )}
)} {isTarget && ( <>