| | |
| | | labelWidth: { |
| | | type: Number, |
| | | default: 120 |
| | | }, |
| | | /** 本次生产数量(成型工序用于计算投入重量) */ |
| | | quantity: { |
| | | type: Number, |
| | | default: null |
| | | }, |
| | | /** 当前工序是否为「成型」 */ |
| | | isFormingProcess: { |
| | | type: Boolean, |
| | | default: false |
| | | }, |
| | | /** 工单 BOM 投入重量,非成型工序回显到「投入重量」 */ |
| | | bomInputQty: { |
| | | type: Number, |
| | | default: null |
| | | } |
| | | }); |
| | | |
| | |
| | | deviceOptions.value = data; |
| | | }; |
| | | |
| | | const normalizeUnit = (unit) => String(unit ?? "").trim().toLowerCase(); |
| | | |
| | | const isInputWeightItem = (item) => |
| | | String(item?.parameterItem ?? "").includes("投入重量") && |
| | | normalizeUnit(item?.unit) === "kg"; |
| | | |
| | | const isBlankCoeffItem = (item) => |
| | | String(item?.parameterItem ?? "").includes("生坯系数") && |
| | | normalizeUnit(item?.unit) === "g"; |
| | | |
| | | /** 投入重量(KG) = 本次生产数量 × 生坯系数(g) / 1000 */ |
| | | const syncFormingInputWeight = () => { |
| | | if (!props.isFormingProcess) return; |
| | | const weightItem = formData.list.find(isInputWeightItem); |
| | | if (!weightItem) return; |
| | | |
| | | const qty = Number(props.quantity); |
| | | const coeffItem = formData.list.find(isBlankCoeffItem); |
| | | const coeff = coeffItem?.value === null || coeffItem?.value === undefined || coeffItem?.value === "" |
| | | ? NaN |
| | | : Number(coeffItem.value); |
| | | |
| | | if (!Number.isFinite(qty) || qty < 1 || !Number.isFinite(coeff)) { |
| | | return; |
| | | } |
| | | |
| | | weightItem.value = Number(((qty * coeff) / 1000).toFixed(4)); |
| | | }; |
| | | |
| | | /** 非成型:投入重量取工单 bomInputQty */ |
| | | const syncBomInputWeight = () => { |
| | | if (props.isFormingProcess) return; |
| | | const weightItem = formData.list.find(isInputWeightItem); |
| | | if (!weightItem) return; |
| | | const bom = props.bomInputQty; |
| | | if (bom === null || bom === undefined || Number.isNaN(Number(bom))) { |
| | | return; |
| | | } |
| | | weightItem.value = Number(bom); |
| | | }; |
| | | |
| | | const syncInputWeight = () => { |
| | | if (props.isFormingProcess) { |
| | | syncFormingInputWeight(); |
| | | } else { |
| | | syncBomInputWeight(); |
| | | } |
| | | }; |
| | | |
| | | const initData = () => { |
| | | formData.list = props.list || []; |
| | | formData.list.forEach(item => { |
| | |
| | | item.value = null; |
| | | } |
| | | }); |
| | | loadDeviceName() |
| | | loadDeviceName(); |
| | | syncInputWeight(); |
| | | }; |
| | | |
| | | const submitData = async () => { |
| | |
| | | {immediate: true, deep: true} |
| | | ); |
| | | |
| | | watch( |
| | | () => [props.quantity, props.isFormingProcess], |
| | | () => { |
| | | if (props.isFormingProcess) { |
| | | syncFormingInputWeight(); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | watch( |
| | | () => { |
| | | const coeffItem = formData.list.find(isBlankCoeffItem); |
| | | return coeffItem?.value; |
| | | }, |
| | | () => { |
| | | if (props.isFormingProcess) { |
| | | syncFormingInputWeight(); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | watch( |
| | | () => [props.bomInputQty, props.isFormingProcess], |
| | | () => { |
| | | if (!props.isFormingProcess) { |
| | | syncBomInputWeight(); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | defineExpose({ |
| | | submitData |
| | | submitData, |
| | | syncFormingInputWeight, |
| | | syncBomInputWeight, |
| | | syncInputWeight |
| | | }) |
| | | </script> |
| | | |