import React, { useCallback, useEffect, useImperativeHandle, useRef, useState, } from "react"; import { Modal, Row, Col, Form, Input, Select, message } from "antd"; import { Button } from "../Button"; import { request } from "../utils"; const ModalClient = React.memo((props) => { const { visible = false, title, onOk = () => {}, onCancel = () => {}, children, } = props; return (
{title}
{children}
); }); // 设置 export const ModelSetting = React.forwardRef((props, ref) => { const {} = props; const callbackRef = useRef(() => {}); const [form] = Form.useForm(); const [visible, setVisible] = useState(false); const handleCancel = useCallback(() => setVisible(false), []); const [equipList, setEquipList] = useState([]); const [operationList, setOperationList] = useState([]); const [workShopList, setWorkShopList] = useState([]); // 查询包装机 const getEquip = useCallback((gid) => { if (gid) { request({ method: "POST", url: `${window.config.mesUrl}/mdgeneric/md/bmWorkCenter/getEquipByOperationGid?operationGid=${gid}`, }).then(({ data, success } = {}) => { if (!success) data = []; setEquipList(data); }); } }, []); // 工序变化 const onOperationChange = useCallback( (code, a, data) => { if (!data) data = operationList; // console.log("val", key, value, data); let {gid: operationGid, name} = data.find((item) => item.code === code) || {}; getEquip(operationGid); form.setFieldsValue({ operationName: name, operationCode: code, equipName: undefined, equipCode: undefined, }); setEquipList([]); }, [operationList, form, getEquip] ); // 查询工序 const getOperation = useCallback( (gid, callback) => { if (gid) { request({ method: "POST", url: `${window.config.mesUrl}/mdgeneric/md/bmWorkCenter/getOpByWorkCenter?workCenterGid=${gid}`, }).then(({ data, success } = {}) => { if (!success) data = []; setOperationList(data); if (callback) { callback(data); } else if (data.length) { let { name, code } = data[0]; form.setFieldsValue({ operationName: name, equipName: code, }); onOperationChange(code,undefined, data) } }); } else setOperationList([]); }, [onOperationChange] ); // 车间变化 const onWorkShopChange = useCallback( (key = {}) => { let { gid: workShopGid, name: value } = workShopList.find(({ code }) => code === key) || {}; getOperation(workShopGid); form.setFieldsValue({ workCenterCode: key, workCenterName: value, operationName: undefined, operationCode: undefined, equipName: undefined, equipCode: undefined, }); setOperationList([]); setEquipList([]); }, [workShopList, form, getOperation] ); // 查询车间 const getWorkShop = useCallback((callback) => { request({ method: "POST", url: `${window.config.mesUrl}/mdgeneric/md/bmWorkCenter/findAllWithPage`, bodys: { // removePermission: true, page: -1, pageSize: -1, sorted: "createTime desc", filter: "type eq 'workshop'", }, }).then(({ data, success } = {}) => { if (!success) data = []; setWorkShopList(data); callback && callback(data); }); }, []); // 设备变化 const onEquipChange = useCallback( (key) => { let { name: value} = equipList.find(({ code }) => code === key) || {} form.setFieldsValue({ equipName: value, equipCode: key, }); }, [form, equipList] ); // 初始化 const init = useCallback( (data, callback) => { setVisible(true); form.resetFields(); form.setFieldsValue(data); callbackRef.current = callback; let { workCenterCode, operationCode } = data; getWorkShop((res) => { if (workCenterCode) { let gid = res.find(({ code }) => code === workCenterCode)?.gid; getOperation(gid, (res) => { if (operationCode) { let gid = res.find(({ code }) => code === operationCode)?.gid; getEquip(gid); } }); } }); }, [form, getWorkShop, getOperation, getEquip] ); const handleOk = useCallback(() => { let formData = form.getFieldValue(); if (["", null, undefined].includes(formData.workCenterCode)) return message.error("请完善车间!"); if (["", null, undefined].includes(formData.equipCode)) return message.error("请完善包装机!"); if (["", null, undefined].includes(formData.bagWeight)) return message.error("请完善包装袋重量!"); if (["", null, undefined].includes(formData.packSpecs)) return message.error("请完包装规格!"); if (["", null, undefined].includes(formData.upperLimit)) return message.error("请完善上限值!"); if (["", null, undefined].includes(formData.lowerLimit)) return message.error("请完善下限值!"); // console.log("form", formData); return new Promise((resolve, reject) => { request({ url: `${window.config.mesUrl}/prodexec/prodexec/packageEquipment/setPackInfo`, bodys: formData, }).then((res) => { handleCancel(); callbackRef.current(); }) .finally(() => { resolve(); }); }); }, [handleCancel, form, workShopList, equipList]); useImperativeHandle( ref, () => ({ show: init, }), [init] ); return (
-
); }); // 中断 export const ModelBreak = React.forwardRef((props, ref) => { const {} = props; const callbackRef = useRef(() => {}); const [form] = Form.useForm(); const [visible, setVisible] = useState(false); const handleCancel = useCallback(() => setVisible(false), []); const handleOk = useCallback(() => { let formData = form.getFieldValue(); if (["", null, undefined].includes(formData.reason)) return message.error("请完善中断原因!"); return new Promise((resolve, reject) => { request({ url: `${window.config.mesUrl}/prodexec/prodexec/packageEquipment/interruptPack`, bodys: { gid: formData.gid, }, }) .then((res) => { if (res.success) { handleCancel(); callbackRef.current(); } else message.error(res.message || "操作失败!"); }) .finally(() => { resolve(); }); }); }, [handleCancel]); useImperativeHandle( ref, () => ({ show() { setVisible(true); }, show: (data, callback) => { setVisible(true); form.resetFields(); form.setFieldsValue(data); callbackRef.current = callback; }, }), [form] ); return (
); }); // 结束 export const ModelFinish = React.forwardRef((props, ref) => { const {} = props; const [form, setForm] = useState([]); const callbackRef = useRef(() => {}); const [visible, setVisible] = useState(false); const handleCancel = useCallback(() => setVisible(false), []); const handleOk = useCallback(() => { return new Promise((resolve, reject) => { request({ url: `${window.config.mesUrl}/prodexec/prodexec/packageEquipment/endPack`, bodys: form, }) .then((res) => { if (res.success) { handleCancel(); callbackRef.current(); message.success("包装完成!"); } else message.error(res.message || "操作失败!"); }) .finally(() => { resolve(); }); }); }, [handleCancel, form]); useImperativeHandle( ref, () => ({ show: (data, callback) => { setVisible(true); setForm(data); callbackRef.current = callback; }, }), [] ); return (

是否确认结束?

); }); // 超产 export const ModelOverproductionBatch = React.forwardRef((props, ref) => { const { } = props; const [form] = Form.useForm(); const codeRef = useRef(); const callbackRef = useRef(() => {}); const [visible, setVisible] = useState(false); const handleCancel = useCallback(() => setVisible(false), []); const handleOk = useCallback(() => { let formData = form.getFieldValue(); if (codeRef.current && codeRef.current === formData.outBatch) { message.error("超产批号不能与原单号一致!"); } else { callbackRef.current && callbackRef.current(formData.outBatch); handleCancel(); }; }, [handleCancel, form]); useImperativeHandle( ref, () => ({ show(code, callback) { codeRef.current = code; callbackRef.current = callback; setVisible(true); }, }), [] ); return (
); }); // 超量打印 export const ModelOverPrint = React.forwardRef((props, ref) => { const {} = props; const [form, setForm] = useState(""); const callbackRef = useRef(() => {}); const [visible, setVisible] = useState(false); const handleCancel = useCallback(() => setVisible(false), []); const handleOk = useCallback(() => { return callbackRef.current(handleCancel); }, [handleCancel, form]); useImperativeHandle( ref, () => ({ show: (data, callback) => { setVisible(true); setForm(data); callbackRef.current = callback; }, }), [] ); return (

{ form }

); });