import react from "react"; import { useState } from "react"; import requests from "../../../utils/requests"; import { doPost } from "../../../utils/requests"; import { PlayIcon, StopIcon, PauseIcon, BellIcon, ViewListIcon, } from "@heroicons/react/outline"; import { BellIcon as BellIconS } from "@heroicons/react/solid"; import { PuzzleIcon } from "@heroicons/react/solid"; import VLabel from "../Header/VLabel"; import eqs from "../../../utils/eqs"; import { Tooltip } from 'antd'; const { eqstatus, orderstatus } = eqs; function Card({ eq, popHandle, alartPopHandle, classNamez, typecode, selectedTab, alertData, }) { if (!eq) { eq = {}; } const [status, setStatus] = useState(eqstatus[0]); const [alertcount, setAlertcount] = useState(0); const [fieldValueMap, setFieldValueMap] = react.useState({}); const [imgUrl, setImgUrl] = react.useState(null); // const [fields, setFields] = react.useState([]); react.useEffect(() => { if (eq.runningstatus === undefined) eq.runningstatus = 0; setStatus(eqstatus.filter((item) => item.key === eq.runningstatus)[0]); // console.log(eq.code,eq.runningstatus) }, [eq.runningstatus]); // eq.updatestatus=(statuscur)=>{ // setStatus(eqstatus.filter((item) => item.key === statuscur)[0]); // } react.useEffect(() => { //updatefields(); // if (eq.operationCode === typecode) { // setFields(eq.bmIotEquipmentRelationshipList); // } async function async1() { if (typecode === "1002") { let item = eq?.bmIotEquipmentRelationshipList.filter( (x) => x.iotField.indexOf("IoStatus") > -1 ); if (item && item.length > 0) { eq.runningstatus = item[0].iotFieldValue || item[0].iotFieldValue === 1 ? 2 : 4; } } } async1(); }, [typecode]); react.useEffect(() => { if (alertData && alertData.length > 0) { eq.alert = alertData.filter((al) => { if (al.equipCode === eq.code) { return al; } }); if(eq.alert.length>0) { let alertcout = eq?.alert?.filter((aa) => { if (!aa?.eliminationTime) { return aa; } }); eq.alertcount = alertcout.length; setAlertcount(alertcout.length); } } }, [alertData, selectedTab]); // react.useEffect(() => { // if(!eq.alertcount){ // eq.alertcount=0; // eq.alert= []; // } // else{ // setAlertcount(eq.alertcount); // } // }, [eq.alertcount, selectedTab]); react.useEffect(() => { }, [eq.alert]); react.useEffect(() => { if (eq.Img) { setImgUrl(eq.Img); } }, [eq.Img]); react.useEffect(() => {}, [eq.runningstatus]); react.useEffect(() => { // setTimeout(() => { // setFields(eq.bmIotEquipmentRelationshipList); // }, 100); }, [eq.bmIotEquipmentRelationshipList]); eq.updateFields = () => { // updatefields(); }; let updatefields = () => { if (!eq?.bmIotEquipmentRelationshipList) { if (!eq.code) { return; } doPost(requests.fetchEquipFields.url, [eq.code]) .then((res) => res.json()) .then((data) => { if (data.success) { // var fileGroupIds = curdata.map((zz) => zz.fileGroupId); //获取图片信息 if (data.data.length > 0) { var eqcur = data.data[0][0]; eq.bmIotEquipmentRelationshipList = eqcur.bmIotEquipmentRelationshipList; updateonlyfields(); } } }); } else { updateonlyfields(); } }; let updateonlyfields = () => { //接口请求物联网influxdb查询服务 doPost(requests.fetchLastFieldsValue.url, { equipCode: eq.code, fields: eq.bmIotEquipmentRelationshipList .filter((re) => { if (re.status && !re.iotIsalarm) { return re; } }) .map((field) => field.iotField), }) .then((res) => res.json()) .then((data) => { if (data.success) { if (data.data !== null && data.data !== []) { var _fieldValueMap = data.data[0]; if (!_fieldValueMap) return; eq.bmIotEquipmentRelationshipList.map((field) => { field.iotFieldValue = !(field.iotField in _fieldValueMap) ? null : _fieldValueMap[field.iotField]; if (field.iotIsalarm) { if (!field.iotFieldValue) field.iotFieldValue = 0; if (field.iotField.indexOf("IoStatus") > -1) { field.iotFieldValue = field.iotFieldValue === 1 ? true : false; } else { field.iotFieldValue = field.iotFieldValue === 0 ? false : true; } } }); if (eq.bmIotEquipmentRelationshipList) { var _alertcount = eq.bmIotEquipmentRelationshipList.filter( (re) => { if (re.iotIsalarm && re.status && re.iotFieldValue) { return re; } } ).length; // setAlertcount(_alertcount); setFieldValueMap(_fieldValueMap); } } } else { // console.log(data); } }) .catch((ex) => { console.log(ex); }); }; react.useEffect(() => { if (eq.code === null) return; //updatefields(); }, [eq]); react.useEffect(() => { //updatefields(); }, [eq.iotFieldValue]); let togglePop = () => { popHandle(eq); // setState((prevState) => ({ // ...prevState, // })); }; let alartPop = () => { alartPopHandle(eq); // setState((prevState) => ({ // ...prevState, // })); }; return (
{" "} {eq.code}
{/* {eq?.typeName} */}{" "} {eq.name}