更换schema,服务管理50%

This commit is contained in:
‘Liammcl’
2024-12-22 12:33:02 +08:00
parent 36db1f29b0
commit df0aa520ca
4 changed files with 322 additions and 91 deletions

View File

@@ -30,9 +30,10 @@ const ServiceForm = () => {
const isEdit = location.search.includes("edit=true");
const [editingSectionIndex, setEditingSectionIndex] = useState(null);
const [availableSections, setAvailableSections] = useState([]);
const [formValues, setFormValues] = useState({});
const [sectionNameForm] = Form.useForm();
const [formValues, setFormValues] = useState({
sections: [{ items: [{}] }],
currency: "CNY"
});
useEffect(() => {
if (id) {
fetchServiceTemplate();
@@ -50,11 +51,13 @@ const ServiceForm = () => {
.single();
if (error) throw error;
form.setFieldsValue({
const formData = {
templateName: data.attributes.templateName,
description: data.attributes.description,
sections: data.attributes.sections,
});
};
form.setFieldsValue(formData);
setFormValues(formData);
} catch (error) {
console.error("获取服务模版失败:", error);
message.error("获取服务模版失败");
@@ -96,6 +99,7 @@ const ServiceForm = () => {
templateName: values.templateName,
description: values.description,
sections: values.sections,
category: values.category || [], // 添加 category 字段
totalAmount,
},
};
@@ -279,7 +283,7 @@ const ServiceForm = () => {
disabled={id && !isEdit}
onValuesChange={handleValuesChange}
>
<div className="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 mb-6">
<div className="bg-white dark:bg-gray-800 p-2 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 mb-6">
<Title level={5} className="mb-4 dark:text-gray-200">
基本信息
</Title>
@@ -327,23 +331,12 @@ const ServiceForm = () => {
</div>
</div>
<div className="bg-white dark:bg-gray-800 p-6 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
<div className="bg-white dark:bg-gray-800 p-2 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
<div className="flex items-center justify-between mb-6">
<Title level={5} className="!mb-0 dark:text-gray-200">
报价明细
</Title>
{(!id || isEdit) && (
<Select
style={{ width: 200 }}
placeholder="选择已有小节"
onChange={handleAddExistingSection}
options={availableSections.map((section) => ({
value: section.id,
label: section.attributes.sectionName,
}))}
className="w-48"
/>
)}
</div>
<Form.List name="sections">
@@ -448,12 +441,7 @@ const ServiceForm = () => {
{...itemField}
name={[itemField.name, "name"]}
className="!mb-0"
rules={[
{
required: true,
message: "请输入服务项目名称",
},
]}
>
<Input placeholder="服务项目名称" />
</Form.Item>