Сделал первые функции под MRP

This commit is contained in:
2026-05-06 23:15:50 +03:00
parent 5417092796
commit 3b7a740081
27 changed files with 2996 additions and 767 deletions
+131 -30
View File
@@ -1,11 +1,20 @@
import { useState } from 'react';
import { createPart } from '../api';
import { useState } from "react";
import { createPart } from "../api";
export default function PartForm({ onCreated }) {
const initialState = {
id: '', destignation: '', order_no: '', material: '',
length: 0, width: 0, thickness: 0, quantity: 1,
product_name: '', status: 'Создан', name: ''
const initialState = {
designation: "",
order_no: "",
material: "",
length: 0,
width: 0,
length_first: 0,
width_first: 0,
thickness: 0,
quantity: 1,
product_name: "",
status: "Создан",
name: "",
};
const [formData, setFormData] = useState(initialState);
@@ -18,41 +27,133 @@ export default function PartForm({ onCreated }) {
...formData,
length: parseFloat(formData.length),
width: parseFloat(formData.width),
length_first: parseFloat(formData.length_first),
width_first: parseFloat(formData.width_first),
thickness: parseFloat(formData.thickness),
quantity: parseInt(formData.quantity)
quantity: parseInt(formData.quantity),
};
await createPart(dataToSend);
setFormData(initialState);
onCreated();
} catch (err) { alert("Ошибка: " + err.response?.data?.error); }
} catch (err) {
alert("Ошибка: " + err.response?.data?.error);
}
};
return (
<section className="bg-slate-800/80 rounded-3xl border border-slate-700 p-8 shadow-xl mb-8">
<h3 className="text-lg font-bold text-white mb-6">Регистрация новой панели</h3>
<form onSubmit={handleSubmit} className="grid grid-cols-1 md:grid-cols-4 gap-4">
<input placeholder="ID" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.id} onChange={e => setFormData({...formData, id: e.target.value})} required />
<input placeholder="Заказ №" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.order_no} onChange={e => setFormData({...formData, order_no: e.target.value})} required />
<input placeholder="Обозначение" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.destignation} onChange={e => setFormData({...formData, destignation: e.target.value})} required />
<input placeholder="Наименование" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.name} onChange={e => setFormData({...formData, name: e.target.value})} required />
<input placeholder="Изделие" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.product_name} onChange={e => setFormData({...formData, product_name: e.target.value})} required />
<h3 className="text-lg font-bold text-white mb-6">
Регистрация новой панели
</h3>
<form
onSubmit={handleSubmit}
className="grid grid-cols-1 md:grid-cols-4 gap-4"
>
<input
placeholder="Заказ №"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.order_no}
onChange={(e) =>
setFormData({ ...formData, order_no: e.target.value })
}
required
/>
<input
placeholder="Обозначение"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.designation}
onChange={(e) =>
setFormData({ ...formData, designation: e.target.value })
}
required
/>
<input
placeholder="Наименование"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
required
/>
<input
placeholder="Изделие"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.product_name}
onChange={(e) =>
setFormData({ ...formData, product_name: e.target.value })
}
required
/>
<input
placeholder="Материал"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.material}
onChange={(e) =>
setFormData({ ...formData, material: e.target.value })
}
required
/>
{/* Числовые поля */}
<input type="number" placeholder="L (Длина)" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={e => setFormData({...formData, length: e.target.value})} required />
<input type="number" placeholder="W (Ширина)" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={e => setFormData({...formData, width: e.target.value})} required />
<input type="number" placeholder="Кол-во" className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.quantity} onChange={e => setFormData({...formData, quantity: e.target.value})} required />
<button type="submit" className="bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-3 rounded-xl transition-all">ДОБАВИТЬ</button>
<input
type="number"
placeholder="L (Длина)"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={(e) => setFormData({ ...formData, length: e.target.value })}
required
/>
<input
type="number"
placeholder="W (Ширина)"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={(e) => setFormData({ ...formData, width: e.target.value })}
required
/>
<input
type="number"
placeholder="L (Длина заготовки)"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={(e) =>
setFormData({ ...formData, length_first: e.target.value })
}
required
/>
<input
type="number"
placeholder="W (Ширина заготовки)"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
onChange={(e) =>
setFormData({ ...formData, width_first: e.target.value })
}
required
/>
<input
type="number"
placeholder="Толщина"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.thickness}
onChange={(e) =>
setFormData({ ...formData, thickness: e.target.value })
}
required
/>
<input
type="number"
placeholder="Кол-во"
className="bg-slate-900 border border-slate-700 rounded-xl px-4 py-3 text-white"
value={formData.quantity}
onChange={(e) =>
setFormData({ ...formData, quantity: e.target.value })
}
required
/>
<button
type="submit"
className="bg-emerald-600 hover:bg-emerald-500 text-white font-bold py-3 rounded-xl transition-all"
>
ДОБАВИТЬ
</button>
</form>
</section>
);
}