import React, { useRef, useEffect, useState, useMemo } from "react"; import { SearchOutlined } from "@ant-design/icons"; import _, { indexOf } from "lodash"; import moment from "moment"; import "antd/dist/antd.css"; import { Select, Button, DatePicker, Checkbox, message, Spin } from "antd"; const { Option } = Select; import { getFactory, getEquipType, getEquip, getEquipmentLocation, getEquipmentLocationEchart, } from "../../../reportUtils/getQueryData"; function CurveParam() { //HTML元素 let refinput = useRef(); //常量 const [factoryValue, setFactoryValue] = useState(""); const [factory, setFactory] = useState([]); const [equipTypeValue, setEquipTypeValue] = useState(""); const [equipType, setEquipType] = useState([]); const [equipValue, setEquipValue] = useState(""); const [equip, setEquip] = useState([]); // 点位集合 const [locations, setLocations] = useState([]); // 点位变化值 const [locationValue, setLocationValue] = useState([]); //react render useEffect(() => { let _locationValue = locationValue; // iframe 消息通讯 let locationsValues = _.cloneDeep(locations); let retData = {}; let selectItems = []; _locationValue.map((key) => { let index = _.findIndex(locationsValues, function (o) { return o.value === key; }); selectItems.push(locationsValues[index]); }); retData.selectItems = selectItems; retData.equipCode = equipValue; console.log(retData); if (retData.selectItems?.length > 0) { window.parent.postMessage(retData, "*"); } }, [locationValue]); // 查询设备类型,查询车间, useEffect(() => { getEquipType().then((data) => { setEquipType(data); }); getFactory().then((data) => { setFactory(data); }); }, []); // 查询设备 监听设备类型 useEffect(() => { getEquip({ equipTypeValue, factoryValue }).then((data) => { setEquip(data); setEquipValue(""); setLocations([]); setLocationValue([]); }); }, [equipTypeValue, factoryValue]); //方法 const locationChange = (checkValue) => { setLocationValue(checkValue); }; const handleCancelClick = () => { setLocationValue([]); }; const equipTypeChange = (value) => { setEquipTypeValue(value); }; const factoryChange = (value) => { setFactoryValue(value); }; const equipChange = (value = "") => { if (value && equipValue !== value) { setLocationValue([]); getEquipmentLocation(value).then((data) => { let locationArr = data .sort((a, b) => (a.iotfieldsort > b.iotfieldsort ? 1 : -1)) .map((item) => { return { label: item.iotfielddescribe, value: item.iotField, }; }); setLocations(locationArr); }); } else { setLocationValue([]); setLocations([]); } setEquipValue(value); }; return (