feat:服务模版 抽离
This commit is contained in:
@@ -83,7 +83,7 @@ const CustomerForm = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-2">
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-2">
|
||||
<Card
|
||||
className="shadow-lg rounded-lg border-0"
|
||||
title={
|
||||
|
||||
@@ -629,7 +629,7 @@ const QuotationForm = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-2">
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white dark:from-gray-800 dark:to-gray-900/90 min-h-screen p-2">
|
||||
<Card
|
||||
className="shadow-lg rounded-lg border-0"
|
||||
title={
|
||||
|
||||
@@ -1,26 +1,56 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Table, Button, Form, Input, Space, message, Popconfirm, Drawer } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { supabase } from '@/config/supabase';
|
||||
import { Table, Button, Form, Input, Space, message, Popconfirm, Drawer, Select, Tabs, Badge, Radio } from 'antd';
|
||||
import { PlusOutlined, FileTextOutlined, ProjectOutlined, CheckSquareOutlined } from '@ant-design/icons';
|
||||
import { supabaseService } from '@/hooks/supabaseService';
|
||||
|
||||
const CategoryDrawer = () => {
|
||||
const [data, setData] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [editingKey, setEditingKey] = useState('');
|
||||
const [drawerVisible, setDrawerVisible] = useState(false);
|
||||
const [activeType, setActiveType] = useState('quotation'); // 当前选中的类型
|
||||
const [form] = Form.useForm();
|
||||
|
||||
// 模板类型配置
|
||||
const TEMPLATE_TYPES = [
|
||||
{
|
||||
value: 'quotation',
|
||||
label: '报价单模板',
|
||||
icon: <FileTextOutlined className="text-blue-500" />,
|
||||
color: 'blue',
|
||||
description: '用于创建标准化的报价单'
|
||||
},
|
||||
{
|
||||
value: 'project',
|
||||
label: '专案模板',
|
||||
icon: <ProjectOutlined className="text-green-500" />,
|
||||
color: 'green',
|
||||
description: '用于创建项目流程模板'
|
||||
},
|
||||
{
|
||||
value: 'task',
|
||||
label: '任务模板',
|
||||
icon: <CheckSquareOutlined className="text-purple-500" />,
|
||||
color: 'purple',
|
||||
description: '用于创建标准任务模板'
|
||||
}
|
||||
];
|
||||
|
||||
// 获取分类数据
|
||||
const fetchCategories = async () => {
|
||||
const fetchCategories = async (type = activeType) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data: categories, error } = await supabase
|
||||
.from('resources')
|
||||
.select('*')
|
||||
.eq('type', 'categories')
|
||||
.order('created_at', { ascending: false });
|
||||
const { data: categories } = await supabaseService.select('resources', {
|
||||
filter: {
|
||||
type: { eq: 'categories' },
|
||||
'attributes->>type': { eq: type }
|
||||
},
|
||||
order: {
|
||||
column: 'created_at',
|
||||
ascending: false
|
||||
}
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
setData(categories || []);
|
||||
} catch (error) {
|
||||
message.error('获取分类数据失败');
|
||||
@@ -34,13 +64,23 @@ const CategoryDrawer = () => {
|
||||
if (drawerVisible) {
|
||||
fetchCategories();
|
||||
}
|
||||
}, [drawerVisible]);
|
||||
}, [drawerVisible, activeType]);
|
||||
|
||||
// 切换模板类型
|
||||
const handleTypeChange = (type) => {
|
||||
setActiveType(type);
|
||||
setEditingKey(''); // 清除编辑状态
|
||||
form.resetFields(); // 重置表单
|
||||
};
|
||||
|
||||
// 新增分类
|
||||
const handleAdd = () => {
|
||||
const handleAdd = (type) => {
|
||||
const newData = {
|
||||
id: Date.now().toString(),
|
||||
attributes: { name: '' },
|
||||
attributes: {
|
||||
name: '',
|
||||
type: type // 默认类型
|
||||
},
|
||||
isNew: true
|
||||
};
|
||||
setData([newData, ...data]);
|
||||
@@ -53,31 +93,26 @@ const CategoryDrawer = () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
if (record.isNew) {
|
||||
// 新增
|
||||
const { error } = await supabase
|
||||
.from('resources')
|
||||
.insert([{
|
||||
type: 'categories',
|
||||
attributes: {
|
||||
name: values.name
|
||||
},
|
||||
schema_version: 1
|
||||
}]);
|
||||
|
||||
if (error) throw error;
|
||||
await supabaseService.insert('resources', {
|
||||
type: 'categories',
|
||||
attributes: {
|
||||
name: values.name,
|
||||
type: values.type
|
||||
},
|
||||
schema_version: 1
|
||||
});
|
||||
} else {
|
||||
// 更新
|
||||
const { error } = await supabase
|
||||
.from('resources')
|
||||
.update({
|
||||
await supabaseService.update('resources',
|
||||
{ id: record.id },
|
||||
{
|
||||
attributes: {
|
||||
name: values.name
|
||||
name: values.name,
|
||||
type: values.type
|
||||
},
|
||||
updated_at: new Date().toISOString()
|
||||
})
|
||||
.eq('id', record.id);
|
||||
|
||||
if (error) throw error;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
message.success('保存成功');
|
||||
@@ -92,12 +127,7 @@ const CategoryDrawer = () => {
|
||||
// 删除分类
|
||||
const handleDelete = async (record) => {
|
||||
try {
|
||||
const { error } = await supabase
|
||||
.from('resources')
|
||||
.delete()
|
||||
.eq('id', record.id);
|
||||
|
||||
if (error) throw error;
|
||||
await supabaseService.delete('resources', { id: record.id });
|
||||
message.success('删除成功');
|
||||
fetchCategories();
|
||||
} catch (error) {
|
||||
@@ -125,6 +155,29 @@ const CategoryDrawer = () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '模板类型',
|
||||
dataIndex: ['attributes', 'type'],
|
||||
render: (text, record) => {
|
||||
const isEditing = record.id === editingKey;
|
||||
return isEditing ? (
|
||||
<Form.Item
|
||||
name="type"
|
||||
style={{ margin: 0 }}
|
||||
rules={[{ required: true, message: '请选择模板类型!' }]}
|
||||
>
|
||||
<Select
|
||||
options={TEMPLATE_TYPES}
|
||||
placeholder="请选择模板类型"
|
||||
/>
|
||||
</Form.Item>
|
||||
) : (
|
||||
<span className="text-gray-600">
|
||||
{TEMPLATE_TYPES.find(t => t.value === text)?.label || text}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (_, record) => {
|
||||
@@ -161,13 +214,14 @@ const CategoryDrawer = () => {
|
||||
setEditingKey(record.id);
|
||||
form.setFieldsValue({
|
||||
name: record.attributes.name,
|
||||
type: record.attributes.type
|
||||
});
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确认删除"
|
||||
title="确认<EFBFBD><EFBFBD><EFBFBD>除"
|
||||
description="确定要删除这个分类吗?"
|
||||
onConfirm={() => handleDelete(record)}
|
||||
okText="确定"
|
||||
@@ -209,14 +263,56 @@ const CategoryDrawer = () => {
|
||||
className="category-drawer"
|
||||
>
|
||||
<div className="p-6">
|
||||
{/* 类型选择器 */}
|
||||
<div className="mb-6">
|
||||
<Radio.Group
|
||||
value={activeType}
|
||||
onChange={(e) => handleTypeChange(e.target.value)}
|
||||
className="flex space-x-4"
|
||||
>
|
||||
{TEMPLATE_TYPES.map(type => (
|
||||
<Radio.Button
|
||||
key={type.value}
|
||||
value={type.value}
|
||||
className={`flex items-center px-4 py-2 ${
|
||||
activeType === type.value ? `bg-${type.color}-50 border-${type.color}-500` : ''
|
||||
}`}
|
||||
>
|
||||
<span className="flex items-center space-x-2">
|
||||
{type.icon}
|
||||
<span>{type.label}</span>
|
||||
<Badge
|
||||
count={data.filter(item => item.attributes.type === type.value).length}
|
||||
className={`bg-${type.color}-100 text-${type.color}-600`}
|
||||
/>
|
||||
</span>
|
||||
</Radio.Button>
|
||||
))}
|
||||
</Radio.Group>
|
||||
</div>
|
||||
|
||||
{/* 当前类型说明 */}
|
||||
<div className="mb-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
|
||||
<h3 className={`text-${TEMPLATE_TYPES.find(t => t.value === activeType)?.color}-500 text-lg font-medium mb-2 flex items-center`}>
|
||||
{TEMPLATE_TYPES.find(t => t.value === activeType)?.icon}
|
||||
<span className="ml-2">{TEMPLATE_TYPES.find(t => t.value === activeType)?.label}</span>
|
||||
</h3>
|
||||
<p className="text-gray-500 dark:text-gray-400">
|
||||
{TEMPLATE_TYPES.find(t => t.value === activeType)?.description}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 新增按钮 */}
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleAdd}
|
||||
onClick={() => handleAdd(activeType)}
|
||||
className="mb-4"
|
||||
icon={<PlusOutlined />}
|
||||
>
|
||||
新增分类
|
||||
</Button>
|
||||
|
||||
{/* 分类列表 */}
|
||||
<Form form={form}>
|
||||
<Table
|
||||
scroll={{ x: true }}
|
||||
@@ -228,7 +324,7 @@ const CategoryDrawer = () => {
|
||||
pageSize: 10,
|
||||
showTotal: (total) => `共 ${total} 条`,
|
||||
}}
|
||||
className="bg-white rounded-lg shadow"
|
||||
className="bg-white dark:bg-gray-800 rounded-lg shadow"
|
||||
/>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import { Form, Card } from 'antd';
|
||||
|
||||
const ProjectTemplate = ({ form, id, isView }) => {
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
disabled={isView}
|
||||
>
|
||||
{/* 专案模板特有的字段和组件 */}
|
||||
<Card>
|
||||
{/* 项目阶段、时间线等内容 */}
|
||||
</Card>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProjectTemplate;
|
||||
@@ -0,0 +1,222 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Form, Card, Input, Select, message,Button } from 'antd';
|
||||
import { supabaseService } from '@/hooks/supabaseService';
|
||||
import {ArrowLeftOutlined}from '@ant-design/icons'
|
||||
import SectionList from '@/components/SectionList';
|
||||
|
||||
const QuotationTemplate = ({ id, isView, onCancel,isEdit }) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formValues, setFormValues] = useState({
|
||||
sections: [{ items: [{}] }],
|
||||
currency: "CNY"
|
||||
});
|
||||
const [categories, setCategories] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(id,'id');
|
||||
|
||||
if (id) {
|
||||
fetchServiceTemplate();
|
||||
}
|
||||
fetchCategories();
|
||||
}, [id]);
|
||||
|
||||
const fetchServiceTemplate = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data } = await supabaseService.select('resources', {
|
||||
filter: {
|
||||
id: { eq: id },
|
||||
type: { eq: 'serviceTemplate' },
|
||||
'attributes->>type': { eq: 'quotation' }
|
||||
}
|
||||
});
|
||||
console.log(data,'data');
|
||||
|
||||
if (data?.[0]) {
|
||||
const formData = {
|
||||
templateName: data[0].attributes.templateName,
|
||||
description: data[0].attributes.description,
|
||||
category: data[0].attributes.category?.map(v => v.id) || [],
|
||||
sections: data[0].attributes.sections || [{ items: [{}] }],
|
||||
currency: data[0].attributes.currency || "CNY",
|
||||
};
|
||||
form.setFieldsValue(formData);
|
||||
setFormValues(formData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取服务模版失败:", error);
|
||||
message.error("获取服务模版失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCategories = async () => {
|
||||
try {
|
||||
const { data } = await supabaseService.select('resources', {
|
||||
filter: {
|
||||
type: { eq: 'categories' },
|
||||
'attributes->>type': { eq: 'quotation' }
|
||||
},
|
||||
order: {
|
||||
column: 'created_at',
|
||||
ascending: false
|
||||
}
|
||||
});
|
||||
|
||||
const formattedCategories = (data || []).map(category => ({
|
||||
value: category.id,
|
||||
label: category.attributes.name
|
||||
}));
|
||||
|
||||
setCategories(formattedCategories);
|
||||
} catch (error) {
|
||||
message.error('获取分类数据失败');
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleValuesChange = (changedValues, allValues) => {
|
||||
setFormValues(allValues);
|
||||
};
|
||||
|
||||
const onFinish = async (values) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const categoryData = values.category.map(categoryId => {
|
||||
const category = categories.find(c => c.value === categoryId);
|
||||
return {
|
||||
id: categoryId,
|
||||
name: category.label
|
||||
};
|
||||
});
|
||||
|
||||
const serviceData = {
|
||||
type: "serviceTemplate",
|
||||
attributes: {
|
||||
type: "quotation",
|
||||
templateName: values.templateName,
|
||||
description: values.description,
|
||||
sections: values.sections,
|
||||
category: categoryData,
|
||||
},
|
||||
};
|
||||
|
||||
if (id) {
|
||||
// 更新
|
||||
await supabaseService.update('resources',
|
||||
{ id },
|
||||
serviceData
|
||||
);
|
||||
} else {
|
||||
// 新增
|
||||
await supabaseService.insert('resources', serviceData);
|
||||
}
|
||||
|
||||
message.success("保存成功");
|
||||
onCancel();
|
||||
} catch (error) {
|
||||
console.error("保存失败:", error);
|
||||
message.error("保存失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={onFinish}
|
||||
onValuesChange={handleValuesChange}
|
||||
layout="vertical"
|
||||
variant="filled"
|
||||
disabled={isView}
|
||||
>
|
||||
<Card
|
||||
className="shadow-sm rounded-lg mb-6"
|
||||
type="inner"
|
||||
title={
|
||||
<span className="flex items-center space-x-2 text-gray-700">
|
||||
<span className="w-1 h-4 bg-blue-500 rounded-full" />
|
||||
<span>基本信息</span>
|
||||
</span>
|
||||
}
|
||||
bordered={false}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<Form.Item
|
||||
label="模版名称"
|
||||
name="templateName"
|
||||
rules={[{ required: true, message: "请输入模版名称" }]}
|
||||
>
|
||||
<Input placeholder="请输入模版名称" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="模版分类"
|
||||
name="category"
|
||||
rules={[{ required: true, message: "请选择或输入分类" }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择或输入分类"
|
||||
showSearch
|
||||
allowClear
|
||||
mode="tags"
|
||||
options={categories}
|
||||
loading={loading}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="模版描述"
|
||||
name="description"
|
||||
className="col-span-2"
|
||||
>
|
||||
<Input.TextArea rows={4} placeholder="请输入模版描述" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
className="shadow-sm rounded-lg"
|
||||
type="inner"
|
||||
title={
|
||||
<span className="flex items-center space-x-2 text-gray-700">
|
||||
<span className="w-1 h-4 bg-blue-500 rounded-full" />
|
||||
<span>服务明细</span>
|
||||
</span>
|
||||
}
|
||||
bordered={false}
|
||||
>
|
||||
<SectionList
|
||||
form={form}
|
||||
isView={isView}
|
||||
formValues={formValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
/>
|
||||
</Card>
|
||||
<div className="flex justify-end space-x-4">
|
||||
<Button
|
||||
icon={<ArrowLeftOutlined />}
|
||||
onClick={onCancel}
|
||||
>
|
||||
返回
|
||||
</Button>
|
||||
{!isView && (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => form.submit()}
|
||||
loading={loading}
|
||||
>
|
||||
保存
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default QuotationTemplate;
|
||||
19
src/pages/company/service/detail/components/TaskTemplate.jsx
Normal file
19
src/pages/company/service/detail/components/TaskTemplate.jsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import { Form, Card } from 'antd';
|
||||
|
||||
const TaskTemplate = ({ form, id, isView }) => {
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
disabled={isView}
|
||||
>
|
||||
{/* 任务模板特有的字段和组件 */}
|
||||
<Card>
|
||||
{/* 任务步骤、检查项等内容 */}
|
||||
</Card>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaskTemplate;
|
||||
@@ -1,251 +1,71 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import {
|
||||
Card,
|
||||
Form,
|
||||
Input,
|
||||
Select,
|
||||
Button,
|
||||
Space,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import {
|
||||
ArrowLeftOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useNavigate, useParams,useSearchParams, useLocation } from "react-router-dom";
|
||||
import { supabase } from "@/config/supabase";
|
||||
import SectionList from '@/components/SectionList';
|
||||
import React from 'react';
|
||||
import { Card, Typography } from 'antd';
|
||||
import { useNavigate, useSearchParams,useParams } from 'react-router-dom';
|
||||
import QuotationTemplate from './components/QuotationTemplate';
|
||||
import ProjectTemplate from './components/ProjectTemplate';
|
||||
import TaskTemplate from './components/TaskTemplate';
|
||||
|
||||
const { Title } = Typography;
|
||||
|
||||
// 模板类型配置
|
||||
const TEMPLATE_CONFIG = {
|
||||
quotation: {
|
||||
title: '报价单模板',
|
||||
component: QuotationTemplate,
|
||||
},
|
||||
project: {
|
||||
title: '专案模板',
|
||||
component: ProjectTemplate,
|
||||
},
|
||||
task: {
|
||||
title: '任务模板',
|
||||
component: TaskTemplate,
|
||||
}
|
||||
};
|
||||
|
||||
const ServiceForm = () => {
|
||||
const [form] = Form.useForm();
|
||||
const navigate = useNavigate();
|
||||
const { id} = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const isView = searchParams.get("isView") === "true";
|
||||
const [loading, setLoading] = useState(false);
|
||||
const location = useLocation();
|
||||
const isEdit = location.search.includes("edit=true");
|
||||
const [formValues, setFormValues] = useState({
|
||||
sections: [{ items: [{}] }],
|
||||
currency: "CNY"
|
||||
});
|
||||
const [categories, setCategories] = useState([]);
|
||||
const type = searchParams.get('type') || 'quotation';
|
||||
const { id } = useParams();
|
||||
const isView = searchParams.get('isView') === 'true';
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
fetchServiceTemplate();
|
||||
}
|
||||
fetchCategories();
|
||||
}, [id]);
|
||||
const currentTemplate = TEMPLATE_CONFIG[type];
|
||||
const TemplateComponent = currentTemplate?.component;
|
||||
|
||||
const fetchServiceTemplate = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data, error } = await supabase
|
||||
.from("resources")
|
||||
.select("*")
|
||||
.eq("id", id)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
const formData = {
|
||||
templateName: data.attributes.templateName,
|
||||
description: data.attributes.description,
|
||||
category: data.attributes.category.map(v=>v.id),
|
||||
sections: data.attributes.sections,
|
||||
};
|
||||
form.setFieldsValue(formData);
|
||||
setFormValues(formData);
|
||||
} catch (error) {
|
||||
console.error("获取服务模版失败:", error);
|
||||
message.error("获取服务模版失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCategories = async () => {
|
||||
try {
|
||||
const { data: categoriesData, error } = await supabase
|
||||
.from('resources')
|
||||
.select('*')
|
||||
.eq('type', 'categories')
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
const formattedCategories = (categoriesData || []).map(category => ({
|
||||
value: category.id,
|
||||
label: category.attributes.name
|
||||
}));
|
||||
|
||||
setCategories(formattedCategories);
|
||||
} catch (error) {
|
||||
message.error('获取分类数据失败');
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const onFinish = async (values) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const categoryData = values.category.map(categoryId => {
|
||||
const category = categories.find(c => c.value === categoryId);
|
||||
return {
|
||||
id: categoryId,
|
||||
name: category.label
|
||||
};
|
||||
});
|
||||
const serviceData = {
|
||||
type: "serviceTemplate",
|
||||
attributes: {
|
||||
templateName: values.templateName,
|
||||
description: values.description,
|
||||
sections: values.sections,
|
||||
category: categoryData,
|
||||
},
|
||||
};
|
||||
|
||||
let result;
|
||||
if (id) {
|
||||
result = await supabase
|
||||
.from("resources")
|
||||
.update(serviceData)
|
||||
.eq("id", id)
|
||||
.select();
|
||||
} else {
|
||||
result = await supabase
|
||||
.from("resources")
|
||||
.insert([serviceData])
|
||||
.select();
|
||||
}
|
||||
|
||||
if (result.error) throw result.error;
|
||||
message.success("保存成功");
|
||||
navigate("/company/serviceTeamplate");
|
||||
} catch (error) {
|
||||
console.error("保存失败:", error);
|
||||
message.error("保存失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleValuesChange = (changedValues, allValues) => {
|
||||
setFormValues(allValues);
|
||||
};
|
||||
if (!currentTemplate) {
|
||||
return <div>无效的模板类型</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-2">
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white dark:from-gray-800 dark:to-gray-900/90 min-h-screen p-2">
|
||||
<Card
|
||||
className="shadow-lg rounded-lg border-0"
|
||||
title={
|
||||
<div className="flex justify-between items-center py-2">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Title level={4} className="mb-0 text-gray-800">
|
||||
{id ? (isEdit ? "编辑服务模版" : "查看服务模版") : "新建服务模版"}
|
||||
<Title level={4} className="mb-0 text-gray-800 dark:text-gray-200">
|
||||
{id ? (isView ? "查看" : "编辑") : "新建"}{currentTemplate.title}
|
||||
</Title>
|
||||
<span className="text-gray-400 text-sm">
|
||||
{id
|
||||
? isEdit
|
||||
? "请修改服务模版信息"
|
||||
: "服务模版详情"
|
||||
: "请填写服务模版信息"}
|
||||
? isView
|
||||
? `${currentTemplate.title}详情`
|
||||
: `请修改${currentTemplate.title}信息`
|
||||
: `请填写${currentTemplate.title}信息`}
|
||||
</span>
|
||||
</div>
|
||||
<Space size="middle">
|
||||
<Button
|
||||
icon={<ArrowLeftOutlined />}
|
||||
onClick={() => navigate("/company/serviceTeamplate")}
|
||||
>
|
||||
返回
|
||||
</Button>
|
||||
{!isView&& <Button
|
||||
type="primary"
|
||||
onClick={() => form.submit()}
|
||||
loading={loading}
|
||||
>
|
||||
保存
|
||||
</Button>}
|
||||
</Space>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={onFinish}
|
||||
onValuesChange={handleValuesChange}
|
||||
layout="vertical"
|
||||
variant="filled"
|
||||
disabled={isView}
|
||||
>
|
||||
<Card
|
||||
className="shadow-sm rounded-lg mb-6"
|
||||
type="inner"
|
||||
title={
|
||||
<span className="flex items-center space-x-2 text-gray-700">
|
||||
<span className="w-1 h-4 bg-blue-500 rounded-full" />
|
||||
<span>基本信息</span>
|
||||
</span>
|
||||
}
|
||||
bordered={false}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<Form.Item
|
||||
label="模版名称"
|
||||
name="templateName"
|
||||
rules={[{ required: true, message: "请输入模版名称" }]}
|
||||
>
|
||||
<Input placeholder="请输入模版名称" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="模版分类"
|
||||
name="category"
|
||||
rules={[{ required: true, message: "请选择或输入分类" }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择或输入分类"
|
||||
showSearch
|
||||
allowClear
|
||||
mode="tags"
|
||||
options={categories}
|
||||
loading={loading}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="模版描述"
|
||||
name="description"
|
||||
className="col-span-2"
|
||||
>
|
||||
<Input.TextArea rows={4} placeholder="请输入模版描述" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
className="shadow-sm rounded-lg"
|
||||
type="inner"
|
||||
title={
|
||||
<span className="flex items-center space-x-2 text-gray-700">
|
||||
<span className="w-1 h-4 bg-blue-500 rounded-full" />
|
||||
<span>服务明细</span>
|
||||
</span>
|
||||
}
|
||||
bordered={false}
|
||||
>
|
||||
<SectionList
|
||||
form={form}
|
||||
isView={!isEdit && id}
|
||||
formValues={formValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
/>
|
||||
</Card>
|
||||
</Form>
|
||||
<TemplateComponent
|
||||
id={id}
|
||||
isView={isView}
|
||||
onCancel={() => navigate("/company/serviceTeamplate")}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ServiceForm;
|
||||
export default ServiceForm;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -83,7 +83,7 @@ const SupplierForm = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-2">
|
||||
<div className="bg-gradient-to-b from-gray-50 to-white dark:from-gray-800 dark:to-gray-900/90 min-h-screen p-2">
|
||||
<Card
|
||||
className="shadow-lg rounded-lg border-0"
|
||||
title={
|
||||
|
||||
Reference in New Issue
Block a user