生产管理系统 - 提交审核开发
This commit is contained in:
@@ -6,6 +6,7 @@ import { Edit, Save, X } from 'lucide-react';
|
|||||||
|
|
||||||
interface EnterpriseInfoHeaderProps {
|
interface EnterpriseInfoHeaderProps {
|
||||||
isEditing: boolean;
|
isEditing: boolean;
|
||||||
|
loading?: boolean;
|
||||||
onEdit: () => void;
|
onEdit: () => void;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
onSave: () => void;
|
onSave: () => void;
|
||||||
@@ -13,6 +14,7 @@ interface EnterpriseInfoHeaderProps {
|
|||||||
|
|
||||||
export function EnterpriseInfoHeader({
|
export function EnterpriseInfoHeader({
|
||||||
isEditing,
|
isEditing,
|
||||||
|
loading = false,
|
||||||
onEdit,
|
onEdit,
|
||||||
onCancel,
|
onCancel,
|
||||||
onSave
|
onSave
|
||||||
@@ -30,13 +32,13 @@ export function EnterpriseInfoHeader({
|
|||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button variant="outline" onClick={onCancel}>
|
<Button variant="outline" onClick={onCancel} disabled={loading}>
|
||||||
<X className="w-4 h-4 mr-2" />
|
<X className="w-4 h-4 mr-2" />
|
||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={onSave}>
|
<Button onClick={onSave} disabled={loading}>
|
||||||
<Save className="w-4 h-4 mr-2" />
|
<Save className="w-4 h-4 mr-2" />
|
||||||
提交审核
|
{loading ? '保存中...' : '提交审核'}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/**
|
||||||
|
* filekorolheader: 企业信息API接口 - 企业详细信息获取和更新接口服务
|
||||||
|
* 功能:API请求封装、数据转换、错误处理、企业信息管理
|
||||||
|
* 路径:/central-config/tenant/enterprise-info/components/enterpriseInfoApi
|
||||||
|
* 规范:遵循crop-x/docs/开发项目规范.md,使用SDK API调用,TypeScript类型安全
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getAuthToken } from "@/utils/token";
|
||||||
|
import { getTenantApiV1TenantsTenantIdGet } from "@/lib/api/sdk.gen";
|
||||||
|
import { Enterprise } from '../types';
|
||||||
|
|
||||||
|
// API返回的租户数据类型(根据实际API返回定义)
|
||||||
|
export interface TenantApiData {
|
||||||
|
id: string;
|
||||||
|
tenant_code: string;
|
||||||
|
is_active: boolean;
|
||||||
|
company_name: string;
|
||||||
|
company_type: string | null;
|
||||||
|
province: string | null;
|
||||||
|
city: string | null;
|
||||||
|
district: string | null;
|
||||||
|
detailed_address: string | null;
|
||||||
|
registrant: string | null;
|
||||||
|
contact_phone: string | null;
|
||||||
|
bank_account: string | null;
|
||||||
|
bank_name: string | null;
|
||||||
|
bank_full_name: string | null;
|
||||||
|
bank_address: string | null;
|
||||||
|
social_credit_code: string | null;
|
||||||
|
legal_person_name: string | null;
|
||||||
|
company_scale: string | null;
|
||||||
|
registered_capital: string | null;
|
||||||
|
established_date: string | null;
|
||||||
|
invoice_type: string | null;
|
||||||
|
business_scope: string | null;
|
||||||
|
submit_time: string | null;
|
||||||
|
audit_time: string | null;
|
||||||
|
auditor: string | null;
|
||||||
|
audit_status: string;
|
||||||
|
audit_comment: string | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业详细信息
|
||||||
|
*/
|
||||||
|
export async function fetchEnterpriseInfo(tenantId: string): Promise<Enterprise | null> {
|
||||||
|
try {
|
||||||
|
const token = getAuthToken();
|
||||||
|
console.log('🏢 获取企业信息API调用,租户ID:', tenantId);
|
||||||
|
|
||||||
|
const response = await getTenantApiV1TenantsTenantIdGet({
|
||||||
|
path: {
|
||||||
|
tenant_id: tenantId,
|
||||||
|
},
|
||||||
|
headers: token ? {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
} : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.error) {
|
||||||
|
throw new Error(`API error: ${response.error.message || 'Unknown error'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = response.data as TenantApiData;
|
||||||
|
console.log('🏢 获取企业信息API响应:', data);
|
||||||
|
|
||||||
|
return transformTenantData(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('🏢 获取企业信息失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新企业信息
|
||||||
|
* 注意:此功能待开发,当前不做任何操作
|
||||||
|
*/
|
||||||
|
export async function updateEnterpriseInfo(tenantId: string, formData: Partial<Enterprise>): Promise<Enterprise | null> {
|
||||||
|
console.log('🏢 更新企业信息功能待开发,租户ID:', tenantId, '数据:', formData);
|
||||||
|
|
||||||
|
// 暂时返回null,等待更新API接口开发完成
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将API数据转换为页面所需的企业数据格式
|
||||||
|
*/
|
||||||
|
export function transformTenantData(tenant: TenantApiData): Enterprise {
|
||||||
|
return {
|
||||||
|
id: tenant.id,
|
||||||
|
name: tenant.company_name || '',
|
||||||
|
type: tenant.company_type || '未分类',
|
||||||
|
province: tenant.province || '',
|
||||||
|
city: tenant.city || '',
|
||||||
|
district: tenant.district || undefined,
|
||||||
|
companySize: tenant.company_scale || undefined,
|
||||||
|
registeredCapital: tenant.registered_capital || undefined,
|
||||||
|
establishmentDate: tenant.established_date ?
|
||||||
|
new Date(tenant.established_date).toLocaleDateString('zh-CN') : undefined,
|
||||||
|
invoiceType: tenant.invoice_type || undefined,
|
||||||
|
socialCreditCode: tenant.social_credit_code || '',
|
||||||
|
businessScope: tenant.business_scope || undefined,
|
||||||
|
bankAccount: tenant.bank_account || undefined,
|
||||||
|
bankName: tenant.bank_name || undefined,
|
||||||
|
bankFullName: tenant.bank_full_name || undefined,
|
||||||
|
bankAddress: tenant.bank_address || undefined,
|
||||||
|
legalPerson: tenant.legal_person_name || undefined,
|
||||||
|
registrant: tenant.registrant || '',
|
||||||
|
contactPhone: tenant.contact_phone || '',
|
||||||
|
address: tenant.detailed_address || '',
|
||||||
|
status: tenant.is_active ? 'active' : 'inactive',
|
||||||
|
auditStatus: mapAuditStatus(tenant.audit_status),
|
||||||
|
auditReason: tenant.audit_comment || undefined,
|
||||||
|
auditTime: tenant.audit_time ? formatDate(tenant.audit_time) : undefined,
|
||||||
|
auditor: tenant.auditor || undefined,
|
||||||
|
createdAt: formatDate(tenant.created_at),
|
||||||
|
updatedAt: formatDate(tenant.updated_at),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 映射审核状态
|
||||||
|
*/
|
||||||
|
function mapAuditStatus(status: string): Enterprise['auditStatus'] {
|
||||||
|
switch (status) {
|
||||||
|
case '未提交':
|
||||||
|
case '草稿':
|
||||||
|
return 'pending';
|
||||||
|
case '待审核':
|
||||||
|
return 'pending';
|
||||||
|
case '已通过':
|
||||||
|
case '审核通过':
|
||||||
|
return 'approved';
|
||||||
|
case '已拒绝':
|
||||||
|
case '已驳回':
|
||||||
|
return 'rejected';
|
||||||
|
default:
|
||||||
|
return 'pending';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化日期
|
||||||
|
*/
|
||||||
|
function formatDate(dateString: string): string {
|
||||||
|
try {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
}).replace(/\//g, '-');
|
||||||
|
} catch (error) {
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,68 +15,59 @@ import { LegalInfoForm } from './components/LegalInfoForm';
|
|||||||
import { SystemInfo } from './components/SystemInfo';
|
import { SystemInfo } from './components/SystemInfo';
|
||||||
import { OperationTips } from './components/OperationTips';
|
import { OperationTips } from './components/OperationTips';
|
||||||
import { Enterprise } from './types';
|
import { Enterprise } from './types';
|
||||||
|
import { getAuthUser } from '@/stores/modules/auth';
|
||||||
|
import { fetchEnterpriseInfo, updateEnterpriseInfo } from './components/enterpriseInfoApi';
|
||||||
|
|
||||||
export default function EnterpriseInfoPage() {
|
export default function EnterpriseInfoPage() {
|
||||||
const [enterprise, setEnterprise] = useState<Enterprise | null>(null);
|
const [enterprise, setEnterprise] = useState<Enterprise | null>(null);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [formData, setFormData] = useState<Partial<Enterprise>>({});
|
const [formData, setFormData] = useState<Partial<Enterprise>>({});
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [currentUser, setCurrentUser] = useState<any>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadEnterpriseInfo();
|
// 获取用户信息
|
||||||
|
const userInfo = getAuthUser();
|
||||||
|
console.log('🏢 从 Zustand 获取的用户信息:', userInfo);
|
||||||
|
console.log('🏢 用户租户 ID (tenant_id):', userInfo?.tenant_id);
|
||||||
|
|
||||||
|
if (!userInfo?.tenant_id) {
|
||||||
|
toast.error('无法获取用户租户信息,请重新登录');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentUser(userInfo);
|
||||||
|
|
||||||
|
// 加载企业信息
|
||||||
|
loadEnterpriseInfo(userInfo.tenant_id);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const loadEnterpriseInfo = () => {
|
const loadEnterpriseInfo = async (tenantId: string) => {
|
||||||
const stored = localStorage.getItem('smart_agriculture_enterprise_info');
|
try {
|
||||||
if (stored) {
|
setLoading(true);
|
||||||
const data = JSON.parse(stored);
|
console.log('🏢 开始加载企业信息,租户ID:', tenantId);
|
||||||
setEnterprise(data);
|
|
||||||
setFormData(data);
|
|
||||||
} else {
|
|
||||||
// 初始化模拟数据
|
|
||||||
const mockData: Enterprise = {
|
|
||||||
id: 'ent-001',
|
|
||||||
// 基本信息
|
|
||||||
name: '智慧农业科技有限公司',
|
|
||||||
type: '有限责任公司',
|
|
||||||
province: '北京市',
|
|
||||||
city: '海淀区',
|
|
||||||
district: '中关村街道',
|
|
||||||
|
|
||||||
// 其他信息
|
// 调用API获取企业信息
|
||||||
companySize: '50-200人',
|
const enterpriseData = await fetchEnterpriseInfo(tenantId);
|
||||||
registeredCapital: '1000万元',
|
|
||||||
establishmentDate: '2020-01-15',
|
|
||||||
invoiceType: '增值税专用发票',
|
|
||||||
socialCreditCode: '91110108MA01XXXX00',
|
|
||||||
businessScope: '农业技术开发、技术咨询、技术服务;销售机械设备、电子产品;软件开发;数据处理服务。',
|
|
||||||
businessLicense: '',
|
|
||||||
|
|
||||||
// 开户信息
|
if (enterpriseData) {
|
||||||
bankAccount: '1234567890123456789',
|
setEnterprise(enterpriseData);
|
||||||
bankName: '中国工商银行',
|
setFormData(enterpriseData);
|
||||||
bankFullName: '中国工商银行股份有限公司北京中关村支行',
|
console.log('🏢 企业信息加载成功:', enterpriseData);
|
||||||
bankAddress: '北京市海淀区中关村大街1号',
|
} else {
|
||||||
bankLicense: '',
|
console.log('🏢 企业信息为空,显示空状态');
|
||||||
|
setEnterprise(null);
|
||||||
|
setFormData({});
|
||||||
|
}
|
||||||
|
|
||||||
// 法人信息
|
} catch (error) {
|
||||||
legalPerson: '张伟',
|
console.error('🏢 加载企业信息失败:', error);
|
||||||
idCardFront: '',
|
const errorMessage = error instanceof Error ? error.message : '加载企业信息失败';
|
||||||
idCardBack: '',
|
toast.error(errorMessage);
|
||||||
|
setEnterprise(null);
|
||||||
// 联系信息
|
setFormData({});
|
||||||
registrant: '李明',
|
} finally {
|
||||||
contactPhone: '010-88888888',
|
setLoading(false);
|
||||||
address: '北京市海淀区中关村大街1号科技大厦A座10层',
|
|
||||||
|
|
||||||
// 系统信息
|
|
||||||
status: 'active',
|
|
||||||
auditStatus: 'approved',
|
|
||||||
createdAt: '2024-01-15T00:00:00',
|
|
||||||
updatedAt: '2024-01-15T00:00:00',
|
|
||||||
};
|
|
||||||
localStorage.setItem('smart_agriculture_enterprise_info', JSON.stringify(mockData));
|
|
||||||
setEnterprise(mockData);
|
|
||||||
setFormData(mockData);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,24 +82,40 @@ export default function EnterpriseInfoPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = async () => {
|
||||||
|
if (!currentUser?.tenant_id) {
|
||||||
|
toast.error('无法获取用户租户信息,请重新登录');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!formData.name || !formData.type || !formData.socialCreditCode) {
|
if (!formData.name || !formData.type || !formData.socialCreditCode) {
|
||||||
toast.error('请填写必填项');
|
toast.error('请填写必填项');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedData: Enterprise = {
|
try {
|
||||||
...(enterprise as Enterprise),
|
setLoading(true);
|
||||||
...formData,
|
console.log('🏢 开始更新企业信息');
|
||||||
updatedAt: new Date().toISOString(),
|
|
||||||
auditStatus: 'pending', // 修改后需要重新审核
|
|
||||||
};
|
|
||||||
|
|
||||||
localStorage.setItem('smart_agriculture_enterprise_info', JSON.stringify(updatedData));
|
// 调用API更新企业信息
|
||||||
setEnterprise(updatedData);
|
const updatedData = await updateEnterpriseInfo(currentUser.tenant_id, formData);
|
||||||
setFormData(updatedData);
|
|
||||||
setIsEditing(false);
|
if (updatedData) {
|
||||||
toast.success('企业信息已更新,等待管理员审核');
|
setEnterprise(updatedData);
|
||||||
|
setFormData(updatedData);
|
||||||
|
setIsEditing(false);
|
||||||
|
toast.success('企业信息已更新,等待管理员审核');
|
||||||
|
} else {
|
||||||
|
toast.info('企业信息保存功能待开发');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('🏢 更新企业信息失败:', error);
|
||||||
|
const errorMessage = error instanceof Error ? error.message : '更新企业信息失败';
|
||||||
|
toast.error(errorMessage);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (field: keyof Enterprise, value: any) => {
|
const handleChange = (field: keyof Enterprise, value: any) => {
|
||||||
@@ -116,10 +123,24 @@ export default function EnterpriseInfoPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleImageUpload = (field: keyof Enterprise) => {
|
const handleImageUpload = (field: keyof Enterprise) => {
|
||||||
// 模拟图片上传
|
// 图片上传功能需要对接后端服务
|
||||||
toast.success('图片上传功能需要对接后端服务');
|
toast.info('图片上传功能正在开发中');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-green-800">企业信息</h2>
|
||||||
|
<p className="text-muted-foreground">查看和管理本企业的完整注册信息</p>
|
||||||
|
</div>
|
||||||
|
<Card className="p-8 text-center text-muted-foreground">
|
||||||
|
加载中...
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!enterprise) {
|
if (!enterprise) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@@ -128,7 +149,7 @@ export default function EnterpriseInfoPage() {
|
|||||||
<p className="text-muted-foreground">查看和管理本企业的完整注册信息</p>
|
<p className="text-muted-foreground">查看和管理本企业的完整注册信息</p>
|
||||||
</div>
|
</div>
|
||||||
<Card className="p-8 text-center text-muted-foreground">
|
<Card className="p-8 text-center text-muted-foreground">
|
||||||
暂无企业信息
|
{loading ? '加载中...' : '暂无企业信息或加载失败,请刷新页面重试'}
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -138,6 +159,7 @@ export default function EnterpriseInfoPage() {
|
|||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<EnterpriseInfoHeader
|
<EnterpriseInfoHeader
|
||||||
isEditing={isEditing}
|
isEditing={isEditing}
|
||||||
|
loading={loading}
|
||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSave={handleSave}
|
onSave={handleSave}
|
||||||
|
|||||||
Reference in New Issue
Block a user